Build a facebook chatbot with API.AI (zero coding)
Messenger bots simply blend artificial intelligence with human interaction. User asks a question and chatbot gives relevant answer to serve the purpose.
What do we need to build our facebook chatbot?
- API.AI account - A natural language understanding platform to design and integrate intelligent sophisticated conversational user interfaces.
- Facebook for developers account - To create a facebook app.
- Facebook page - Chatbot feature is only available to pages, not personal accounts.
What we are going to doWe are going to subscribe our API.AI agent to read all messages we receive on our Facebook page and in turn our agent processes the message and responds the way we have trained it.
Steps to setup API.AI and Facebook Messenger
- Create a facebook page, I have named it TestBot.
- Make facebook app with your facebook developers account.
- Set up your API.AI account and create a new agent.
- Next, we will add product(Messenger and Webhooks) to our Facebook app. Click on Add Product button and then click on Set Up in both Messenger and Webhooks boxes.Once both Messenger and Webhooks are added, you will see them added under PRODUCTS tab.
- Now, under PRODUCTS tab click on messenger and under Token Generation tab select your page to get the token.
- Open the Integrations tab in API.AI and Turn ON the Messenger integration. Click on Settings, paste the facebook access token copied in above step, write the unique VERIFY TOKEN and hit START. Also copy the callback URL.
- In Facebook developers page click on Messenger tab then select Setup Webhooks and paste your Callback URL and the Verify token from API.AI page. Click Verify and Save.
Setup responses in API.AIWe are already provided with 2 default intents. The Default Welcome intent replies to greeting messages and the Default Fallback intent replies if bot doesn't understands something. That's a good starting point.
Before we start, let's understand 2 important things: Intents and Entities
Intent: We classify user's queries as intents which means how a user is going to ask something from the bot. Example: send me some cool jokes
Entity: This is what we are looking from user as a value, let's say "send me 3 jokes", here we can consider 3 as a number entity and jokes as category entity(not required though). Then we process this on our webhook and send the response. Don't worry if you are not getting this, we are going to work only with intents right now.
Let's create some intents:
- Create a joke intent. Add a few queries, the way user can ask for a joke i.e. send me a joke, or simply joke.
- Now, come down the screen and add a response to this query, a joke. For this, we need to add a FACEBOOK MESSENGER response by clicking the + button next to Default Response and then add the Text Message.
- Same way we are going to create an image intent, add a user query and submit the response as image, so that the image is displayed for the query.
These are only static responses, for dynamic responses we need to create a webhook which is not covered in this tutorial.
- Facebook webhook setup subscribed to TestBot page. Check
- API.AI connected to Facebook page. Check
- Intents created. Check
Wow, we have made our first simple chatbot which sends joke and a capuchin pic on demand. Now, go ahead and try to use this to create awesome chatbots.
Chatbot responses shall only work for page admins/moderators not for public until they are verified by facebook.Additionally, we can also give some small talk sense to our chatbot by importing the small-talk pre-built agent from the Pre-Built agent tab. Oh yeah!
If you have any queries/suggestions write below in the comments or send me a mail at email@example.com. See you in the next tutorial!