Skip to content

Instantly share code, notes, and snippets.

@aroach
Created February 21, 2019 20:51
Show Gist options
  • Save aroach/a6af30ea8fbe83825cc222cedf076dce to your computer and use it in GitHub Desktop.
Save aroach/a6af30ea8fbe83825cc222cedf076dce to your computer and use it in GitHub Desktop.
twilio-sg-example
require('dotenv').config()
var Twilio = require('twilio');
var sgMail = require('@sendgrid/mail');
var accountSid = process.env.TWILIO_SID;
var authToken = process.env.TWILIO_AUTH_TOKEN;
var client = new Twilio(accountSid, authToken);
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
// Notify user via Twilio SMS
client.messages.create({
from: process.env.HEDWIG_TWILIO_NUMBER,
body: 'Sending Owl Post',
to: 'harry@potter.com'
}).then(message => {
console.log(message)
// Send email here via SendGrid
console.log('********** Sending Email');
sgMail.send({
to: 'harry@potter.com',
from: process.env.HEDWIG_ADDRESS,
templateId: process.env.SG_TEMPLATE_ID,
dynamic_template_data: {
owl_post_subject: 'You\'ve got an Owl Post!',
owl_post_content: 'Alohamora!',
send_time: new Date(Date.now()).toLocaleString()
}
});
})
.done();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment