We need to give the user a good start to their chat with SUSI.AI. Engaging the users with some good skills at the start of the conversation, can leave a good impression about SUSI.AI. In SUSI messenger bots, we show up with some sample queries to try, during the conversation with SUSI.AI. In this blog, SUSI_Tweetbot and SUSI_FBbot are used as examples.
These queries are shown as quick replies i.e. the user can click on any of these sample queries and get an answer from SUSI.AI.
Facebook:
When the user clicks on the “Start chatting” button, we send a descriptive message on what can the user ask to SUSI.AI .
Code snippet used for this step is:
var queryUrl = 'http://api.susi.ai/susi/chat.json?q='+'Start+chatting'; var startMessage = ''; // Wait until done and reply request({ url: queryUrl, json: true }, function (error, response, body) { if (!error && response.statusCode === 200) { startMessage = body.answers[0].actions[0].expression; } else{ startMessage = errMessage; } sendTextMessage(sender, startMessage, 0);
Just a text message is not much engaging. To further enhance the experience of the user, we show some quick reply options to the user. We have finalized some skills to show to the user:
Due to the character limit for the text shown on buttons, we try to show short queries as shown in the above picture. This way the user gets an idea about what type of queries can be asked.
Generic template, help us achieve this feature in SUSI_FBbot.
The code snippet used:
var messageT = { "type": "template", "payload": { "template_type": "generic", "elements": [{ "title": 'You can try the following:', "buttons": [{ "type":"postback", "title":"What is FOSSASIA?", "payload":"What is FOSSASIA?" }] }] } }; sendTextMessage(sender, messageT, 1);
As seen in the code above, each button has a corresponding postback text. So that whenever that button is clicked the postback text is sent to our chat automatically:
This postback text acts as a query to SUSI API which fetches the response from the server and shows it back to the user.
Twitter:
As SUSI.AI bots must be generic among all the messenger platforms available , we will inculcate the same skills available in SUSI_FBbot to SUSI_Tweetbot. The quick reply feature provided by Twitter devs help us to accomplish this task at hand.
As in SUSI_FBbot a descriptive message is shown to the users first and then some quick reply options following it.
Message_create event helps in adding quick replies:
var msg = { "event": { "type": "message_create", "message_create": { "target": { "recipient_id": senderId }, "message_data": { "text": "You can try the following:", "quick_reply": { "type": "options", "options": [{ "label": "What is FOSSASIA?", "metadata": "external_id_4" }] } } } } }; T.post('direct_messages/events/new', msg, sent);
One thing to keep in mind while coding is to send the quick reply message after the initial descriptive message i.e. the code used to send quick replies should be written inside the function, which sends the descriptive message first and aafter that step is complete it runs the code for quick replies. If we accidentally write quick reply code outside that function, it’s highly likely to find bugs in the replies by SUSI.AI.
Resources