Facebook Messenger chatbot (short) history
When Facebook announced the Facebook Messenger APIs in 2016, developers and marketers ware saying that bots are the new apps and in a couple of years we will quit installing new apps on our smartphones. The voice commands are the new UI making the mobile apps obsolete. Now it’s 2020 and we can all see we are not there (yet). Nevertheless, the chatbots are slowly crawling in our everyday lives in one form or another. It’s clear that they are a popular piece of software since we already have the App Store equivalent for chatbots (see Botlist.co and There is a bot for that)
Facebook Messenger chatbot architecture
Now, you may be wondering what are the main components for a Facebook messenger chatbot and what you need to do to build and deploy one. For performance and cost reasons, the chatbot will be deployed on AWS. Let’s see the high-level architecture.
First, you will need an AWS Lambda function to handle incoming user messages. When a user types something in the Facebook Messenger chat, Facebook redirects that message to your AWS Lambda handler.
A simple Facebook Messenger chatbot can work without any database connection but in most cases, a database is required. For this purpose, you could choose between a MySQL instance under the AWS Relational Database Service (AWS RDS) or DynamoDB depending on your use case.
After the AWS Lambda function is deployed, you will get a URL where you can call your function. The URL might look like this https://xxxxxxxxxx.execute-api.eu-west-1.amazonaws.com/dev/facebook-messenger-callback.
You can use this URL directly in your Facebook Developer console. However, if you want to have an easier to use URL you need to set up a custom domain in AWS API Gateway. After you set up the custom domain you can link it to your AWS Lambda function and resulting in a Facebook Messenger chatbot callback that could look like this bot.mydomain.com/facebook-messenger-callback that is easier to remember.
For your custom domain to work, assuming that your domain registrar is AWS, you need to use AWS Route 53 to alias your domain to your AWS API Gateway deployment.
Now that you have a high-level idea about what is the architecture of a Facebook Messenger chatbot deployment on AWS you can go and start implementing one yourself.
If you have suggestions or questions, please use the comment section below, I am happy to discuss with you. Don’t forget, improvements can always be made.