Integrating API.AI agent to SMS chatbot

Now that we have an API.AI agent and a Node.js interface to interact with it, let's move on to integrate it with the two-way SMS chatbot we have been building. To do this, we need to revisit the index.js file which is the web app that responds to the incoming SMS messages. We will copy and rework the code from apiai.js to call the API.AI agent from index.js:

  1. In the Twilio webhook, call the API.AI agent with the user's utterance. We shall also use the user's phone number as sessionId so that the context of the conversation is not lost:
//Twilio'/sms/', function (req, res) {    //send it to the bot        var sessionId = req.body.From;    var userUtterance = req.body.Body;        //API.AI  var apiai ...

Get Hands-On Chatbots and Conversational UI Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.