Instant-SMS-Alert is a demo project that utilizes an SMS API to retrieve instant updates on COVID-19 via SMS. The purpose of this project is to provide an example of how to implement an SMS alert/update system in response to disease epidemics.
At the time of creating this project, no known APIs for updates on diseases cases are available; this project parses html from websites to retrieve data. The issue with using this method rather than being able to call an API means that the code relies on the websites used to maintain their structure of where specific elements are placed in the DOM.
- Install node.js
- Set up the app in the Vonage Communications API using the SMS API
- Install ngrok (if running locally). Refer to the docs
- Heroku account (if running remotely on Heroku)
- Clone the source locally and cd into the project.
$ git clone <clone with https url>
$ cd Instant-SMS-Alert
- Install project dependencies.
$ npm install
- Create .env file.
$ touch .env
- Configure environment variables in .env file.
PORT = <port number>
VONAGE_NUMBER = <your Vonage number>
VONAGE_API_KEY = <your Vonage api key>
VONAGE_API_SECRET = <your Vonage api secret>
PRODUCTION = <production type>
- Start ngrok
ngrok http <port number>
-
Link your Vonage application and number to the /webhooks/inbound-sms webhook endpoint.
-
Run the app
npm run dev
- View the demo project on the browser through localhost and enter in your phone number.
-
Create a new app on Heroku.
-
Fork this repository.
-
Connecting your Github account to your app on Heroku.
-
Choose a branch to deploy and start the deploy process.
-
Configure environment variables.
-
Link your Vonage number to the /webhooks/inbound-sms webhook endpoint.
-
Go to the app url and type your phone number.
Here is an explanation of some of the project files and to modify them for your own use.
These are constants that hold commands that are read in from inbound messages. Commands are written in the following format:
<command>: {
cmd: <The command that the user enters>,
desc: <Describes what the command does>
}This file contains a function sendSms to take in the toNumber, fromNumber, and command message. The command message is then searched through a switch statement to see if the command is valid or not. Using the constants file, the switch statement can be modified as follows:
switch(command) {
case K.<Your new command>.cmd:
// Statements to execute when the
// command is found.
break;
}These are constants for the sources used to retrieve data. Sources are written in the following format:
<source name>: {
html: <URL of the data to be fetched>,
source: <source name>
}This file uses jssoup to parse html. The function sendSms takes in a fromNumber, toNumber, source, and country to retrieve data then issue an SMS message. The source is used in the switch statement to identify which instructions to execute next. Using the sources file, the switch statement can be modified as follows:
switch(source) {
case sources.<Your source name>.html:
fetch(sources.<Your source name>.html)
.then(response => response.text())
.then(html => {
let soup = new JSSoup(html);
// Add statements to fetch the data
})
.catch(err => {
console.log(err);
});
break;
}- Vonage Communications API
- Node.js, Express.js