I would like to merge a function with a studio flow (get them to work together).
I used a guide to create a function:
exports.handler = function(context, event, callback) { const MY_NUMBER = '+440000000000'; let twiml = new Twilio.twiml.MessagingResponse(); if (event.From === MY_NUMBER) { const separatorPosition = event.Body.indexOf(':'); if (separatorPosition < 1) { twiml.message('You need to specify a recipient number and a ":" before the message.'); } else { const recipientNumber = event.Body.substr(0, separatorPosition).trim(); const messageBody = event.Body.substr(separatorPosition + 1).trim(); twiml.message({ to: recipientNumber }, messageBody); } } else { twiml.message({ to: MY_NUMBER }, `${event.From}: ${event.Body}`); } callback(null, twiml); };
When I send a message to my twilio number from my number (+4400000000000) with the format of [E.164 formatted number: message] the message is forwarded to the [E.164 formatted number].
If it is not from my number, the mssage is forwarded to my number.
This is working fine when I select this function as my SMS handler.
I also used a guide to create a flow which on receiving an SMS, makes a http request to a webhook attached to Slack. the payload delivered is:
{ "text":"MESSAGE: {{trigger.message.Body}} MESSAGE FROM: {{trigger.message.From}}"}.
This is sent to my slack channel.
This workes fine when I select this flow as my handler.
I would like the best of both worlds. When I receive a message with [E.164 number:] from my number, I woul like the function to process it. When the message is NOT from my number, the flow to process it and send to my Slack.
The solution I see is to have the function call the http webhook and delivery the payload as shown above.
I just have no idea how to do this, and as far as i can tell, no guide exists.
Categories
- 83 All Categories
- 19 SIGNAL 2021
- 376 Product Discussions
- 7 Community - Announcements
- 2 Changelog
- 4 Forum UI Updates
- 8 Welcome Guide
- 6 Community - Events
- 2 Twilio Relay Developer Conference 2021 Mega Thread
- 1 External Community Events
- 25 Inspiration
- 17 Community - Other Discussions
- 1 Community- Twilio Startups