Slack Integration

Use the slack integration to send Slack messages with a message step or to prompt for user input in an input step.

integration "slack" "my_slack_app" {
token = "xoxp-111111"
channel = "#infosec"
signing_secret = "Q#$$#@#$$#W"
}

Arguments

ArgumentTypeOptional?Description
tokenStringOptionalThe Slack user token for the app. The token must have the required scopes. You must specify either a token or webhook_url.
webhook_url StringOptionalA Slack webhook url to post to a slack channel. Note that a webhook is tied to a specific channel; if you specify a channel in the step options it will be ignored. You must specify either a token or webhook_url.
channelStringOptionalThe Slack channel to send to. This value should be considered a default; if an input step specifies a channel it will override this value. Note that a webhook is tied to a specific channel, so if you specify a webhook_url then this setting will have no effect.
signing_secretStringOptionalSlack signing secret used to verify that the responses are from Slack. This setting only applies if you use a token.
titleStringOptionalDisplay title for the integration.

Attributes (Read-Only)

AttributeTypeDescription
request_urlStringThe webhook URL to configure as the request url in your Slack app

Examples

Slack integration requires exactly one of:

  • A slack token
  • A webhook_url. Note that a webhook is tied to a specific channel; if you specify a channel in the step options it will be ignored.

Example: Slack with token

integration "slack" "my_slack_app" {
token = "xoxp-111111"
channel = "#infosec"
signing_secret = "Q#$$#@#$$#W"
}

Example: Slack with webhook URL

integration "slack" "my_slack_app" {
webhook_url = "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"
}

Setting up as Slack Integration

To prompt for input via Slack you need to:

  1. Create an app in Slack.
  2. Create a Slack integration.
  3. Enable Interactivity in the Slack App.
  4. Add the integration to a notifier.
  5. Use an input step or a message step to send to the notifier.

Create the Slack App

First, we'll need to create an app in Slack for Flowpipe.

  1. Go to the Slack Apps page and click the Create New App button.
  2. In the Create an app dialog, choose From scratch.
  3. The Name app & choose workspace dialog appears. Enter a name for your app and select the workspace in which to create it. Click Create App.
  4. Your app is created and you are sent to the Basic Information page for the app. From the left-hand hand menu, select OAuth & Permissions. In the Scopes section, under Bot Token Scopes, click Add an OAuth Scope and add the chat:write scope.
  5. Scroll back to the top of the page and in the OAuth Tokens for Your Workspace section, click the Install to Workspace button. You will be prompted to allow access. Click Allow.
  6. On the OAuth & Permissions page, in the OAuth Tokens for Your Workspace, copy the Bot User OAuth Token. This will be the token that you use to configure the integration in Flowpipe.
  7. Go back to the Basic Information page. In the App Credentials section, copy the Signing Secret. This will be the signing_secret that you use to configure the integration in Flowpipe.

Create the Flowpipe Integration

Now that the app is created, we will create a new Slack integration in Flowpipe. If you don't already have one, create a flowpipe.fpc in your config directory (usually ~/.flowpipe/config/). Create a Slack Integration. Set the token and signing_secret to the values for your slack app, and set the channel to whichever Slack channel you would like to use as the default channel.

integration "slack" "default" {
token = "xoxb-111111"
channel = "#vandelay-industries"
signing_secret = "000000000000"
}

Because Slack will need to call back to Flowpipe, we will need a public endpoint. For this example, we will use ngrok. Download and install ngrok, and then start it, listening to HTTP on the Flowpipe port:

ngrok http 7103

When ngrok starts, it will create a random public URL to forward to your local system. Copy this URL (from the Forwarding line), we will use it to set the Flowpipe base URL. In this case, we are using an ephemeral address from ngrok, so we will just pass the base URL to the flowpipe server command.

You can also set the base URL via the FLOWPIPE_BASE_URL environment variable or the base_url workspace argument, and this may be simpler if you have a stable reverse proxy or public URL.

In another terminal, restart Flowpipe server, passing in the ngrok URL as the base URL:

flowpipe server --base-url https://0000-1111-2222-ee0-16b0-91dd-fdc0-3333-4444.ngrok-free.app

In order to finish setting up the Slack app, we will need to get the Request URL for our Slack integration. In another terminal, run flowpipe integration show to and copy the Request URL:

$ flowpipe integration show slack.default --host local
Name: slack.default
Type: slack
Request URL: https://0000-1111-2222-ee0-16b0-91dd-fdc0-3333-4444.ngrok-free.app/api/latest/integration/slack/default/0s9bkjhq8mn0x

Enable Interactivity in the Slack App

Now we need to enable your Slack app for interactivity and complete the Slack setup.

  1. In a browser, go to the Slack app configuration page for the app that you created earlier.
  2. In the settings for the app, go to Interactivity & Shortcuts. Enable Interactivity, and set the Request URL to the integration's Request URL. Click Save Changes.
  3. Re-install the app in the workspace. From the menu on the left, select Install App, then click Reinstall to Workspace.

The Slack app is now configured. Note that you must also invite the bot user to any channel that you want to post messages to! You can go to the channel in Slack and invite the integration by name: /invite @Flowpipe Integration.

Setup the Notifier

Now that the app is set up and installed in your Slack workspace and the integration is set up in Flowpipe, you can add the integration to your default notifier (or create a new one) by adding this to your ~/.flowpipe/config/flowpipe.fpc file:

notifier "default" {
notify {
integration = integration.http.default
}
notify {
integration = integration.slack.default
}
}