Stream new group chat and DM messages and preference updates
This function listens to the network for new messages within all active group chats and DMs, as well as preference updates.
Whenever a new message is sent to any of these conversations, the callback is triggered with a DecodedMessage
object. This keeps the inbox up to date by streaming in messages as they arrive.
By default, streamAll
streams only conversations with a consent state of allowed or unknown.
We recommend streaming messages for allowed conversations only. This ensures that spammy conversations with a consent state of unknown don't take up networking resources. This also ensures that unwanted spam messages aren't stored in the user's local database.
To stream all conversations regardless of consent state, pass [Allowed, Unknown, Denied]
.
const stream = await client.conversations.streamAllMessages(["allowed"]);
try {
for await (const message of stream) {
// Received a message
console.log("New message:", message);
}
} catch (error) {
// Log any stream errors
console.error(error);
}