slack.endpoint() function

The slack.endpoint() function sends a message to Slack that includes output data.

*Function type: Output*

  1. import "slack"
  2. slack.endpoint(
  3. url: "https://slack.com/api/chat.postMessage",
  4. token: "mySuPerSecRetTokEn"
  5. )

Parameters

url

The Slack API URL. Defaults to https://slack.com/api/chat.postMessage.

If using a Slack webhook, you’ll receive a Slack webhook URL when you create an incoming webhook.

*Data type: String*

token

The Slack API token used to interact with Slack. Defaults to "".

A token is only required if using the Slack chat.postMessage API.

*Data type: String*

Usage

slack.endpoint is a factory function that outputs another function. The output function requires a mapFn parameter.

mapFn

A function that builds the record used to generate the POST request. Requires an r parameter.

You should rarely need to override the default mapFn parameter. To see the default mapFn value or for insight into possible overrides, view the slack.endpoint() source code.

*Data type: Function*

The returned record must include the following fields:

  • channel
  • text
  • color

For more information, see slack.message()

Examples

Send critical statuses to a Slack endpoint
  1. import "slack"
  2. import "influxdata/influxdb/secrets"
  3. token = secrets.get(key: "SLACK_TOKEN")
  4. e = slack.endpoint(token: token)
  5. crit_statuses = from(bucket: "example-bucket")
  6. |> range(start: -1m)
  7. |> filter(fn: (r) => r._measurement == "statuses" and status == "crit")
  8. crit_statuses
  9. |> e(mapFn: (r) => ({
  10. channel: r.channel,
  11. text: r.text,
  12. color: r.color,
  13. })
  14. )()

endpoints