Running code snippets in bots
When creating or editing a bot, you can add a code snippet by clicking the "+" to add an action as you normally would. From the action selection panel, click on "Run a code snippet."
Next, give your action a nickname. Within the code editing pane, you'll see our default template for Node.js 10.x. The details of the "event" object and possible response object formats are detailed below.
The code will be triggered when the saved action is reached in a conversation.
There are three main things to keep in mind when working with code snippets:
- The
exports.main()
function is called when the code snippet action is executed. - The
event
argument is an object containing details for the visitor and chat session. - The
callback()
function is used to pass data back to the bot and user. It should be called in theexports.main
function.
The event
object will contain the following data:
The callback()
function is used to send data back to the bot. The argument should be an object with the following data:
Thank you for your feedback, it means a lot to us.