Posting to Slack with Threads and AWS

Update (July 30, 2015): The post below shows an awesome example of the flexibility you get when combining Threads webhooks with other services. But if what you want to do is post to Slack from Threads, you no longer need to follow these steps. As of today, Threads has a “Send to Slack” action. Just select that when you’re building your workflow, enter the Slack “Incoming Webhook” URL, and you’re good to go!

When you launch a new product, one of the most exciting things to do is watch new users start to roll in. Threads went into public beta recently, and we’ve been wanting a good way to keep an eye on signups. Our team uses Slack all day long, so I thought that would be a good place to announce new signups. And what better way to do that than through a Threads workflow triggering off of our “Sign Up” event?

Threads workflows can’t post to Slack directly, but they can call webhooks. With a little help from the brand new Amazon API Gateway and AWS Lambda, it only took a few minutes to set up a Threads workflow to post into a Slack channel. Here’s how I did it.

Posting to a Slack channel is as easy as POSTing the right data to a specific URL. So all I really needed to do was translate the Threads webhook data into the format Slack wants. The first thing I did was write a simple NodeJS script to do that translation. Threads webhook data looks like this:

Notice that any traits you’ve stored for the user are available, along with the user ID, workflow name, and the Threads IDs for the project, action, and workflow. I simply wanted to include the user ID in my slack message, so there wasn’t much work to do.



Once the Lambda function was saved and tested, I used Amazon API Gateway to create an external-facing HTTPS API endpoint for it. Because it’s an incredibly simple API (only one resource and method), this only took a minute to get going.

Slack Gateway

Once that part is done, it was time to move into Threads. I just created a Threads workflow that triggers off of our Threads “Sign Up” event, and had it POST to my new API Gateway endpoint.

Slack Workflow

And that, truly, is all there was to it. I activated the workflow, and signup messages started flowing into our Slack channel. Awesome!

Of course, this is just the beginning of what you can do with Threads webhooks. You could use a setup like this to update values in one of your databases, send other types of notifications, or really anything you can imagine. Have fun!