Documentation

slack.message() function

The slack.message() function sends a single message to a Slack channel. The function works with either with the chat.postMessage API or with a Slack webhook.

Function type: Output

import "slack"

slack.message(
  url: "https://slack.com/api/chat.postMessage",
  token: "mySuPerSecRetTokEn",
  channel: "#flux",
  text: "This is a message from the Flux slack.message() function.",
  color: "good"
)

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

channel

(Required) The name of channel to post the message to.

Data type: String

text

(Required) The text to display in the Slack message.

Data type: String

color

(Required) The color to include with the message.

Valid values include:

  • good
  • warning
  • danger
  • Any valid RGB hex color code. For example, #439FE0.

Data type: String

Examples

Send the last reported status to Slack using a Slack webhook
import "slack"

lastReported =
  from(bucket: "example-bucket")
    |> range(start: -1m)
    |> filter(fn: (r) => r._measurement == "statuses")
    |> last()
    |> findRecord(fn: (key) => true, idx: 0)

slack.message(
  url: "https://hooks.slack.com/services/EXAMPLE-WEBHOOK-URL",
  channel: "#system-status",
  text: "The last reported status was \"${lastReported.status}\"."
  color: "warning"
)
Send the last reported status to Slack using chat.postMessage API
import "slack"

lastReported =
  from(bucket: "example-bucket")
    |> range(start: -1m)
    |> filter(fn: (r) => r._measurement == "statuses")
    |> last()
    |> tableFind(fn: (key) => true)
    |> getRecord(idx: 0)

slack.message(
  url: "https://slack.com/api/chat.postMessage",
  token: "mySuPerSecRetTokEn",
  channel: "#system-status",
  text: "The last reported status was \"${lastReported.status}\"."
  color: "warning"
)

Select your region

Upgrade to InfluxDB Cloud or InfluxDB 2.0!

InfluxDB Cloud and InfluxDB OSS 2.0 ready for production.