telegram.endpoint() function

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

The telegram.endpoint() function sends a message to a Telegram channel using data from table rows.

*Function type: Output*

  1. import "contrib/sranka/telegram"
  2. telegram.endpoint(
  3. url: "https://api.telegram.org/bot",
  4. token: "S3crEtTel3gRamT0k3n",
  5. parseMode: "MarkdownV2",
  6. disableWebPagePreview: false,
  7. )

For information about retrieving your Telegram bot token and channel ID, see Set up a Telegram bot.

Parameters

url

URL of the Telegram bot endpoint. Default is https://api.telegram.org/bot.

*Data type: String*

token

Required Telegram bot token.

*Data type: String*

parseMode

Parse mode of the message text. Default is "MarkdownV2".

*Data type: String*

disableWebPagePreview

Disable preview of web links in the sent message. Default is false.

*Data type: Boolean*

Usage

telegram.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 POST request. Requires an r parameter.

*Data type: Function*

mapFn accepts a table row (r) and returns an object that must include the following fields:

  • channel
  • text
  • silent

For more information, see telegram.message() parameters.

Examples

Send critical statuses to a Telegram channel
  1. import "influxdata/influxdb/secrets"
  2. import "contrib/sranka/telegram"
  3. token = secrets.get(key: "TELEGRAM_TOKEN")
  4. endpoint = telegram.endpoint(token: token)
  5. crit_statuses = from(bucket: "example-bucket")
  6. |> range(start: -1m)
  7. |> filter(fn: (r) => r._measurement == "statuses" and status == "crit")
  8. crit_statuses
  9. |> endpoint(mapFn: (r) => ({
  10. channel: "-12345",
  11. text: "Disk usage is **${r.status}**.",
  12. silent: true
  13. })
  14. )()

Package author and maintainer

Github: @sranka
InfluxDB Slack: @sranka