Post Tweets to Slack

POST {{slack_webhook_url}}

About

Overview

This request sends a single tweet to a Slack channel via a POST request/Slack webhook integration. There are 3 things that are essential for this request. Below we'll break down each component.

Pre-request Script

The code in the Pre-request Script tab runs before your request is sent. In this case, to know what tweets to send to Slack, we capture the data from the environment variable tweets_to_post and save it as a variable we can work with called tweetsToPost. This is the array containing all of the tweets for a specific hashtag. If there are elements in the array, we simultaneously remove the first element of the tweetsToPost array and set it as an environment variable called current_tweet, which is the stringified version of a single tweet to be sent in the body of the request.

Body

Here is the content that is sent over to Slack. Using the nifty Block Kit Builder tool provided by Slack, it's easy to format your message exactly how you'd like to see it in Slack. You can see that current_tweet is in the double curly braces to reference the variable named current_tweet that we defined in the Pre-request Script.

Tests

Here we again capture that newly updated tweetsToPost variable and make use of Qodex's ability to [customize your workflow] Because we want this request to run for every single tweet found, we use the setNextRequest method to determine which request should run next. If there are still tweets to post to Slack, we actually want to set the next request to the same request we just ran (Post Tweets to Slack)! When all the tweets have been posted to Slack, we set the next request to Get Qodex Environment UID, which allows to store the highest tweet id.

Request Body

{"blocks"=>[{"type"=>"section", "text"=>{"type"=>"mrkdwn", "text"=>"{{current_tweet}}"}}]}

RESPONSES

status: OK

"ok"