The functions in the bot.channel namespace are used to send messages, display typing indicators, and manage handovers and handbacks.
Jump to:
Channel information
getName()
Returns the name of the channel as a string. Currently-supported channels are:
- messenger
- smooch
- smooch_v2
- google_assistant
- alexa
- khoros
- teams
- zendesk
- genesys_dialogflow
bot.channel.getName();
done();getSubchannelName()
Returns the sub-channel name of a supported channel.
getCustomChannelName()
Returns the name of the custom channel within the channel or sub-channel, if available.
isAsync()
Returns true if the current chatbot channel is asynchronous.
Handover
handover(options)
Hand the chatbot over to a third party such as a live chat or another app. This method is asynchronous.
| Parameter | Type | Required | Description |
|---|---|---|---|
| options | Object | Required |
JSON object of data to pass to the third party. The content and structure of this payload depends on the third-party API. |
Send message
sendTextMessage(text, options)
Send a text message to the user. This method is asynchronous and should be prefixed with await.
| Parameter | Type | Required | Description |
|---|---|---|---|
| text | String | Required | The message to send. |
| options | Object | Required |
Object containing params.metadata and params.quickReplies. If you don’t want to change the next passage or send quick replies, you can just use the params variable. See Chatbot properties. Also see Passage Locator and Quick Reply. |
//Send a simple text message
await bot.channel.sendTextMessage(`Hello world!`, params);
done();Add emojis to your scripts 🤩
If you want to add emojis to your message, you can search for the emoji you want on https://emojifinder.com and paste it in.
sendAttachmentMessage(type, url, options)
Send a rich-content message such as an image, video, audio file or other file. This method is asynchronous and should be prefixed with await.
| Parameter | Type | Required | Description |
|---|---|---|---|
| type | String | Required | The content type of the attachment. Must be one of: audio, image, file or video. |
| url | String | Required | The URL of the attachment to send. |
| options | Object | Required |
Object containing params.metadata and params.quickReplies. If you don’t want to change the next passage or send quick replies, you can just use the params variable. See Chatbot properties. Also see Passage Locator and Quick Reply. |
//Using sendAttachmentMessage to send a gif
await bot.channel.sendAttachmentMessage('image', 'https://example.com/cat.gif', params);
done();sendTemplateMessage(template, options)
Send a structured message using a template. This method is asynchronous and should be prefixed with await.
| Parameter | Type | Required | Description |
|---|---|---|---|
| template | Object | Required |
Object detailing the template type and content, including any inline actions you want to assign to buttons. For more information on available templates and their structures, see Metaa’s Message Templates. |
| options | Object | Required |
Object containing params.metadata and params.quickReplies. If you don’t want to change the next passage or send quick replies, you can just use the params variable. See Chatbot properties. Also see Passage Locator and Quick Reply. |
//Sending a generic-type templated message
//that launches a URL as a default action, with another option to start chatting.
await bot.channel.sendTemplateMessage({
"template_type":"generic",
"elements":[
{
"title":"Welcome!",
"image_url":"https://petersfancybrownhats.com/company_image.png",
"subtitle":"We have the right hat for everyone.",
"default_action": {
"type": "web_url",
"url": "https://petersfancybrownhats.com/view?item=103",
"webview_height_ratio": "tall",
},
"buttons":[
{
"type":"web_url",
"url":"https://petersfancybrownhats.com",
"title":"View Website"
},{
"type":"postback",
"title":"Start Chatting",
"nextPassage": { "passageId": "<PassageId>" }
"inlineActions": [ { "type": "saveData", "name": "foo", "value": "bar" } ] // optional
}
]
}
]
}, params);
done();Add actions to a button
You can add actions to buttons in template messages using inline actions. These actions behave the same as if they had been configured by the chatbot content creator.
Inline actions are specified as an array of objects, where each object defines an action. If the user presses the button, the actions will be performed in the order they are defined in the array.
Each inline action object contains a property type which defines the name of the action. Some inline actions may also define additional properties. All property names and property values are strings.
| InlineAction | Action description | Additional properties |
|---|---|---|
| clearVariables | Clear all variables currently assigned to the user. | none. |
| saveVariables | Assign a value to a variable for this user. |
|
Typing effects
startTyping()
Start the typing effect on the user’s chat window. This method is asynchronous.
Using typing effects
Typing effects are automatically started and stopped when you send a message. If you need to perform some processing that will take longer than 3 seconds, you can call startTyping() to create the typing effect so the chatbot seems to remain present to the user while processing completes.
bot.channel.startTyping();
//Do some lengthy processing
message = lengthyCalculations();
await bot.channel.sendTextMessage(message, params);
done();stopTyping()
Stop the typing effect on the user’s chat window. This method is asynchronous.