airflow.providers.discord.hooks.discord_webhook

Classes

DiscordCommonHandler

Contains the common functionality.

DiscordWebhookHook

This hook allows you to post messages to Discord using incoming webhooks.

DiscordWebhookAsyncHook

This hook allows you to post messages to Discord using incoming webhooks using async HTTP.

Module Contents

class airflow.providers.discord.hooks.discord_webhook.DiscordCommonHandler[source]

Contains the common functionality.

get_webhook_endpoint(conn, webhook_endpoint)[source]

Return the default webhook endpoint or override if a webhook_endpoint is manually supplied.

Parameters:
  • conn (airflow.providers.common.compat.sdk.Connection | None) – Airflow Discord connection

  • webhook_endpoint (str | None) – The manually provided webhook endpoint

Returns:

Webhook endpoint (str) to use

Return type:

str

validate_embed(*, embed)[source]

Validate Discord Embed JSON payload.

Validates the embed object against Discord limits. See:

https://discord.com/developers/docs/resources/message#embed-object-embed-limits

Parameters:

embed (airflow.providers.discord.notifications.embed.Embed) – Discord embed object.

Returns:

Discord embed object.

Return type:

airflow.providers.discord.notifications.embed.Embed

build_discord_payload(*, tts, message, username, avatar_url, embed=None)[source]

Build a valid Discord JSON payload.

Parameters:
  • tts (bool) – Is a text-to-speech message

  • message (str) – The message you want to send to your Discord channel (max 2000 characters)

  • username (str | None) – Override the default username of the webhook

  • avatar_url (str | None) – Override the default avatar of the webhook

  • embed (airflow.providers.discord.notifications.embed.Embed | None) – Discord embed object.

Returns:

Discord payload (str) to send

Return type:

str

class airflow.providers.discord.hooks.discord_webhook.DiscordWebhookHook(http_conn_id=None, webhook_endpoint=None, message='', username=None, avatar_url=None, tts=False, proxy=None, embed=None, *args, **kwargs)[source]

Bases: airflow.providers.http.hooks.http.HttpHook

This hook allows you to post messages to Discord using incoming webhooks.

Takes a Discord connection ID with a default relative webhook endpoint. The default endpoint can be overridden using the webhook_endpoint parameter (https://discordapp.com/developers/docs/resources/webhook).

Each Discord webhook can be pre-configured to use a specific username and avatar_url. You can override these defaults in this hook.

Parameters:
  • http_conn_id (str | None) – Http connection ID with host as “https://discord.com/api/” and default webhook endpoint in the extra field in the form of {“webhook_endpoint”: “webhooks/{webhook.id}/{webhook.token}”}

  • webhook_endpoint (str | None) – Discord webhook endpoint in the form of “webhooks/{webhook.id}/{webhook.token}”

  • message (str) – The message you want to send to your Discord channel (max 2000 characters)

  • username (str | None) – Override the default username of the webhook

  • avatar_url (str | None) – Override the default avatar of the webhook

  • tts (bool) – Is a text-to-speech message

  • proxy (str | None) – Proxy to use to make the Discord webhook call

  • embed (airflow.providers.discord.notifications.embed.Embed | None) – Discord embed object.

conn_name_attr = 'http_conn_id'[source]
default_conn_name = 'discord_default'[source]
conn_type = 'discord'[source]
hook_name = 'Discord'[source]
classmethod get_connection_form_widgets()[source]

Return connection widgets to add to Discord connection form.

handler[source]
http_conn_id: Any = None[source]
webhook_endpoint[source]
message = ''[source]
username = None[source]
avatar_url = None[source]
tts = False[source]
proxy = None[source]
embed = None[source]
execute()[source]

Execute the Discord webhook call.

class airflow.providers.discord.hooks.discord_webhook.DiscordWebhookAsyncHook(*, http_conn_id='', webhook_endpoint=None, message='', username=None, avatar_url=None, tts=False, proxy=None, embed=None, **kwargs)[source]

Bases: airflow.providers.http.hooks.http.HttpAsyncHook

This hook allows you to post messages to Discord using incoming webhooks using async HTTP.

Takes a Discord connection ID with a default relative webhook endpoint. The default endpoint can be overridden using the webhook_endpoint parameter (https://discordapp.com/developers/docs/resources/webhook).

Each Discord webhook can be pre-configured to use a specific username and avatar_url. You can override these defaults in this hook.

Parameters:
  • http_conn_id (str) – Http connection ID with host as “https://discord.com/api/” and default webhook endpoint in the extra field in the form of {“webhook_endpoint”: “webhooks/{webhook.id}/{webhook.token}”}

  • webhook_endpoint (str | None) – Discord webhook endpoint in the form of “webhooks/{webhook.id}/{webhook.token}”

  • message (str) – The message you want to send to your Discord channel (max 2000 characters)

  • username (str | None) – Override the default username of the webhook

  • avatar_url (str | None) – Override the default avatar of the webhook

  • tts (bool) – Is a text-to-speech message

  • proxy (str | None) – Proxy to use to make the Discord webhook call

  • embed (airflow.providers.discord.notifications.embed.Embed | None) – Discord embed object.

default_headers[source]
conn_name_attr = 'http_conn_id'[source]
default_conn_name = 'discord_default'[source]
conn_type = 'discord'[source]
hook_name = 'Async Discord'[source]
http_conn_id = ''[source]
webhook_endpoint = None[source]
message = ''[source]
username = None[source]
avatar_url = None[source]
tts = False[source]
proxy = None[source]
embed = None[source]
handler[source]
async execute()[source]

Execute the Discord webhook call.

Was this entry helpful?