top of page

How to develop conversational personal Assistant?

  • Karthikeyan Prakash
  • May 31, 2017
  • 3 min read

What are chatbots? Why are they such a big opportunity? How do they work? How can I build one?

These are the questions we’re going to answer for you right now.


Here is a small tutorial and demo on building and using a conversational bot. While there are many platforms available to develop bot with graphical user interface but it’s not free forever. Here we have used open source bot trainer called wit.ai.


Wit.ai acquired by Facebook back in Jan 2015 and assured that it will remain free. Wit.ai implements NLP processing to classify the human entered text/voice into intent and entity classification.

What is Intent and Entity?

Take a look at image above. Here the user entered “Book a table for 3 at Barney’s tonight”. Here the intent of the message is to book a restaurant and hence Intent = restaurant booking. Now, the details required for booking restaurant is given by the user and are called entities. Here, people = 3, place = Barney’s Burger, San Francisco,CA, date = April 27th 2013, 7pm.


Now you may notice that user said tonight and wit.ai converted it into Date and time. This is done by using Duckling (duckling.wit.ai), The linguist that parses text into structured data. Duckling converts the linguist data into structured data based on context.


The intent of the conversation can be trained initially in the wit.ai understanding console.

Context and Actions:

With addition to these capabilities to implement conversation wit.ai provides Stories (now in beta) to train the bot to have conversational questions, confirmation and greetings etc.,. These stories add a functions called actions and context.


Actions: These are the functions which will be invoked based on the intent. The functions can be handled by using the node-wit (wit.ai Node.js SDK). The functions pass variables called context and entities.

For every action it passes the entities in the user entered input and returns the context of the message.

Here when I entered “Hi I am karthik”. The entered text contains the intent to wish (greetings) and entity as contact “Karthik”. Now when the context has both wish and contact the bot sends Hi + wish + contact.


When the user enters the greetings and bot doesn't know the contact name. The context here becomes missing contact.

When the context is missingContact the bot asks user to enter the name. When user enters name it will be identified in entity and then invokes the given function with context and entity.

Here is small demo application developed to understand the conversation bot development

Architecture:

Socket.io Chat Server:

Socket.io Chat server which bridges communication between the wit.ai SDK and user. The socket.io chat server can be cloned from https://github.com/socketio/socket.io

Node wit.ai SDK:

Now I have created a communication between the wit.ai Node SDK to wit by using the server access token. The Node-Wit SDK tutorial can be found in (https://github.com/wit-ai/node-wit).


By default the node-wit SDK prompts the user to enter the text in terminal, Here I modified the code by processing the User entered text from socket.io connection.

Android Application:

I have used the Socket.io Android Application and modified the code to handle the message from our Socket Server. Here the Personal Assistant also becomes one client to Socket server and interacts with other users. Clone the socket.io chat Android Application from github (https://github.com/nkzawa/socket.io-android-chat). Sync the application with your Android Studio Gradle. Once the project is synced and opened we need to do few changes in order to make it work with our chat server.


Open ChatApplication.java. You may notice that mSocket tries to connect to the CHAT_SERVER_URL. Here we need to change the chat server URL to point to our server. In my case it's running on LOCAL IP and 3000 Port.

You can find the defined variable under Constants.java Open and change the default URL to our chat server URL. Refer to the image below.


Connect Android Device and Build Application.

Setting up things for first run

Step 1: Run wit.ai node-wit server

Step 2: Run socket.io Chat server

Step 3: Start Socket.io Android Chat Application

Screen shots of Application:

Server Screen shots:

When I entered the text “Hey”, Text is sent to the wit.ai server and processed to identify the intent and entities. Once the Context is identified based on our story training the wit replies as “Can I know your Name?”. The reply text is then converted into user message from Assistant and sent to the Chat Box.


 
 
 

Comments


Recent Posts
Archive
Search By Tags
Follow Us
bottom of page