InfluxDB Docs

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",
  username: "Fluxtastic",
  channel: "#flux",
  workspace: "",
  text: "This is a message from the Flux slack.message() function.",
  iconEmoji: "wave",
  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

username

The username to use when posting the message to a Slack channel. Required

Data type: String

channel

The name of channel to post the message to. Required

Data type: String

workspace

The name of the Slack workspace to use if there are multiple. Defaults to "".

Data type: String

text

The text to display in the Slack message. Required

Data type: String

iconEmoji

The name of emoji to use as the user avatar when posting the message to Slack. Required

Data type: String

Things to know about iconEmoji

  • Do not enclose the name in colons : as you do in the Slack client.
  • iconEmoji only appears as the user avatar when using the Slack chat.postMessage API.

color

The color to include with the message. Required

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
import "slack"

lastReported =
  from(bucket: "example-bucket")
    |> range(start: -1m)
    |> filter(fn: (r) => r._measurement == "statuses")
    |> last()
    |> map(fn: (r) => { return {status: r._status} })

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