docs-v2/content/flux/v0.x/stdlib/slack/message.md

2.4 KiB

title description aliases menu weight introduced
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.
/influxdb/v2.0/reference/flux/functions/slack/message/
/influxdb/v2.0/reference/flux/stdlib/slack/message/
/influxdb/cloud/reference/flux/stdlib/slack/message/
flux_0_x_ref
name parent
slack.message slack
202 0.41.0

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.

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. Default is https://slack.com/api/chat.postMessage.

{{% note %}} If using a Slack webhook, you'll receive a Slack webhook URL when you create an incoming webhook. {{% /note %}}

token

The Slack API token used to interact with Slack. Default is "".

{{% note %}} A token is only required if using the Slack chat.postMessage API. {{% /note %}}

channel

({{< req >}}) The name of channel to post the message to.

text

({{< req >}}) The text to display in the Slack message.

color

({{< req >}}) The color to include with the message.

Valid values include:

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

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()
    |> 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",
)