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*

  1. import "slack"
  2. slack.message(
  3. url: "https://slack.com/api/chat.postMessage",
  4. token: "mySuPerSecRetTokEn",
  5. channel: "#flux",,
  6. text: "This is a message from the Flux slack.message() function.",
  7. color: "good"
  8. )

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

The name of channel to post the message to. Required

*Data type: String*

text

The text to display in the Slack message. Required

*Data type: String*

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
  1. import "slack"
  2. lastReported =
  3. from(bucket: "example-bucket")
  4. |> range(start: -1m)
  5. |> filter(fn: (r) => r._measurement == "statuses")
  6. |> last()
  7. |> tableFind(fn: (key) => true)
  8. |> getRecord(idx: 0)
  9. slack.message(
  10. url: "https://slack.com/api/chat.postMessage",
  11. token: "mySuPerSecRetTokEn",
  12. channel: "#system-status",
  13. text: "The last reported status was \"${lastReported.status}\"."
  14. color: "warning"
  15. )