Image is a title of "Sending Slack Interactive Messages with Okta Workflows" with an example of an approval interactive message.

Sending Slack Interactive Messages with Okta Workflows

Attempting to learn how to use interactive messages in a Slack bot to add to an approval process, I found the tutorial from Okta lacking. So I went and figured it out and now I am writing a more complete and easier-to-follow tutorial on the process.

Overview

Steps

  1. Create an Application that will act as your Bot in Slack
  2. Create your Blocks in the Slack Block Kit Builder in the way that you want them to appear in a Slack message
  3. Set up a Workflow in Okta Workflows to process the action taken in Slack.
  4. Set up a Workflow in Okta Workflows to send the Interactive Message using your Application created above

Creating a Slack Bot

Preferably using a service account, go to https://api.slack.com/apps/, Create a new App, and click from scratch. Give your App a name and select the workspace you want to connect it to. Keep in mind this App Name will be what users see when they get the message for approval. Click, create app.

Navigate to OAuth and Permissions on the sidebar. For Scopes add the following scopes: “chat:write” and “chat:write:public”. On this page you will also find your Bot User OAuth Token, which you will need to setup your API Connector for Okta Workflows. Save that value for later.

Navigate to Install App on the sidebar. Click on Install to Workspace to add the App to your Workspace. Confirm by clicking on Allow.

Keep this window open for later.

Creating your Blocks Message for Slack

In the UI you can delete all the sample blocks and build it out on your own using the available blocks on the left side panel. What I would suggest is using the Templates button found in the center top of the builder to select a template to start with and customize to your needs.

When you have completed your template in the builder, copy your JSON for the blocks. Make sure to copy all the code that is the value of the blocks parameter. It should be an array of objects and should start with the “[” after “blocks:” and end with “]” before the final “}”.

Leave this open or store the JSON for later.


Configuring Response Workflow

In Okta Workflows you will be creating two workflows; one to handle sending the message and one to process the button press.

Configuring the API Connector

Log in to Okta Workflows and proceed to the Connections page. Create a new connection and select API Connector. Give the Connector a name and description and use Custom Auth type. For your “Header Name” use “Authorization” and for Header Value use “Bearer ” followed by your Bot Token. Your bot token is found on the OAuth & Permissions page of your Slack App.

Image showing the example setup of the API Connector.
Example of how to setup the API Connector
Image shows where to get the Auth Token for the Bot user.
Image shows where to get the API Token for the API Connector

Configuring the Response Workflow

Start with the workflow that will receive the response from the interactive message. Create a new workflow. for the trigger card, select “API Endpoint” and security level select “Secure with client token” and close the dialog box. At this point save your workflow, this will generate the values you need in the endpoint settings. Go to the Endpoint Settings and copy the “Invoke URL”.

Return to the Slack App window. Navigate to “Interactivity & Shortcuts” on the sidebar. Turn Interactivity On and it will ask for the Request URL. This is where the bot will send a response when a person clicks on a button for approval. Paste the “Invoke URL” found in the Endpoint settings for the Response Workflow. Click on Save Changes.

Object – Get
Use this card to retrieve the payload from the body of the API response.

Object – Get Multiple
Use this card to get the values for “actions.0.action_id”, “response_url”, and “message.blocks”.

If/Else
Use this to check the “action_id” for the action taken, then create the strings used for the updated response.

Object – Construct
Create two parameters: “replace_original” with a value of “true” and “text” with a value of what you want to replace the original message with.

API Connector – Post
Make sure you select the API Connector you created earlier. Use the “response_url” and the object you just created as your Body for this card. This will be the API call to replace the original request message. This is important to remove the buttons to prevent multiple API calls.

If/Else
Use this to check the “action_id” for the action taken, then act on that. Put the main actions at the end of the workflow so that the workflow prioritizes getting the original message update to block multiple API calls.

Creating the Interactive Message Workflow

As a reminder, you will not be using a standard Slack App connector when you make the API call at the end of the workflow. Remember to use an “API Connector – Post” card and that you are using the API Connector you set up earlier.

Create a new workflow and use the “Helper Flow” card for the trigger. I used the following variables for the Helper Flow card: userEmail, applicationName, and approverEmail. This is based on how I will be using this flow so you can tweak this to your needs.

Text – Compose
Here you will paste the Slack Block Builder Kit JSON that you created earlier.

JSON – Parse
Input the string for your Slack Block Builder JSON here and it will output a JSON object.

Object – Construct
Create two parameters: “channel” and “blocks” with the value being the JSON object you just created. If you want to send the message as a DM to a user, the value should be the User ID of the Slack User. If you want to message to a Channel, then input the Channel ID instead.

API Connector – Post
Make sure your connection is to the API Connector created earlier. For the URL, use “https://slack.com/api/chat.postMessage” and for the body, use the Object you just created.


Future Improvements

For the future, I am planning to update the original request message by removing x amount of objects from the end of the original Slack blocks message and adding the thank you for responding with a message indicating the selection.


Resources

Leave a Reply

Your email address will not be published. Required fields are marked *