Created
April 18, 2018 13:53
-
-
Save supratims/56b1c379fad1e8fccf9f97b468041399 to your computer and use it in GitHub Desktop.
Twilio function to forward sms
This file contains 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
// This is a simple usag of twilio function | |
// Buy a number in twilio | |
// Setup a twilio function (akin to amazon mabda) that handles incoming messages and forwards the message to your number | |
// If you are using test twilio account, make sure your number is verified | |
// Flow: | |
// Assuming your twilio number is A | |
// Sender S, sends a sms to A | |
// This function forwards the sms to your number Y | |
// Make sure Y is verified in twilio | |
exports.handler = function(context, event, callback) { | |
console.log('Incoming message found ... '); | |
console.log(event.Body); | |
// Fetch already initialized Twilio REST client | |
const twilioClient = context.getTwilioClient(); | |
// event.From : has sender number (S above) | |
twilioClient.messages.create({ | |
from: event.To, // Twilio number (A above) | |
to: '+1 xxx', // Final destination - your number (Y above) | |
body: event.Body ? event.Body : '<blank>' | |
}, function(err, result) { | |
console.log('Done'); | |
callback(); | |
}); | |
}; | |
// Note: Under twilio -> Runtime-> functions-> logs, you can see console.log output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment