2
votes

I want to forward any sms messages incoming to my Twilio (virtual) number to an email address using Twilio functions. How would I go about that?

2
do you want forward incoming message coming to your phone number? - user8377060
I want to forward the messages coming to the Twilio number - user2133623

2 Answers

2
votes

Twilio developer evangelist here.

You absolutely can forward incoming SMS messages to email using Twilio Functions. I actually wrote a blog post on how to forward SMS as email. This particular post uses the SendGrid API to send the message, the full code is available, with instructions, on GitHub.

If you wanted to use a different service to send the email you can. There is a pull request right now that I need to review where someone added SparkPost support. As long as you have a service that you can call as an HTTP API, then you can use the code and just adjust the payload.

Let me know if that helps at all.

0
votes

So, I've been making some research on this, and found these info:

Whenever a message is sent to a twilio number, also an http request is sent to the twilio server, and this server saves the message that was sent to the number.

To access that message that server is holding

We are using this code down below.

const MessagingResponse = require('twilio').twiml.MessagingResponse;

const response = new MessagingResponse();
const message = response.message();
message.body('Hello World!');
response.redirect('https://demo.twilio.com/sms/welcome');//you need to have your own document

console.log(response.toString());

The message is being redirected to the link that we have specified there, and it must be a twilio link, you can create a link from here

And all you have to do is read the message and enjoy it! For more info, please see https://www.twilio.com/docs/api/twiml/sms/your_response