In an earlier post, We went over how to set up Todoist in our node JS project to integrate it with the Whatsapp bot. We set up the API and also fetched and displayed all our pending tasks. You can read the post here.
In this post, we will go over adding new tasks, completing existing tasks and also deleting unwanted tasks.
Adding a new task
If we follow the documentation to add a new task, we can see that we need to provide the content for the task and use a unique ID every time we add a new task. So let's set up a basic command where we can enter the task content and it automatically gets added to our to-do list. I think the command
add TASK_NAME would be a good start.
Once we get this setup, we should be able to add our tasks to Todoist using Whatsapp. The tasks by default get added into the Todoist inbox and I am adding a deadline of the same day as I intend to use this for immediate tasks. You can explore the API further and even go as far as adding the tasks to a specific project.
Completing a task
If you look at the documentation for completing/closing a task, you will see that we need the task ID. To get this, I updated my original task list API to return the task ID along with the content and the due date. Now I can just send back the ID in my command to tell Todoist to complete that task -
Deleting a task
The deletion API is very similar to the completion API except for the fact that we have to use the
DELETE request instead of the
POST request. We will also be using a similar command where we just say
We can now see our list of tasks, add new tasks, complete pending tasks and delete unwanted/canceled tasks. Here is a screenshot with all the features in action!
With these features, I think I am done with the Todoist part of my Botler experiment. You can find the updated code here!
What other features do you think I should add to the bot? Feel free to hit me up with your ideas on Twitter!