MinChat Documentation
SupportHome
  • Introduction
  • Getting Started
    • Using Vanilla Javascript
    • Using React
    • Using React Native
  • Webhooks
    • Overview
  • Rest APIs
    • Overview
  • Websockets
    • Overview
  • Customize UI
    • Customizing React UI
  • Reference
    • User
    • Message
    • File
  • Javascript SDK
    • Overview
    • Conversation (Chat)
  • React SDK
    • Overview
    • useChats hook
    • useMessages hook
    • useUser hook
    • useMinChat
    • Conversation (Chat)
  • React Native SDK
    • Overview
    • useChats hook
    • useMessages hook
    • useUser hook
    • useMinChat
    • Conversation (Chat)
    • File
Powered by GitBook
On this page
  • General Events
  • Listen for Chats
  • Conversation Events
  • Listen for new messages
  • Listen for updated messages
  • Listen for deleted messages
  • Listen for typing started
  • Listen for typing stopped

Was this helpful?

  1. Websockets

Overview

Last updated 1 year ago

Was this helpful?

Websockets are used for real-time, event-driven communication between clients and the MinChat server. They are useful in listening for specific events such as a new message received event.

The following is the socket URL endpoint to connect to.

import { io } from "socket.io-client"

const socket = io("https://api.minchat.io", { transports: ['websocket'] });

it is recommended to use socket.io, however, you can also use any WebSocket library.

Specify the active user to listen to events.

socket.emit('room.user.join', { channelUserId: USER_ID, apiKey: YOUR_API_KEY })

Replace YOUR_API_KEY with your API Key found on the MinChat , and USER_ID with the userID of the that will make requests.

General Events

Listen for Chats

Invoked when there is a new message in any conversation.

socket?.on('chat',(chatData) => {   /** do something with the chat */ })

Conversation Events

The following events require you to subscribe to listen to events for a specific chat by running the following code.

socket.emit('room.join', { channelId: CHAT_ID, apiKey: YOUR_API_KEY })

Listen for new messages

Invoked when there is a new message in the subscribed chat

socket.on('message', (messageData) => { /** do something with the messageData */ })

Listen for updated messages

Invoked when a message gets updated in the subscribed chat

socket.on('message.update', (messageData) => { /** do something */ })

Listen for deleted messages

Invoked when a message gets deleted in the subscribed chat

socket.on('message.delete', (messageId) => { /** do something */ })

Listen for typing started

Invoked when a user in the conversation starts typing.

socket.on('typing.start', (userData) => { /** do something with the userData */ })

Listen for typing stopped

Invoked when a user in the conversation stops typing.

socket.on('typing.stop', (userData) => { /** do something with the userData */ })

Replace YOUR_API_KEY with your API Key found on the MinChat , and CHAT_IDwith the id of the conversation you would like to listen to events.

Dashboard
User
Dashboard