From 01b57287125c7f292482d485c9083cecb61850cc Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Mon, 20 Jul 2020 14:28:45 -0600 Subject: [PATCH] Added discord.endpoint function, resolves #1218 --- .../flux/stdlib/contrib/discord/_index.md | 4 +- .../flux/stdlib/contrib/discord/endpoint.md | 99 +++++++++++++++++++ 2 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 content/v2.0/reference/flux/stdlib/contrib/discord/endpoint.md diff --git a/content/v2.0/reference/flux/stdlib/contrib/discord/_index.md b/content/v2.0/reference/flux/stdlib/contrib/discord/_index.md index ecd131b2e..f7ed590d1 100644 --- a/content/v2.0/reference/flux/stdlib/contrib/discord/_index.md +++ b/content/v2.0/reference/flux/stdlib/contrib/discord/_index.md @@ -2,7 +2,7 @@ title: Flux Discord package list_title: Discord package description: > - The Flux Discord package provides functions for sending data to Discord. + The Flux Discord package provides functions for sending messages to Discord. Import the `contrib/chobbs/discord` package. menu: v2_0_ref: @@ -12,7 +12,7 @@ weight: 202 v2.0/tags: [functions, discord, package] --- -The Flux Discord package provides functions for sending data to Discord. +The Flux Discord package provides functions for sending messages to Discord. Import the `contrib/chobbs/discord` package: ```js diff --git a/content/v2.0/reference/flux/stdlib/contrib/discord/endpoint.md b/content/v2.0/reference/flux/stdlib/contrib/discord/endpoint.md new file mode 100644 index 000000000..9e0d59ea7 --- /dev/null +++ b/content/v2.0/reference/flux/stdlib/contrib/discord/endpoint.md @@ -0,0 +1,99 @@ +--- +title: discord.endpoint() function +description: > + The `discord.endpoint()` function sends a single message to a Discord channel using + a [Discord webhook](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks&?page=3) + and data from table rows. +menu: + v2_0_ref: + name: discord.endpoint + parent: Discord +weight: 202 +--- + +The `discord.endpoint()` function sends a single message to a Discord channel using +a [Discord webhook](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks&?page=3) +and data from table rows. + +_**Function type:** Output_ + +```js +import "contrib/chobbs/discord" + +discord.endpoint( + webhookToken: "mySuPerSecRetTokEn", + webhookID: "123456789", + username: "username", + avatar_url: "https://example.com/avatar_pic.jpg" +) +``` + +## Parameters + +### webhookToken +Discord [webhook token](https://discord.com/developers/docs/resources/webhook). + +_**Data type:** String_ + +### webhookID +Discord [webhook ID](https://discord.com/developers/docs/resources/webhook). + +_**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 object used to generate the Discord webhook request. +Requires an `r` parameter. + +_**Data type:** Function_ + +`mapFn` accepts a table row (`r`) and returns an object that must include the +following field: + +- `content` + +_For more information, see the [`discord.send() content` parameter](/v2.0/reference/flux/stdlib/contrib/discord/send/#content)._ + +## Examples + +##### Send critical statuses to a Discord channel +```js +import "influxdata/influxdb/secrets" +import "contrib/chobbs/discord" + +discordToken = secrets.get(key: "DISCORD_TOKEN") +endpoint = telegram.endpoint( + webhookToken: discordToken, + webhookID: "123456789", + username: "critBot" +) + +crit_statuses = from(bucket: "example-bucket") + |> range(start: -1m) + |> filter(fn: (r) => r._measurement == "statuses" and status == "crit") + +crit_statuses + |> endpoint(mapFn: (r) => ({ + content: "The status is critical!", + }) + )() +``` + +{{% note %}} +#### Package author and maintainer +**Github:** [@chobbs](https://github.com/chobbs) +**InfluxDB Slack:** [@craig](https://influxdata.com/slack) +{{% /note %}}