Channel functions

The functions in the bot.channel namespace are used to send messages, display typing indicators, and manage handovers and handbacks.

getName()

Returns the name of the channel as a string. Currently-supported channels are:

  • messenger
  • smooch
  • google_assistant
  • alexa
  • khoros
  • teams
  • zendesk
  • genesys_dialogflow
bot.channel.getName();
done();

getAync()

Returns true if the current chatbot channel is asynchronous.

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.

sendText​Message​(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.

sendAttachment​Message(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();

sendTemplate​Message(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.

For more information on available templates and their structures, see Facebook’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", "payload":"DEVELOPER_DEFINED_PAYLOAD" } ] } ] }, params); done();

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.

handback(options)

Request control back from 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.

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Article is closed for comments.