Rate this page:

Post Messages to Slack with Twilio Studio

In this tutorial you will post an inbound SMS to a Slack feed using 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.


Before you get started, you'll need:

Create Your Flow

You'll start with a new Twilio Studio Flow. A Flow is an individual workflow you create to handle your use case. For example, in this case you're going to post an inbound SMS to a Slack Feed. All the logic for this will exist in the Twilio Studio Flow you create.

To create a new Studio Flow:

  1. Log into your Twilio account and navigate to the Studio Dashboard.
  2. Click the Create a Flow button to create your first Studio flow. If you already have some Studio Flows (awesome!), tap the "+" icon instead.
  3. Name your Flow. You can name your Flow anything you like; we're calling ours "SMS to Slack".
  4. Click next to select a template. You'll see a few different templates you can use but you'll want a blank Canvas for this tutorial, so select Start from scratch on the template selection screen.
    SMS to Slack Flow

You’ll notice that the Canvas comes with a widget already in place – that’s the Trigger Widget. It will kick off your Flow when the trigger you specify is fired. In this case, your trigger is going to be an Incoming Message.

Incoming Message Trigger

The HTTP Request Widget

This Studio Flow only requires one Widget -- the HTTP Request Widget. Drag an HTTP Request Widget onto the Canvas from the Tools & Execute Code section of the Widget Library, and connect the red dot from the Incoming Message Trigger to the gray dot in the upper left corner of the HTTP Request Widget. Give your Widget a name (we named ours post_to_slack).

HTTP widget - Post to Slack

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.

Configure Slack Webhook URL

Slack has excellent documentation around setting up incoming webhooks, and we encourage you to learn about the available customizations. Today, you'll focus on the part that is most relevant to the HTTP Request widget -- the webhook URL.

First, head over to Slack to set up an incoming webhook integration.

Navigate to the incoming webhooks configuration page and select the Slack channel you'd like to send your inbound SMS to. Click the Add Incoming WebHooks integration button to create a new incoming webhook.

Slack incoming webhook integration

Once you create a new webhook integration, you'll get a Webhook URL like the one shown in the screenshot below:

Slack 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 Widget configuration menu for the HTTP Request Widget.

HTTP widget with Slack webhook URL

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 Body in a format that Slack will recognize.

Declare the Payload

In the HTTP Request Widget configuration menu, set the Widget's Content Type to Application/JSON so that Slack knows what to expect. To format inbound SMS messages for the payload, set the Request Body field to the following, keeping the curly braces and quote marks in place:

{"text": "{{trigger.message.Body}}"}

Tap the Add button to save your parameters.

Post to Slack Webhook

Your HTTP request is now configured! Now you're ready to connect the Studio Flow to a Twilio phone number.

Connect your Flow to a Twilio Phone Number

  1. First, navigate to the Phone Numbers section of the Twilio Console, and select the phone number you'd like to forward from.
  2. Scroll down to the Messaging section, and select Webhooks, TwiML Bins, Function, Studio Flow, or Proxy Service from the "Configure With Other Handlers" dropdown.
  3. Select Studio Flow next to the "A Message Comes In" dropdown, and choose the Studio Flow that you just created to attach it to the number.
  4. Don't forget to click Save!

Configure Phone Number with Studio

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.

SMS message in Slack feed

What's Next?

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!

Learn more about Twilio Studio:

Mica Swyers Andrej Saweljew Shawn Stern Stephanie Marchante
Rate this page:

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd by visiting Twilio's Stack Overflow Collective or browsing the Twilio tag on Stack Overflow.


        Thank you for your feedback!

        Please select the reason(s) for your feedback. The additional information you provide helps us improve our documentation:

        Sending your feedback...
        🎉 Thank you for your feedback!
        Something went wrong. Please try again.

        Thanks for your feedback!

        Refer us and get $10 in 3 simple steps!

        Step 1

        Get link

        Get a free personal referral link here

        Step 2

        Give $10

        Your user signs up and upgrade using link

        Step 3

        Get $10

        1,250 free SMSes
        OR 1,000 free voice mins
        OR 12,000 chats
        OR more