discord.endpoint() function

The discord.endpoint() function is a user-contributed function maintained by the package author and can be updated or removed at any time.

The discord.endpoint() function sends a single message to a Discord channel using a Discord webhook and data from table rows.

*Function type: Output*

  1. import "contrib/chobbs/discord"
  2. discord.endpoint(
  3. webhookToken: "mySuPerSecRetTokEn",
  4. webhookID: "123456789",
  5. username: "username",
  6. avatar_url: "https://example.com/avatar_pic.jpg"
  7. )

Parameters

webhookToken

Discord webhook token.

*Data type: String*

webhookID

Discord webhook ID.

*Data type: String*

username

Override the Discord webhook’s default username.

*Data type: String*

avatar_url

Override the Discord webhook’s default avatar.

*Data type: String*

Usage

discord.endpoint is a factory function that outputs another function. The output function requires a mapFn parameter.

mapFn

A function that builds the record used to generate the Discord webhook request. Requires an r parameter.

*Data type: Function*

mapFn accepts a table row (r) and returns a record that must include the following field:

  • content

For more information, see the discord.send() content parameter.

Examples

Send critical statuses to a Discord channel
  1. import "influxdata/influxdb/secrets"
  2. import "contrib/chobbs/discord"
  3. discordToken = secrets.get(key: "DISCORD_TOKEN")
  4. endpoint = telegram.endpoint(
  5. webhookToken: discordToken,
  6. webhookID: "123456789",
  7. username: "critBot"
  8. )
  9. crit_statuses = from(bucket: "example-bucket")
  10. |> range(start: -1m)
  11. |> filter(fn: (r) => r._measurement == "statuses" and status == "crit")
  12. crit_statuses
  13. |> endpoint(mapFn: (r) => ({
  14. content: "The status is critical!",
  15. })
  16. )()

Package author and maintainer

Github: @chobbs
InfluxDB Slack: @craig