A simple appointment reminder app using Bandwidth's Messaging API, Node.JS, and Express.
- Node v.8.12.0+
- Bandwidth Account
- Heroku Account
BANDWIDTH_USER_ID
- Saved to environment variableBANDWIDTH_API_TOKEN
- Saved to environment variableBANDWIDTH_API_SECRET
- Saved to environment variable- NPM packages:
- Some database set up from which you can pull each day's clients that need an appointment reminder
This app checks your database once a day for clients that need to be reminded of appointments and prompts them for a confirmation of their appointment.
Make sure you have at least one Bandwidth number registered to you app.bandwidth.com account and that it is set up to receive callbacks from messaging events. For more info on this, go here.
const express = require("express");
const bodyParser = require("body-parser");
const path = require("path");
const bandwidth = require("node-bandwidth");
const app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, "/public")));
const client = new bandwidth({
userId : "{{BANDWIDTH_USER_ID}}",
apiToken : "{{BANDWIDTH_API_TOKEN}}",
apiSecret : "{{BANDWIDTH_API_SECRET}}"
});
function sendReminderSMS(){
//first, pull info about the client
//(their phone number and the date and time of their appointment)
//from whatever database you are using
//and set variables
//If there are multiple clients, you will
//have to loop through this code
let apptDate = "{{DATE}}";
let apptTime = "{{TIME}}";
let clientNum = "{{CLIENT_NUMBER}}";
let BWNum = "{{YOUR_BANDWIDTH_NUM}}";
//create outgoing SMS
client.Message.send({
from: BWNum,
to: clientNum,
text: "This is a reminder that you have an appointment at {{OFFICE NAME}} on " + apptDate + " at " + apptTime + ". Text YES to confirm your appointment."
}).then(message => {
console.log(message);
});
}
//set SMS reminder function
//to run once a day
setInterval(sendReminderSMS, 86400000);
module.exports = app => {
//listen for callbacks
app.post("/callback", (req, res) => {
//check that callback is from incoming SMS event
if (req.body.eventType == "sms"){
//check content of message for 'yes' response
if (req.body.text.toLowerCase() == ("yes" || "y")){
//here put however you want to process a confirmation of appointment
res.end();
}
} else {
res.end();
}
});
}
require("./routes/routes.js")(app);
const port = process.env.PORT || 3000;
app.listen(port, function() {
console.log("App listening on PORT " + port);
});
You can now deploy your appointment reminder app to Heroku. Click the button below for more information.