My experience of building a Facebook Messenger chatbot
Since Facebook launched Messenger with chatbots back in 2016, there are now more than 100,000 chat bots for Messenger now. According to Facebook, each month there are over 2 billion messages sent between people and businesses — including automated conversations. Messenger is no doubt an important platform for businesses to reach out to customers or potential customers. Messenger chat bots can be very useful as a virtual personal shopping assistant to customers, or as a replacement of automated phone call systems. I can see a lot of potential in chatbot in helping businesses to increase sales.
Imagine when you want to a buy a little black dress from a website, you can tell the chatbot you would like to find a little black dress for a special occasion. Via the Messenger Platform’s new Send/Receive API, chat bots can send back structured messages that contain buttons, links and images. The chatbots will display images of all the black dresses for special occasions in product carousel for you to choose from. You can further ask the chatbot to find the younger or more mature styles for you. Once you decide on the one you love, click on the image, and this will lead you to the website to make a purchase. This makes customer/user’s experience a more personalized and interactive one. For me as an almost all time internet shopper, I am pretty tired of using website’s product filters to filter out the products I want. A lot of time it still returns hundreds of items even after applying all the available filters . A chatbot that works like a shopping assistant will highly enhance customer's experience.
Another use case is replacing those automated phone call systems. For those who hate waiting over the phone forever and selecting from endless menu in order to get assistance like I do, I believe they would prefer getting assistance from a chatbot instead. The most frustrating thing about getting through the endless menu is that in the middle the phone call was cut off, and you have to start everything again.
A chat bot for user to get information on movies and celebrities
As I think chatbot is pretty useful, I decided to build a chat bot on Facebook Messenger platform for me to further understand how it actually works. It is based on a set of rules, and only respond to specific commands. My chat bot allows users to query information on movies and celebrities in a interactive way. The technologies I use are NodeJS, ExpressJS, MongoDB.
After user enters a movie's name, the chat bot will confirm with user if it is the correct movie one is looking for . If user replies it is the correct movie, the chat bot will ask user what information he/she wants to know. If user wants to know the cast, the chat bot will show user the major actor/actress in the cast. Then the user can query chat bot further about a particular celebrities. Or user can choose to get other information on the movie rather than querying further about the cast. User can also choose to get information on another movie so that the session on the former movie will be ended.
The APIs used
There are several major APIs that play important roles in a Messenger chat bot. The Facebook Graph API is for getting data in and out of Facebook’s Messenger platform. The server of my chat bot app has to make use of Graph API to receive, process and send back messages while the chat bot communicates with Facebook users. Facebook’s server needs to talk to our server, and thus our server has to have an endpoint URL that is accessible from Facebook’s server. I deploy the app to Heroku where all domains are SSL-enable as Graph APL requires secure HTTPS callback URL.
I have to also enable the webhooks integration so that whenever users send messages and other events to the chat bot, I can track and receives updates in real time. Webhooks receive calls through HTTP POSTs only when the messenger has data updates from users.
Database
As Messenger doesn't keep a session open with our webhook, any data you store in a session will be lost if user makes a new request. User then won't be able to get another piece of information on the same movie. In order to allow user to be able to make further queries on the same movie/celebrity, I need to set up a database to store the movie/celebrity that the user is interested in. MongoDB is used for database for this project.
Conclusion
It is pretty fun to build a Messenger chat bot and to see see it fully function. Because I use free Heroku service, the response rate of the first query is a bit slower than I want. After the first query, the responses are prompt. I am looking forward to building another chat bot using machine learning which will allow the chat bot to interact with users in a more natural way.