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 an array which contains all snapshots of cases. We will use the latest, which means the last element of the 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); }); }
Top comments (1)
Good work