Post inbound SMS to a Slack feed with Twilio Studio and an incoming Slack webhook. You’ll need an existing Slack team to follow along with this tutorial, so if you don’t have one yet, create one for free now.
We’ll start with a fresh Twilio Studio flow; log into your Twilio account and navigate to the Studio Dashboard, then tap the + icon to create a new flow. You can name your flow anything you like; we’re calling ours SMS to Slack.
You’ll notice that the canvas comes with a widget already in place -- that’s the Trigger widget, which kicks off our flow when the trigger we specify is fired. In this case, our trigger is going to be an Incoming Message.
This flow only requires one widget -- the HTTP Request widget. Drag one onto the canvas, and connect the dot from the Incoming Message trigger to the dot in the upper left corner of the new widget.
You’ll need a Request URL in order to successfully use the HTTP Request widget, and in this case, it’s going to be a Slack webhook URL. Let’s head over to Slack to set up an incoming webhook integration.
Slack has excellent documentation around setting up incoming webhooks, and we encourage you to learn about the available customizations. Today, we’re concerned with the part that is most relevant to the HTTP Request widget -- the webhook URL.
Navigate to the incoming webhooks configuration page and select the channel you’d like to send your inbound SMS to. Click the button to add a new WebHooks integration.
Once you create a new webhook integration, you’ll get a Webhook URL:
Copy this URL to your clipboard; you’ll need it for the HTTP Request widget. Paste the URL into the Request URL field in the sidebar for the HTTP Request widget.
We’re now halfway there! Once you’ve got the Request URL set up, the next step is to declare a payload (the incoming SMS message). You can do this by setting an HTTP Parameter in a format that Slack will recognize.
Set the first HTTP Parameter field to payload so Slack knows what to expect. To format inbound SMS messages for the payload, set the second field to the following, keeping the curly braces and quote marks in place:
Tap the Add button to save your parameters.
Your HTTP request is now configured! Time to connect the flow to a Twilio phone number. Navigate to the Phone Numbers section of the Twilio Console, and select the number you’d like to forward from. Scroll down to the Messaging section, and select Webhooks, TwiML Bins, Functions, Studio, or Proxy from the first dropdown. Select Studio Flow next to the “A Message Comes In” dropdown, and choose the flow that you just created to attach it to the number. Click Save.
Now you can test out your SMS to Slack hook! Send an SMS to your Twilio number, and watch your Slack channel for an inbound message.
Want to get creative? You can specify additional payload properties, such as icon_emoji, username, and more. Enjoy watching the stream of messages in your Slack channel!