Created
December 1, 2016 19:22
-
-
Save dtolb/c5f36bcb3ec741dbfc9defe9458a9b4f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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](https://github.com/BandwidthExamples/appointment-reminders-node/pull/1) 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