This application is a submission for the Twilio Hackathon on DEV. Covid News leverages the twilio api to send out daily SMS messages to the individuals that have subscribed. Included in the text message would be state statistics for total case, positive and negative counts, and number of deaths. Along with the state statistics will be the latest 5 national news headlines to jumpstart the morning.
This application is a barebones Node.js application using Express.js, Mongoose.js and Pug Templating for webpages. A cron job is setup to run at 8:00AM to get all the users in a MongoDb collection. It gathers the news and the stats based on the state from 2 different APIs then sends a text message to the user.
- Node.js web server using Express.js
- Basic web user interface using Pug for templating and Bootstrap for UI
- User interface to allow users to subscribe to the SMS message list
- Project specific environment variables using
.env
file
- Once the server is started, navigate to localhost:3000
- Input your phone number and state into the web form
- Text message should be received at 8:00am with the updated stats and news
- To unsubscribe, reply to the text message.
Before we begin, we need to collect all the config values we need to run the application:
Config Value | Description |
---|---|
Account Sid | Your primary Twilio account identifier - find this in the Console. |
Auth Token | Used to authenticate - just like the above, you'll find this here. |
Phone number | A Twilio phone number in E.164 format - you can get one here |
We also need to setup a webhook within Twilio to handle replies to texts so that it allows the users to unsubscribe from the SMS list through text. The webhook will need to be directed to /user/unsubscribe.
- Follow the "Configure Your Webhook URL" section: Webhooks
After the above requirements have been met:
- Clone this repository and
cd
into it
git clone https://github.com/RozzaysRed/covid-news.git
cd covid-news
- Install dependencies
npm install
- Set your environment variables
Create .env file at the project's root directory and add the following variables.
Variable Name | Description |
---|---|
TWILIO_ACCOUNT_SID | Your primary Twilio account identifier - find this in the Console. |
TWILIO_AUTH_TOKEN | Used to authenticate - just like the above, you'll find this here. |
TWILIO_PHONE_NUM | A Twilio phone number in E.164 format - you can get one here |
MONGODB_CONN_STRING | Connection to your MongoDb instance |
See Twilio Account Settings to locate the necessary environment variables.
- Run the application
npm start
Alternatively, you can use this command to start the server in development mode. It will reload whenever you change any files.
npm run watch:start
- Navigate to http://localhost:3000
That's it! |
This project is open source and welcomes contributions.
No warranty expressed or implied. Software is as is.