Skip to content

Instantly share code, notes, and snippets.

@dtolb
Created December 1, 2016 19:22
Show Gist options
  • Select an option

  • Save dtolb/a0aabc9d5f45e21b18bdf83c701c3b45 to your computer and use it in GitHub Desktop.

Select an option

Save dtolb/a0aabc9d5f45e21b18bdf83c701c3b45 to your computer and use it in GitHub Desktop.

Appointment Reminders. Powered by Bandwidth - Node.js/Express

This is an example of the small amount of work required to migrate an existing Twilio application to Bandwidth.

The original Appointment Reminders can be found over at Twilio's website.

Migrating to Bandwidth

Migration to Bandwidth for Appointment Reminders is VERY Easy

Remove Twilio Client

First thing is to update the Communications API to Bandwidth instead of Twilio

//var twilio = require('twilio');
var bandwidth = require('node-bandwidth');

Update Client Initialization

//var client = new twilio.RestClient(cfg.twilioAccountSid, cfg.twilioAuthToken);
var client = new bandwidth({
    userId: cfg.bandwidthUserId,
    apiToken: cfg.bandwidthAPIToken,
    apiSecret: cfg.bandwidthAPISecret
});

Update Message Send Function

Bandwidth's methods each inherit from the base client class. So client.sendMessage becomes client.Message.send.

Bandwidth also uses text instead of body for the options.

var options = {
  to: "+" + appointment.phoneNumber,
  //from: cfg.twilioPhoneNumber,
  from: cfg.bandwidthPhoneNumber,
  //body: "Hi " + appointment.name + ". Just a reminder that you have an appointment coming up  " + moment(appointment.time).calendar() +"."
  text: "Hi " + appointment.name + ". Just a reminder that you have an appointment coming up  " + moment(appointment.time).calendar() +"."
};

// Send the message!
//client.sendMessage(options, function(err, response) {...});
client.Message.send(options, function(err, response) {...});

Update user-id, token, secret, and phone number.

Be sure to update all your environment variables to include Bandwidth!

Read More:

Take a look at the pull request on github.com for a breakdown on all the changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment