I love bots, both building and using them. They make complex tasks simpler, mostly by reducing the number of steps you need to do before completing them. Earlier this year, I built a bot that gets information from the Fantasy Premier League website. It would let you look up players, their teams, your individual score and also notify you of price changes. I later had to move the bot to Telegram because I don't have a registered company so I couldn't launch it on Whatsapp but that's a story for another day/post. You can check it out here if you'd like.
But today, I had another idea, to build a personal Whatsapp bot. Think the Alfred to my Batman. It could do nothing but at the same time, it could do anything and everything I wanted. So, let's get started.
You need to go through the initial steps that involve signing up for and setting up the bot using Twilio. I started writing about it and then remembered that I myself followed this post by Samarth Jajoo. In his tutorial, he uses repl.it. I faced some issues with repl.it so I personally opted for Glitch. I also set up a very basic app on Glitch that responds with
Hello there to every single message. You can fork it here if you'd like to use Glitch as well. Just make sure you set up the environment variables in the
.env file properly. You can find your account ID and auth token for Twilio here.
To begin with, I thought we could start with something simple and get the bot to show me my to-do list.
Let's start by integrating the Todoist API so we can fetch our tasks. The first thing we need to do is get our Todoist API token and add it to our project so let's create an environment variable called
TODOIST_TOKEN. You can find your token here. We also want to install
moment to our project as we will be using those libraries to help us with our implementation. Oh, and it always helps to have the documentation handy, so here's a link.
First, we want to make a request to the Todoist API to fetch all our active tasks.
Next, we want to filter and get only our pending tasks.
We can now format the tasks any way we want to before we send them back as a message to ourselves. I, for now, am going to fetch the task content and its due date.
Once we put it all together, this is what it looks like.
We can use this as a starting point and implement things like adding new tasks, completing existing tasks and even deleting unwanted tasks. I'll probably write another post going over how to implement those features into our bot. In the meantime, you can try rebuilding this bot for yourself and tell me how it went!
Feel free to throw any questions/ideas about the whole project to me on Twitter. You can also find my version of the app on Glitch and simply fork it if you don't want to bother with the implementation yourself. You can find it here.