Channels
Subscribe Channel Messages
Subscribe to channel messages
Description
Subscribe to a channel to receive real-time messages published to it. This endpoint returns a streaming response that will continuously send message events as they are published to the channel via the publish endpoint. The connection remains open until the client closes it or an error occurs.
Authorization
ChatBotKit API Secret * Required
HTTP Authorization Scheme: bearer
Path Parameters
channelIdstring* Required
The ID of the channel to subscribe to (minimum 16 characters)
Request Body * Required
Request Body Schema: application/json
historyLengthinteger
Number of historical messages to replay from the channel before subscribing to live updates. When provided, the subscriber will first receive up to this many recent messages that were published before the subscription started. This is useful for catching up on messages that may have been published during connection setup.
import { ChatBotKit } from '@chatbotkit/sdk'
const cbk = new ChatBotKit({
secret: process.env.CHATBOTKIT_API_KEY!
})
const response = await cbk.channel.subscribe(
channelId,{)}"historyLength":"integer"