How To Make Facebook Messenger Chat Bot With

Alright, Time has finally came where we have started moving from GUI to Conversational UI (CUI), We are moving into world where we would be conversing with technology as we would do with any other person, for Iron-Man fans, Yeah its right Jarvis is going to be a real thing soon enough and with this ability computing is going to be much easier and as app and smart phone ecosystem came and changed our life so will the conversational UI.

But understanding human speech has its own challenges, what we humans have learned and created over so many years about language and speech can not be tought to computers via some algorithm or formula it needs much more than that. It needs the computer to recognize patterns and create its own understanding and here is where machine learning comes to rescue you can Google more about it if you are interested.

But for us developers we don't need to teach our system the language because giants like Google and Facebook are here to help you out. Google provides service called which helps you build conversational user experience.

What We Are Going To Build

We are going to build a Facebook messenger bot which would recommend you movie based on your genre preferences selection

This tutorial would be in two parts

Part 1 - Creating Agent and connecting it with Facebook Messenger

Part 2 - How to make a node.js backend for Facebook Messenger Chat Bot
(Connecting our bot to api with Node.js backend for movie recommendation)

Getting Started With 

Step 1. Sign up to and log into your account you would be presented with the dash board.

Step 2. Click on create a new agent, consider agents as your project engine which process language and spits out actions you define when language input matches the pattern you want.

Step 3. Name your agent now, I am naming my agent as "MovieBot", add a description and hit save button 

Understanding API.AI Agent

There are two important things that you need to understand about api,ai agents before we move any further, These are the two main components of the service.

1. Intents - Think of intents as actions you want your bot to send to you along with the parameters you want for ex. Our movie bot has only one action and that is to recommend movie, so the intention or the intent can be defined as movie.recommendation  

2. Entities - Entities are concepts that your bot should understand and using this concepts your bot would extract parameter values for your intents, our movie bot is going to recommend movies based on genre you wants so one concept that our bot needs to understand is genre so movie.genre would be one entity for our bot. similarly if we want our bot to recommend movie based on cast we would add movie.cast as one of the entity as well.

Creating Entities

Now as we know about entities lets start with adding one for our movie bot

1. Click on the entities tab on your dashboard
2. Then click on Create Entity button on top right
3. You would be on a page similar to shown in below screen shot.

Step 4. Fill the fields as shown in the above image, First lets name our entity movie-gener then in the space below add a row  and in it add some examples of movie geners as you can see in the screen shot. The left hand side is the parameter value that you want your bot to send to your backend and right hand side are the words or phrases that could map to those parameter value for example when your says "show me some funny movies" I want this to send me movie-gener parameter with the value of comedy, so in the left hand side I have named the parameter value and in right hand side I have mentioned some synonyms or phrases that should be used to map.

Step 5. After you have added your examples click on save, give it some time to save do not close the browser.With that we have the Entities part ready.

Creating Intent 

As we had discussed earlier we know that intents help us map user said phrases to developer defined actions or we can call it developer defined intents.

Step 1. Click on intent on dashboard and then hit create intents
Step 2. Name your intent, our intent is just one and that is movie recommendation, so I have named it movie.recommendation
Step 3. There are three sections to creating intents that are

A. User Says

Here you would add some example phrases that would trigger your movie intent, For movie recommendation a user might say something like "I  would like to watch a movie" which would trigger our Intent we are also going to handle the genre which a user could say something like "I would like to watch a horror movie" so all such phrases we would add in the user says section while you add those you can highlight a single word in a sentence and define which entity it matches if the agent it self doesn't understands the entities in the sentence you can read more on this from the offical documentation.

B. Action

Here you define what action would be triggered for your user says phrases, for us its our intent action it self so we have mentioned the action to be movie.recommendation along with this action we can see the list of parameters that have been extracted from our user says example phrases, from the list we can define if any parameter is absolutely required for our action by ticking the required box. As we need movie genre to be specified for us to provide the movie result we have marked it as required. But what if user says something like "I want to watch a movie" then we can not just leave the user blank as we dont have a gener to show him the movies. In such case bot will send the prompt question that you have set to extract the required parameter from user. So If user says "I want to watch a movie" our bot would reply with "From which gener do you want ?" and extract the required parameter.

C. Response

And finally when all is perfect and you have your required parameters here is where you define what the response text from the bot would be.

With this we have our conversational engine set up we can test it on it self via the "Try it now" console.

Here is the screen shot of our bot in Try It Now console

As you can see It is working fine, We first hit the agent with the query "I would like to watch a movie" for which we receive the response "From which gener to do you want ?" as agent was not able to find the genre from the query . Then we enter "I think I am in mood of horror movies" and agent gives us the response "I think you would like the following movies"  with intent value of movie.recomendation and movie-gener parameter value set to Horror just as we had wanted.

With this we have our Converstional UI tested and ready to be integrated with Facebook Messanger Platform 

Integrating Bot with Facebook Messenger

Now we need to connect the bot with Facebook messenger, For that we need to follow the following steps

Step 1. Log into Facebook Developer Console and create a new app as shown below.

Name your app with your agent name here, add your email id and select apps for messenger as the category then hit create App ID.

Step 2. Now you would be taken to a screen as shown below, you have to select a page for your messenger bot, if you dont have a page created you can create a new page and come back to this page, after selecting the page facebook will generate a Page Access Token for that page

Copy that Page access token and save it somewhere we would need it in the next step

Step 3. Now time to actually connect the page we created with the api,ai agent we made earlier for that go to dashboard of your agent and select integration as shown in the picture below.

Enable the Facebook Messenger toggle and click on setting.
In the settings panel enter the details as shown in the picture below


Add a verify token which would help verify your bot identity to FB messenger keep it secret and do not share it. Paste the Page Access token that you had generated earlier here in page access token box, now copy the Callback URL which you would need in the next step.

Step 4. Now we need to configure Webhook go to the developer page on Facebook, In the products tabs go to messenger and click on set up webhooks, you would see a screen as shown below, Paste the Callback URL that you copied in last step and also enter the verify token you created previously, tick the messages and messages_postbacks check box and hit verify and save.

Step 5. Now its time to test the first phase of our bot, go to the page you created for your bot and try and send a messenger to the the page, If you have correctly followed the tutorial you would have your bot give you response as below.

So we have successfully created our Facebook bot which can handle basic conversations and extract out the parameters required to fulfill user requirement i.e movie recommendation.

In the next part we would connect this bot to movie API from TheMovieDb and thus provide user a movie recommendation as we had decided.

Here is the next part of this tutorial - How to make a node.js backend for Facebook Messenger Chat Bot

Akash bangad

Computer Engineer from Maharashtra,India. Trying to make my way in the world of mobile development. Steve Jobs admirer and techy at heart.


  1. I had some issues integrating it with facebook messenger, also i want to discuss more about the bot. Ping me on

    1. Hey let me know what issue you are facing, Ill help you out solve the problem


  2. The blog or and best that is extremely useful to keep I can share the ideas
    of the future as this is really what I was looking for, I am very comfortable and pleased to come here. Thank you very much.
    tanki online | 2048 game |
    tanki online game

  3. In your blog I was happy to see your article, better than last time, and have made great progress, I am very pleased. I am looking forward to your article will become better and better.
    hotmail login | red ball

  4. Thanks for sharing your info. I really appreciate your efforts and I will be waiting for your further write.
    Thanks for sharing !
    tanki online 2 | 2048 game online

  5. Your blog posts are more interesting and impressive. I think there are many people like and visit it regularly, including me.I actually appreciate your own position and I will be sure to come back here.
    facebook entrar l outlook iniciar sesión l hotmail login l baixar facebook

  6. In your blog I was happy to see your article, better than last time, and have made great progress, I am very pleased. I am looking forward to your article will become better and better.
    hotmail login | red ball |

  7. Your blog is extremely brilliant especially the quality content is really appreciable.
    Web & Mobile App Development Services


  8. The blog or and best that is extremely useful to keep I can share the ideas
    of the future as this is really what I was looking for, I am very comfortable and pleased to come here. Thank you very much.
    tanki online | 2048 game| tanki online game

  9. skype is a online application where you are able to make voice calls over the internet. You may also use skype to video conference with other users. When you make voice calls, if you are contacting a skype member it is free, and on the other hand when you contact someone who is not a member you will be charged.

  10. Much thanks to you for your fascinating infomation super mario world

  11. Thank you for this tutorial! Very simple and informative!
    json formatter online

  12. Wow never essay writers knew what I'd find when I clicked on the link

  13. Thanks man... Keep writing great articles

  14. Hi , Thanks for the tutorial.

    I want to get facebook username ? How to do that ?

  15. Your site has a lot of useful information for myself. I visit regularly. Hope to have more quality items.
    color switch

  16. Extraordinary occupation for distributed such an advantageous site. Your web log isn't just helpful yet it is moreover truly inventive as well. There have a tendency to be relatively few individuals who can unquestionably compose not all that straightforward posts that creatively. Proceed with the decent composition FtiOS Download

  17. I feel it interesting, your post gave me a new perspective! I have read many other articles about the same topic, but your article convinced me! I hope you continue to have high quality articles like this to share with veryone!
    happy wheels

  18. I've perused some well done here. Certainly worth bookmarking for returning to. I astound the amount of exertion you put to make such an extraordinary useful site. Tinyumbrella Windows

  19. I have read your blog it is very helpful for me. I want to say thanks to you. I have bookmark your site for future updates. TutuApp Android

  20. An intriguing dialog is value remark. I feel that it is best to compose more on this matter, it may not be a forbidden theme however normally people are insufficient to chat on such subjects. To the following. Here's to you. Phantom for SnapChat

  21. Wonderful article, thanks for putting this together! This is obviously one great post. Thanks for the valuable information and insights you have so provided here. Cydia iOS 11.3

  22. I enjoyed over read your blog post. Your blog have nice information, I got good ideas from this amazing blog. I am always searching like this type blog post. I hope I will see again.mother’s day gifts

  23. I acknowledge all that you have added as far as anyone is concerned base.Admiring the time and exertion you put into your online journal and point by point data you offer.Thanks. FlekStore Download

  24. I pay a visit everyday some sites and information sites to read articles or reviews, except this blog offers quality based writing. netflix account

  25. The article is great, thank you for providing complete and easy-to-understand information
    vex 3

  26. I hope you continue to have such quality articles to share with everyone! I believe a lot of people will be surprised to read this article hotmail sign in

  27. This comment has been removed by the author.

  28. Indeed, it is a fact that if you want to judge the abilities of any app developer then assign him such kinds of task which requires API's to be built. It actually requires some sort of experiences in the field. Android app developer Dubai, is the ultimate choice for every client as they got a team of highly experienced and talented app developers that can deliver within the tight deadline as well.

  29. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
    Selenium Training in Bangalore | Selenium Training in Bangalore | Selenium Training in Bangalore | Selenium Training in Bangalore

  30. This is something that you just read and read. You just can’t get tired of it.
    Phone Number for Base Chat in Germany