How to use BotKit SDK Message Formatting with Templates?

(Yanluis Ulloa) #1

I’m trying to use the example described in BotKit SDK Message Formatting with Templates but it is incomplete.

For example, we can see what the value of the variable overrideMessagePayload, but, what to do with it? Where in the payload it goes? What means “_ when the isTemplate parameter is set to true_”?

Here is a simple example I’ve playing with:

on_bot_message: function(requestId, data, callback) {
  const message = {
	type: 'template',
	payload: {
	  template_type: 'button',
	  text: 'What do you want to do next?',
	  buttons: [
		  type: 'web_url',
		  title: 'Show Website',
		  url: '',
		  type: 'postback',
		  title: 'Start Chatting',
		  payload: 'USER_DEFINED_PAYLOAD',

  // What to do with this variable?
  const overrideMessagePayload = { 
	  body: JSON.stringify(message),
	  isTemplate: true
  data.message = overrideMessagePayload; // Right or Wrong?
  sdk.sendUserMessage(data, callback);

But, it doesn’t work.

Now, from the previous example, if we make this change

 data.message =  JSON.stringify(message);
data.isTemplate = true;
sdk.sendUserMessage(data, callback);

It doesn’t work either.

Or, this one

 data.message =  JSON.stringify(overrideMessagePayload);
sdk.sendUserMessage(data, callback);


So, please, help me up to clear my head on How to use BotKit SDK Message Formatting with Templates? and update the doc.

Transition from Entity to Entity with BotKit SDK template response
(Subrahmanyam Donepudi) #2

Hi @yanluis.ulloa,
When we have a channel override message template configured at any of the messages on the bot builder, during the execution the data.formattedMessage will contain the configured template and isTemplate as True.

For example, I have configured the welcome message at web/mobile client channel for a bot which will send a quick replies template to the user as below:

At the bot kit, as mentioned, the template configuration will be available under data.formattedMessage as shown in the below snip


You could write the logic at on_bot_message event in the bot kit to manipulate the response sent by bot in this case. The same was being referred to @

Well, the above article is intended to show the ability to send messages with templates applied from the bot kit. Below is a simple illustration to explain the same.

In this example, the bot will send a button template which is configured inside the bot kit if the user message to the bot is “Hi”

Logic for the same at on_user_message event in the bot kit:

on_user_message: function(requestId, data, callback) {
        console.log("User Message ----->", data.message);
        if (data.message === "Hi") {
var overrideMessagePayload = 
body : JSON.stringify({
"type": "template",
"template_type": "button",
"text": "This is an example to demonstrate message templates sent from bot kit",
"type": "postback",
"title": "Yes",
"payload": "Yes"
"type": "postback",
"title": "No",
"payload": "No"
isTemplate :true
		   data.overrideMessagePayload= overrideMessagePayload;}
  return sdk.sendUserMessage(data, callback);

The developer need to add the overMessagePayload to the data and then could send it back to the user as mentioned in above code snippet.

Below snip show the template sent to user with the message “Hi”