About Archives

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.

On this post we’re going to explore how to create a zero coding, AI powered, serverless expense recording chatbot using API.ai, mLab MongoDB and Auth0 webtask.

Chatbot workflow

  1. Our user writes a message to the chatbot (Telegram in this case).
  2. API.ai parses the message and tries to match it with one of our Intents.
  3. Once API.ai has all the required info it calls a webhook served by Webtask.
  4. Webtask receives and saves the data into mLab, then outputs the proper HTTP code.
  5. API.ai checks the Webtask response and answers to the user accordingly.

Technical breakdown

1. Requirements
1. Register an account in API.ai.
2. Create a Telegram bot and save the Authorization Token.
3. Quick-Start Guide to mLab and make sure to save your DSN.
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 Name pre-built agent for speeding up things. I’ll also rename the agent to something more fun, such as accountant-chatbot.

3. Entities creation
Create the Category (example) and Expense (example) Entities so our Assistant can use them to create our Intent.

4. Intents creation
Under the User Says section 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 Action and 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 Spent.

The amount parameter is using the sys.unit-currency API.ai System Entity which gives us a Javascript object with amount and currency properties in case you decide to do multi currency.

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 Intents and enable the “Use Webhook” checkbox under the Fulfillment section of your expense.create Intent.

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 CLI:
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_DSN to 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.