Created
January 31, 2019 11:40
-
-
Save grantstephens/b39f2fce14269e6f152af15d9fa25ecd to your computer and use it in GitHub Desktop.
Twilio Function Script to forward text messages sent to a twilio number to email via the mandril api
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
const mandrill = require('mandrill-api') | |
mandrill_client = new mandrill.Mandrill('#key-here'); | |
exports.handler = function(context, event, callback) { | |
const message = { | |
"text": event.Body, | |
"subject": `New SMS message from: ${event.From}`, | |
"from_email": "#from-address here", | |
"from_name": "#from-here", | |
"to": [{ | |
"email": "#email-here", | |
"name": "To Here", | |
"type": "to" | |
}], | |
}; | |
var async = false; | |
var ip_pool = "Main Pool"; | |
mandrill_client.messages.send({"message": message, "async": async, "ip_pool": ip_pool}, function(result) { | |
console.log(result); | |
}, function(e) { | |
console.log('A mandrill error occurred: ' + e.name + ' - ' + e.message); | |
}); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment