Walkthrough: Using the Request trigger to create Slack custom commands

On Microsoft Flow we recently released the Request feature, that allows you to trigger a flow run by calling a specific HTTP endpoint. As part of this walkthrough, we are going to look at how to use this new trigger to create a Slack custom command that posts the latest XKCD comic strip in your slack channel. The walkthrough has two aspects: 1. Setting up the flow and 2. Configuring a Slack custom command

Part 1: Setting up the flow

  • To start off, head on to My Flows page, and click on the “Create from blank” button in the top right corner.

  • Search and select the Request trigger. It should look like as shown below

  • Now we need to get the XKCD comic strip, for this we are going to use the HTTP action. You can add the HTTP action by clicking “+New Step”, then click on “Add an action” and search for HTTP in the search box.

  • Set the method to “GET” and URI to http://xkcd.com/info.0.json

  • Finally, we need to setup the response action – this action always need to be used in conjunction with the Request action, as it is used to define the response to the incoming request.

  • You can add the Response action by clicking “+New Step”, then click on “Add an action” and search for Response in the search box.

  • Paste in the response body provided, use the “status code” token from the HTTP action and create the flow.

Response body:

{

  "text": "@actions('HTTP').outputs.body.safe_title",

  "attachments": [

    {

      "image_url": "@actions('HTTP').outputs.body.img",

      "text": "@actions('HTTP').outputs.body.alt",

      "footer": "Microsoft Flow",

      "footer_icon": "https://procsi.blob.core.windows.net/blog-images/icon_Flow_167x167.png"

    }

  ],

  "response_type": "in_channel"

}

 

Important: Copy the URL in the Request trigger. You may have to close and re-open the flow to get this URL.

Part 2: Configure a Slack custom command

  • Head over to the home page on your Slack team – https://<teamName>.slack.com/home.

  • Under Applications, navigate to Slash commands and click on Add Configuration

  • Provide a name for your Slash Command, I used /xkcd for mine.

  • In the URL field paste in the URL that you coped from the Request trigger from Flow.

  • Make sure the Method is set to POST.

  • Once you have saved the integration, go over to the Slack and type in /xkcd, you should see the latest comic strip show up in seconds.

We hope this tutorial was helpful and are excited to see how you will use this feature to build new and interesting flows. For questions or feedback reach out to us on Twitter or on the forums.