Chat.Client

View as Markdown

You can use the Client object to build a messaging system into the browser.

Example usage:

1import { Chat } from "@signalwire/js";
2
3const chatClient = new Chat.Client({
4 token: "<your_chat_token>", // get this from the REST APIs
5});
6
7await chatClient.subscribe(["mychannel1", "mychannel2"]);
8
9chatClient.on("message", (message) => {
10 // prettier-ignore
11 console.log("Received", message.content,
12 "on", message.channel,
13 "at", message.publishedAt);
14});
15
16await chatClient.publish({
17 channel: "mychannel1",
18 content: "hello world",
19});

Constructors

constructor

  • new Client(chatOptions)

Creates a new Chat client.

Parameters

chatOptions
objectRequired

Configuration options for the Chat client

chatOptions.token
stringRequired

SignalWire Chat token that can be obtained from the REST APIs.

Example

1import { Chat } from "@signalwire/js";
2
3const chatClient = new Chat.Client({
4 token: "<your_chat_token>",
5});

Type Aliases

PaginationCursor

This is a utility object that aids in pagination. It is specifically used in conjunction with the getMessages method.

Properties

after
string

This property signifies the cursor for the subsequent page.

before
string

This property signifies the cursor for the preceding page.