PubSubMessage

View as Markdown

Represents a message in a PubSub context.

Properties

id
stringRequired

The id of this message.

channel
stringRequired

The channel in which this message was sent.

content
anyRequired

The content of this message.

publishedAt
DateRequired

The date and time at which this message was published.

meta
any

Any metadata associated to this message.

Example

Listening for PubSub messages and accessing PubSubMessage properties:

1import { SignalWire } from "@signalwire/realtime-api";
2
3const client = await SignalWire({ project: "your-project-id", token: "your-api-token" });
4
5await client.pubSub.listen({
6 channels: ["my-channel"],
7 onMessageReceived: (message) => {
8 console.log("Message ID:", message.id);
9 console.log("Channel:", message.channel);
10 console.log("Content:", message.content);
11 console.log("Published at:", message.publishedAt);
12 console.log("Metadata:", message.meta);
13 }
14});