publish

View as Markdown

publish

  • publish(params): Promise<void>

Publish a message into the specified channel.

Parameters

params
objectRequired

Object containing the parameters of the method.

channel
stringRequired

Channel in which to send the message.

content
anyRequired

The message to send. This can be any JSON-serializable object or value.

meta
Record<any, any>

Metadata associated with the message. There are no requirements on the content of metadata.

Returns

Promise<void>

Examples

Publishing a message as a string:

1import { SignalWire } from "@signalwire/realtime-api";
2
3const client = await SignalWire({ project: "ProjectID Here", token: "Token Here" })
4
5const chatClient = client.chat;
6
7await chatClient.publish({
8 channel: "my-channel",
9 content: "Hello, world."
10});

Publishing a message as an object:

1import { SignalWire } from "@signalwire/realtime-api";
2
3const client = await SignalWire({ project: "ProjectID Here", token: "Token Here" })
4
5const chatClient = client.chat;
6
7await chatClient.publish({
8 channel: "my-channel",
9 content: {
10 field_one: "value_one",
11 field_two: "value_two"
12 }
13});