InfluxDB Docs

slack.endpoint() function

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

Function type: Output

import "slack"

slack.endpoint(
  url: "https://slack.com/api/chat.postMessage",
  token: "mySuPerSecRetTokEn"
)

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

mapFn

A function that builds the object used to generate the POST request.

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 object must include the following fields:

  • username
  • channel
  • workspace
  • text
  • iconEmoji
  • color

For more information, see slack.message()

Examples

Send critical statuses to a Slack endpoint
import "monitor"
import "slack"

endpoint = slack.endpoint(token: "mySuPerSecRetTokEn")

from(bucket: "example-bucket")
  |> range(start: -1m)
  |> filter(fn: (r) => r._measurement == "statuses" and status == "crit")
  |> map(fn: (r) => { return {r with status: r._status} })
  |> monitor.notify(endpoint: endpoint)