Use this file to discover all available pages before exploring further.
Back to BotKit SDK OverviewThe BotKit SDK provides functions for controlling message flow, managing agent sessions, and working with async webhook responses.Available functions:
Sends a message to the user. Use inside on_bot_message to modify the bot’s reply before delivery.Syntax:
sdk.sendUserMessage(payload, callback)
Payload:
{ "message": "Spell-corrected message sent by the bot to the user", "originalMessage": "Original message sent by the bot to the user", "taskId": "Dialog task ID", "nodeId": "Current node ID in the dialog flow", "channel": "Channel name", "context": "<context object>"}
// Return error to userreturn sdk.sendUserMessage(payload, function(err) { if (err) console.log("err", err);});// Notify user of agent transferdata.message = "An Agent will be assigned to you shortly!";sdk.sendUserMessage(payload, callback);// Override message based on user selectionif (message == "yes") { payload.overrideMessagePayload = { body: "Enter the currency code for conversion", isTemplate: false }; return sdk.sendUserMessage(payload);}
Sends a message to the bot. Use inside on_user_message to modify or forward the user’s message. Messages are validated: max 3000 characters total, max 1200 characters per word.Syntax:
sdk.sendBotMessage(payload, callback)
Payload:
{ "message": "Message sent by the user", "channel": "Channel name", "context": "<context object>"}
Examples:
// Forward message to boton_user_message: function(requestId, payload, callback) { sdk.sendBotMessage(payload, callback);}// Intercept and rerouteon_user_message: function(requestId, payload, callback) { if (payload.message === "Hi") { payload.message = "Hello"; return sdk.sendUserMessage(payload, callback); // Return to user } else if (!payload.agent_transfer) { return sdk.sendBotMessage(payload, callback); // Forward to bot } else { payload.message = "Agent Message"; return sdk.sendUserMessage(payload, callback); }}
Sends an HTTP 202 to the Platform to indicate an async webhook response is in progress. Call sdk.respondToHook(payload) when the response is ready.Syntax:
Clears the agent session and re-establishes the conversation with the bot. Call this when the live agent closes the chat (triggered by a chat_closed event from the third-party provider).Syntax:
sdk.clearAgentSession(requestData, callback)
Example:
if (event.type === "chat_closed") { delete userResponseDataMap[visitorId]; delete _map[visitorId]; sdk.clearAgentSession(data);}
Notifies the Platform that an agent transfer is in progress. After calling this, the data object received by BotKit will have agent_session: true. When sdk.clearAgentSession is called, the Platform sets it back to false.Syntax:
sdk.startAgentSession(requestData, callback)
Example:
function connectToAgent(requestId, data, cb) { data.message = "An Agent will be assigned to you shortly!"; sdk.sendUserMessage(data, cb); sdk.startAgentSession(data, cb); // Notify Platform before initChat return api.initChat(visitorId, formdata).then(function(res) { _map[visitorId] = { secured_session_id: res.secured_session_id, ... }; });}
Extends the time window for BotKit to send messages to the Platform. Use during prolonged agent transfer sessions where the Platform might stop receiving messages.Syntax:
sdk.extendRequestId(requestData, callback)
Extension is ineffective after 15 minutes of conversation inactivity. An inactive session resets agent_transfer mode regardless.