Making a serverless chatbot powered by AI
Over the course of the last few months I have been doing research and working extensively on serverless architectures. I’ve been thinking a lot about the notion of “zero coding apps” and I can only say good things about it.
- Our user writes a message to the chatbot (Telegram in this case).
- API.ai parses the message and tries to match it with one of our Intents.
- Once API.ai has all the required info it calls a webhook served by Webtask.
- Webtask receives and saves the data into mLab, then outputs the proper HTTP code.
- API.ai checks the Webtask response and answers to the user accordingly.
1. Register an account in API.ai.
2. Create a Telegram bot and save the
3. Quick-Start Guide to mLab and make sure to save your
4. Setup webtask.io CLI.
5. Create a requestb.in for debugging your API.ai Bot.
2. API.ai account creation
If you never used the API.ai service before, it’s recommended to read their Getting Started with API.ai as we’ll use some concepts from that page.
We’re going to use the
Agent Namepre-built agent for speeding up things. I’ll also rename the agent to something more fun, such as
3. Entities creation
Expense(example) Entities so our Assistant can use them to create our Intent.
4. Intents creation
User Sayssection we’ll add as many trigger messages as we can, mapping their different components to our Entities.
Writing more entries here will make the chatbot appear more natural in it’s interactions.
Review the parameters under
Actionand configure the “Prompts” so the chatbot can ask our user if it’s missing any info.
This is also reused for the catch-all phrase
amountparameter is using the
5. Configuring Telegram integration
Go to Integrations ➔ Telegram and enable the Integration by pasting your
Telegram Bot Authorization Token.
6. Temporary webhook setup
Go to Fulfillment and enable the Webhook using the requestb.in URL.
Then navigate to
Intentsand enable the “Use Webhook” checkbox under the Fulfillment section of your expense.create
Try messaging your Telegram bot until you see the webhook data on the requestb.in bucket.
7. Webtask setup
Since this is a zero coding chatbot we must use an already existing code for saving to the database, fortunately that is easy thanks to the
wt create --secret MONGO_DSN=YOUR_MONGO_DSN_HERE https://raw.githubusercontent.com/francolaiuppa/webtask-create-expense-bot/master/index.js
Make sure you change
MONGO_DSNto use your own. Save the URL of the generated webtask.
8. Test and deploy
Change the API.ai Webhook to point to your webtask, confirm it works by creating an expense talking to the chatbot and then reviewing the database.
Not bad for a bot that didn’t require code and was trained under 15 minutes!.
Giving users the ability to mix different building blocks to solve their own problems is indeed a very good thing as there is no generic app or service that can be tailored to meet the exact user needs.
The development industry must also adapt to this change by lowering the entry barrier to interact with their services (where applicable) and having developers embrace the fact that more often than not, non-developer users will be using their building blocks.
If you want to to be notified of new posts and join the discussion follow me on Twitter.