HomeModule CreatorWidgetsButtons

Buttons

A Button is shown to the end user. This is shown in the Chat window.

The Code for the button is:

 

var buttonTemplate = [{
			type: "postback",
			title: "By Mood",
			payload: {
				variable: "cocktail_suggestion_category",
				value: "mood"
			},
			variableType: {
				type: 'values',
				valueName: 'cocktail_suggestion_category_by_mood'
			}
		}, {
			type: "postback",
			title: "By Food",
			payload: {
				variable: "cocktail_suggestion_category",
				value: "food"
			},
			variableType: {
				type: 'values',
				valueName: 'cocktail_suggestion_category_by_food'
			}
		},{
                        type: "postback",
                        title: "Cancel",
                        payload: {
                            variable: "plan",
                            value: "cancel"
                        },
                        variableType: {
                            type: 'regexParser',
                            valueName: 'payee_add',
                            values: ['cancel', 'no', 'not', 'later']
                        }
                    }
		];
exit(views.buttons(buttonTemplate, 'Chose the recommendation Criterion'));

 

It works by the following way:

  1. You create a Button Template Json where each item represents a button
  2. Type can be of multiple types:
    1. Postback
    2. URL
  3. Title is the content of the Variable
  4. Payload is the value that will be passed to the global variable. It has two things:
    1. variable: The variable that is set
    2. value: The Value that is sent to the users
  5. variableType is the text value that can be sent by the user to trigger this action. When the user is shown with the button, then the user can either click the button, or enter text to trigger that action. The text to trigger the action can be mapped in variableType. There are two types of variableTypes:
    1. Using Entity: Here all of the possible values are stored in an Entity and the Entity Object is passed. This is done by:
      1. type: value   (fixed answer)
      2. valuename: This is the entity variable that determines the entity. This can be created by the entity tab.
    2. Using RegexParser: In case of a fixed list, we can use the regex parser variable to define the exact list and then check using a Regex. This is done by:
      1. type: regexParse (fixed answer)
      2. valueName: the global variable that will be updated.
      3. values: The list of variables that can be typed by the user.
  6. Then you send an exit passing views.button and the template json as well as text output.
Was this article helpful to you? Yes No