Workflow Application: Using SENDHTTPPOST to send messages to Slack

About SENDHTTPPOST

The SENDHTTPPOST workflow application (available as of WorkflowGen version 6.6.0) lets you create webhook HTTP requests to external systems. For example, this is an easy way to send messages to Slack channels. The JSON and URLENCODED request exhange formats are supported, and you can create more action parameters to send additional data.

Note: It is recommended to use the RESTAPICLIENT workflow application instead of SENDHTTPPOST, since RESTAPICLIENT provides more extensive features.

For general information on integrating webhooks with WorkflowGen, see the Using webhooks with WorkflowGen topic and the SENDHTTPPOST workflow application section in the WorkflowGen Administration Guide.

For samples of APIs that use SENDHTTPPOST, see the SENDHTTPPOST Workflow Application repository on GitHub.

Configuring SENDHTTPPOST to send webhooks to Slack

In this article, we’ll set up SENDHTTPPOST to send webhooks to Slack channels, and create a form that will let users enter messages in a text box to send to a channel selected from a drop-down list.

First, you’ll need to get an incoming webhook URL with your Slack token; see https://api.slack.com/incoming-webhooks for information on how to do this.

Note: A Slack incoming webhook URL will contain your Slack token. If you’re configuring SENDHTTPPOST for an external API that doesn’t support tokens concatenated in the URL, you can include the optional TOKEN parameter (see the Optional parameters table below), which SENDHTTPPOST will then include in the JSON payload.

  1. Create a new process or open an existing process.

  2. On the Data tab, create a text type data called URL with the Slack webhook URL set as its default value.

  3. Create a text type data called RESPONSE_STATUS and another called RESPONSE_MESSAGE, and leave them empty for HTTP request status codes and error messages from Slack.

  4. In the Form Designer, add a text box labeled Username for the user’s Slack username, a text area labeled Message for the contents of the message, and a drop-down list labeled Slack channel to let the user choose from a set of Slack channels.

  5. Configure the drop-down list of Slack channels. To do this:

    i. Click the pencil icon next to the drop-down list to open the Settings panel.

    ii. Add items for each of the channels, then set their values as the channel names using the proper Slack format (e.g. #marketing-channel; #purchasing-channel).

    iii. Set the items’ corresponding texts as how you want the channels to appear in the drop-down list (e.g. Marketing Team; Purchasing Team).

  6. On the Mapping tab, create the OUT values for the username and message text boxes and the channel drop-down list, which we’ll call USERNAME, TEXT, and CHANNEL.

  7. In the Workflow Designer, add a SENDHTTPPOST action to your process and link it to the other actions in the process design.

  8. On the Parameters tab in the Edit action panel, set the URL data you configured in the first step as the value of the required APP_URL parameter.

  9. Add IN parameters called username, text, and channel (these are the data that will received by Slack and must be in lowercase), and set their values as the corresponding USERNAME, TEXT, and CHANNEL data you mapped to the text boxes and drop-down list in the form.

  10. Add the optional APP_RESPONSE_STATUS and APP_RESPONSE_CONTENT OUT parameters (available by clicking Browse in the Add parameter panel), and set them to retrieve their values into the RESPONSE_STATUS and RESPONSE_MESSAGE data you created.

JSON payload

The payload created by SENDHTTPPOST for a message sent to Slack would look something like this:

{
  "channel": "#marketing-channel",
  "text": "This is a test",
  "username": "eric_knox"
}

SENDHTTPPOST parameters

The following tables list the required and optional parameters that can be used in SENDHTTPPOST actions.

Required parameter

Parameter                                    Type       Direction Description
APP_URL Text IN External API URL

Optional parameters

Parameter                                    Type       Direction Description
TOKEN Text IN API authorization token (use this parameter to specify a token for external APIs that don't include the token in the URL)
APP_TIMEOUT Numeric IN Maximum time interval between the request sending and the response reception (default: 3000 milliseconds; maximum 60000 milliseconds)
APP_CONTENT_TYPE Text IN Request content type supported by the external API (SENDHTTPPOST supports JSON and URLENCODED; the default is JSON)
APP_RESPONSE_CONTENT Text OUT Returned optional payload or error message
APP_RESPONSE_STATUS Text OUT Returned HTTP request status code

You can also add additional custom parameters specific to the external API. For example, you can add a parameter to include an emoji in a Slack message, and map this to Slack's "icon_emoji" parameter.

Parameter                                    Type       Direction Description
icon_emoji Text IN Slack emoji (e.g. the parameter value ":smile:" without quotation marks will include a smile emoji in the message)