Skip to main content

Chat

Access the Chat API Consumer. You can instantiate a Chat.Client to subscribe to Chat events.

info

For a full list of events that a Chat.Client can subscribe to, refer to Chat Events.

Example

The following example shows how to instantiate a Chat.Client and listen to the onMemberJoined event on the channel1 channel. When a member joins the channel, the bot will send a message to the channel with the number of members in the channel and the list of members.

import { SignalWire } from "@signalwire/realtime-api";

const client = await SignalWire({ project: "ProjectID Here", token: "Token Here" })

const chatClient = client.chat;

await chatClient.listen({
channels: ["channel1"],
onMemberJoined: async (member) => {

let members = await chatClient.getMembers({
channel: member.channel
});
let chatMessage = `Hello ${member.id}!
There are ${members.members.length} members in this channel.
The members are: ${members.members.map(m => m.id).join(", ")}`

await chatClient.publish({
channel: member.channel,
content: chatMessage
})
}
});

Classes