CovidX : Watsapp Chatbot for information on Covid-19
Tags: twiliohackathon, python, covid19, opensource
Published: 2020-04-10 21:18:31

---
title: CovidX : Watsapp Chatbot for information on Covid-19
published: True
description: My submission to the Twilio x DEV Hackathon!
tags: #twiliohackathon,#python, #Covid-19, #opensource
---

[Comment]: # (All of this is placeholder text. Use this format or any other format of your choosing to best describe your project.)

[Reminder]: # (Make sure you've submitted the Twilio CodeExchange agreement: https://ahoy.twilio.com/code-exchange-community)

[Important]: # (By making a submission, you agree to the competition's terms: https://www.twilio.com/legal/twilio-dev-hackathon-terms)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/eb61d3n0zq4d83gojfeq.jpg)

## What I built
Hi, I have built here a **Watsapp chatbot using Twilio API for WhatsApp** which gives Corona virus statistics from all over the world and also a special provision for India as it can give information about the states of India which have covid-19 and the number of people infected as well as the stats of the internal districts with all the number of people inflicted by covid-19. 

The main idea behind this project was to keep you informed in a nice systematic manner where all the information from world cases to your state to your districts will be available into just **1 Watsapp chat group** and no other hassle of downloading another app or going to another website. And also you can share that info as simple as forwarding that info to someone on watsapp without the problem for other person to go on any other 3rd party app or website.

**I have divided this project in 4 ways :-**
1) First is to get the list about all the countries infected by covid-19 all around the world.
2) Get the information about each independent countries and about their stats of how many are active cases, total cases and total no. of deaths and other infos.
3) Get data about each independent states in india and similar info as that for the independent countries.
4) Get the list of districts as well as the infected number of the infected cases in each districts.

## Demo

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/oxcc8ygwguvvqn4vzeqs.gif)

## Link to Code
The complete project is opensource and you can find it at https://github.com/Adarsh1999/CovidX
Instructions to run project is in readme.

## How I built it (what's the stack? did I run into issues or discover something new along the way?)

The project contains the following tech stack:
1) Python
2) Flask
3) 3rd Party API for country information
4) Twilio python library
5) 3rd Party API for information about Indian states and districts.

Firstly to start with I was very rookie to this topic when I started thinking about this project or this hackathon or about Twilio so I am sorry if you feel that this project is not that unique or special. I thought that what I can make that is easy for a beginner and I will also use it for my day-to-day routine also
I was very excited to have a first hand experience with the Twilio APIs. So I decided to make a watsapp chatbot which will do that for me.

On internet there already exists many website or tracker for the same purpose but what makes my project unique was that in India almost all indians use watsapp and also its the most widespread chatting app so I almost open this app atleast once in 30 mins everyday and if I have to share any information I my primary source of sharing is also watsapp so making a chat bot for that purpose was great.

So I started working with **flask** and took help of various blogs about which I will be giving links in Additional Resources section. The important things I learned from here is how to use Twilio console and dashboard and made my self familiar with the twilio watsapp console. How to use **ngrok** to redirect my localhost port for the twilio to work on. Then I learned how to use various APIs and integrate it with my flask app and also sending and receiving messages from watsapp to twilio and vice-versa. 

The **main challenges** for me was that to find good APIs and then parse them according to my needs. But this was not that big a issue for my global data API but unfortunately for information about India and its state there was no APIs and services I could find easily so it took a hack of a time for me and I even did web scrapping from governments official site  [https://www.mohfw.gov.in/](https://www.mohfw.gov.in/) but still the data about districts was unknown so for that thing I thought of webscrapping the tables of states on wikipedia such like this: https://en.wikipedia.org/wiki/2020_coronavirus_pandemic_in_Gujarat
and thought that I will scrap the table situated in the page and also for the unique states I would change the url of the wikipedia with other state but that thing didn't worked because urls were very case-sensitive and with states name like Madhya Pradesh there it was hard to do the same as many didn't follow the trend and also didn't had Wikipedia page. So I surfed a lot and found this hidden link of API for indian states and districts which is : https://api.covid19india.org. And also the data which was coming from the state API was not in a good format so making it according to my need was important too.

Also I have to deal with another thing which is max length of a message which is 1660 characters so I had to break one of my output in 2 parts also so to not exceed the limit.

For further implementation I would like to integrate **chatterbot** in it which enables the bot to make small talks with a user with just 2 lines of code. So that will make it a more of a chatbot.


## Additional Resources/Info 

 - **For staring with watsapp api of twilio** : [https://www.twilio.com/blog/build-a-whatsapp-chatbot-with-python-flask-and-twilio](https://www.twilio.com/blog/build-a-whatsapp-chatbot-with-python-flask-and-twilio)
 - **API for global covid-19 data**: https://api-sports.io/documentation/covid-19#operation/get-history
 - **API for the Indian State and Districts**: https://api.covid19india.org