Build COVID19 SMS Tracker using Twilio + NodeJS
1 min readApr 11, 2020
In this blog, we will learn to build COVID19 SMS Tracker using external API and Twilio.
Let’s get started,
Install the required packages
npm install --save express twilio axios
We will be using an external REST API to get COVID19 Cases.
First, get the latest COVID19 cases for India using Axios.
const covidINdata = await axios.get('https://api.covid19api.com/live/country/india/status/confirmed');const latestData = covidINdata.data;//API returns array which contains all snapshots of cases. We will use latest, means last element of array.
const data = latestData[latestData.length - 1];
Now configure, Twilio SMS API
Signup for Twilio, and get Account ID and API KEY.
const ACCOUNT_ID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
const API_KEY = "your_auth_token";const client = new twilio(ACCOUNT_ID, API_KEY);
Create body and send SMS,
client.api.messages.create({
body: data, //This is SMS body, returned from API
to: 'your_mobile_number',
from: +12569789527
}).then(data => {
return res.status(200).send('SMS has been sent' + data);
}).catch(error => {
return res.status(404).send(error);
});
}
Code: