Simple NodeJS program to notify clients by SMS when certain conditions are met on a web page's source content.
First: you'll need an activated Twilio account. Free trial works OK.
Then:
git clone https://github.com/tomtwo/midcheck
cd midcheck && npm install
# Configure package.json with Twilio API credentials and target SMS number
# Modify app.js to include your checks
npm start
It's recommended to background this process, so that it can continuously keep checking. For example, you may use nohup:
nohup npm start &
Sensitive config is passed in via env:
TWILIO_ACCOUNT_SID=<your twilio sid>
TWILIO_AUTH_TOKEN=<your twilio auth token>
TWILIO_PHONE_NUMBER=<your twilio phone number>
DESTINATION_NUMBER=<phone number to notify>
Alternatively, put the above in a .env
file to pass environment variables in via dotenv.
In package.json, you can configure app's configuration:
"config": {
"checkIntervalSeconds": <INTERVAL IN SECONDS TO CHECK PAGES>
}
In app.js, the main app's logic is contained. You must add checks by calling checker.addCheck():
checker.addCheck("SYSTEM007",
"http://www.wearesystem.co.uk/product/systm007-las-backyard-tic",
function(page) {
// Return true iff "Coming Soon" is not present
return !(/(Coming Soon)/.test(page));
});
Arguments:
- name (string): A name for the check, which is quoted when users are notified
- url (string): The URL for which to perform the check on
- callback(page) (function): Callback which to perform your synchronous analysis of the page, returning true when the client should be alerted
No public API is available (yet), please do not depend on any of this for external projects. Fork or use as given.
MIT
Currently this project is fairly flexible for basic use cases. In future, all synchronous calls should probably be removed - it's not the NodeJS way!
Also, I'm not sure about the current configuration split between package.json and app.js. I may move more app logic out of app.js and move the configuration in from package.json.
## midcheck?!