BFDN
BFDN

Reputation: 1

Can I generate a Twilio SMS when a new email is received (email -> SMS)?

I am trying to generate an SMS from Twilio when I receive a new email in my Gmail.

I need to find a way to forward the email to another email address and have that generate the call to Twilio to send the SMS.

Upvotes: 0

Views: 197

Answers (1)

Riley Worthen
Riley Worthen

Reputation: 96

Here is a thought!

You could setup an webhook that will post your email data using one of these services:

Services That Cost:

Either

https://automate.io/integration/gmail/webhooks

The Widget you would want to use.

OR

https://zapier.com/apps/gmail/integrations/webhook

Free Service:

This is a bit of a hack, but it is free as far as I can tell:

  1. Forward all Emails To A Slack Channel: https://slack.com/help/articles/206819278-send-emails-to-slack
  2. Create a slack app that listens for new messages, and when it recieves a message, send a post request to a Twilio Function... Instructions below.... Link to slack app building: https://api.slack.com/start/building

THEN: you would post the data to a twilio function that takes the data and sends and SMS with it. the basic started application to send a message in a twilio function looks like this:

exports.handler = function(context, event, callback) {
    let twiml = new Twilio.twiml.MessagingResponse();
    twiml.message("Hello World");
    callback(null, twiml);
};

the event parameter will contain any data that you post to it. as this twilio doc shows:

Here is the twilio documentation for 'function' data posting

if your event looks like this: {"message-content": "Hey Jim I just wanted to send you this fantastic email over the holidays"}, all you would then need to do is as follows:

exports.handler = function(context, event, callback) {
  context.getTwilioClient().messages.create({
    to: '<ENTER YOUR PHONE NUMBER HERE>',
    from: '<ENTER ONE OF YOUR TWILIO PHONE NUMBERS WITH SMS CAPABILITIES>',
    body: event.message-content
  }).then(msg => {
    callback(null, msg.sid);
  }).catch(err => callback(err));
};

If you have any questions or get stuck along the way, use this twilio doc to help you: https://www.twilio.com/docs/runtime/quickstart/programmable-sms-functions

Cheers!!

Upvotes: 1

Related Questions