Showing “Get started” button in SUSI Viber bot
When we start a chat with SUSI.AI on Viber i.e. SUSI Viberbot, there should be an option on how to get started with the bot. The response to it are some options like “Visit repository”, “How to contribute” which direct the user to check how SUSI.AI bot is made and prompts him/her to contribute to it. Along with that an option of “start chatting” can be shown to add up some sample queries for the user to try. To accomplish the task at hand, we will accomplish these sub tasks: To show the “Get started” button. To show the reply to “Get started” query. To respond to the queries, nested in the response of “Get started” Showing “Get started”: The Viber developers platform notifies us when a user starts a conversation with our bot. To be exact, a conversation_started event is sent to our webhook and can be handled accordingly. The Viberbot shows a welcome message to the user along with a Get started button to help him/her start. To send just the welcome message: if (req.body.event === 'conversation_started') { // Welcome Message var options = { method: 'POST', url: 'https://chatapi.viber.com/pa/send_message', headers: headerBody, body: { // some required body properties here text: 'Welcome to SUSI.AI!, ' + req.body.user.name + '.', // code for showing the get started button here. } json: true }; request(options, function(error, res, body) { // handle error }); } The next step is to show the “Get started” button. To show that we use a keyboard tool, provided by Viber developers platform. So after the “text” key we have the “keyboard” key and a value for it: keyboard: { "Type": "keyboard", "DefaultHeight": true, "Buttons": [{ "ActionType": "reply", "ActionBody": "Get started", }] } The action type as shown in the code, can be “reply” or “open-url”. The “reply” action type, triggers an automatic query sent back with “Get started” (i.e. the value of "ActionBody" key), when that button gets clicked. Hence, this code helps us tackle our first sub task: Reply to “Get started”: We target to make each SUSI.AI bot generic. The SUSI FBbot and SUSI Tweetbot shows some options like “Visit repository”, “Start chatting” and “How to contribute?” for the “Get started” query. We render the same answer structure in Viberbot. The “rich_media” type helps us send buttons in our reply message. As we ought to use three buttons in our message, the button rows are three in the body object: if(message === "Get started"){ var options = { method: 'POST', url: 'https://chatapi.viber.com/pa/send_message', headers: headerBody, body: { // some body object properties here type: 'rich_media', rich_media: { Type: "rich_media", ButtonsGroupColumns: 6, ButtonsGroupRows: 3, BgColor: "#FFFFFF", Buttons: buttons } }, json: true }; request(options, function(error, res, body) { if (error) throw new Error(error); console.log(body); }); As said before, 2 type of Action types are available - “open-url” and “reply”. “Visit repository” button has an “open-url” action type and “How to contribute?” or “start chatting” has a “reply” action type. Example of “Visit repository” button: var buttons…
