How-To: Integrate Slack

This is a how-to for creating and integrating a Slack App with Pliant.io

We will be creating an entirely new Slack App, integrating Pliant.io with it, and testing it in a development Slack workspace.

We will not be covering distributing the application to other users/workspaces.

Instructions

(1/4) we need to create our Slack App:

  1. Login to Slack
  2. Navigate to https://api.slack.com/apps
  3. Click on "Create an App"
  4. Fill in the name for the app and select the workspace to be used as a development workspace from the drop-down, then click Create App.
  5. Scroll down to the "App Credentials" section and write down the "Verification Token", we will need it later:
  6. Go to "Bot Users"
  7. Click on "Add a Bot User"
  8. Acknowledge the creation by clicking on the green "Add Bot User" button.
  9. Navigate to "Install App"
  10. Click on "Install App to Workspace", then Authorize the addition of the bot:
  11. Take note of the "Bot User OAuth Access Token"

(2/4) We can now post messages to the development workspace from Pliant.io:

  1. We log into the Pliant.io system as a fresh user:
  2. Navigate to Workflows.
  3. Click on "New Flow" and put in a name for the flow containing the word "Event", e.g. "SlackEvent":
     



  4. From the system flows panel navigate to Slack → chat, and drag and drop the "chat_postMessage" flow:
  5. Click on the "more" link below the "authKey" to expand the parameters list:

  6. Fill in the following fields as follows:
    "username" - the  username given to the Bot
    "text" - a message to send to a Slack channel
    "as_user" - false
    "token" - the "Bot User OAuth Access Token"
    "channel" - a name of a public channel or a channel the bot has access to post messages to
  7. We now have a way of sending messages to Slack. Let's tidy up the flow a bit:
  8. In order for the integration in the opposite direction (from Slack) to be successful, we need to implement a way for the Slack test message (challenge) to pass-through.
    We do this by declaring a "challenge" variable that is both input and output, thereby passing the challenge through unmodified:
  9. Click on Save to save the flow.

(3/4) Integrating the Slack App to send notifications to our newly created Flow Event.

  1. From the following page, click on "Event Subscriptions" from the list of features and functionalities:
  2. Enable the Event Subscriptions feature:
  3. Click on "Add Workspace Event" from the Subscribe to Workspace Events view, then select "message.channels":

  4. Enter the flow's event trigger URL in the "Request URL" field:

    The event trigger url is composed of the following parts
    1. https://livedemo.pliant.io - the domain name of the pliant.io installation
    2. /api/v1/trigger/event/ - the event trigger endpoint
    3. slacker - the name of the user we created the flow under
    4. /User/SlackEvent - the full path and name of the flow we created
    5. ?sync=true - we want a blocking request, waiting for flow execution's completion before returning a response
  5. Click "Save Changes"
  6. We are prompted for re-installing our App, click on the "click here" from the yellow bar to go to and re-authorize the permissions for our App to be able to receive messages (can also be found under the "Install App" from the left-hand side navigation menu)
  7. Authorize the required permission

(4/4) Now that our Pliant.io can receive messages from Slack, we want to make it respond to some.

  1. Back in our Pliant.io flow, add two variables:
     
    1. "slack_token" with a default value equal to the "Verification Token" we took a note of in the beginning.
    2. "should_respond" with a default value of false

  2. Add another two Input variables:
      
    1. "token" with a default value of ""
    2. "event" with a default value of {}
  3. Navigate to Home → Common and drag and drop an "Assign" block to be the first in our flow

  4. Fill in the parameters:

    1. select "variable" then "should_respond" as the target variable parameter
    2. Fill in the value: ($token === $slack_token) && $event && $event.text && ($event.username !== $bot_username)
  5. Drag and drop an "IF" statement block
  6. Move (drag and drop) the chat_postMessage block inside the IF section
  7. Select variable → "should_respond" in the Condition parameter of the IF block
  8. Change the "text" parameter of the chat_postMessage from "const" to "expression" with the following value: "OK, I will " + $event.text
  9. Change the "channel" parameter of the chat_postMessage from "const" to "expression" with the following value: $event.channel
  10. Save the flow.

We now have a working bi-directional integration with a Slack workspace. The current integration bot will always respond to anyone other than itself by replying "OK I will " and whatever was said in the channel.