airflow.providers.discord.hooks.discord_webhook

Module Contents

class airflow.providers.discord.hooks.discord_webhook.DiscordWebhookHook(http_conn_id: Optional[str] = None, webhook_endpoint: Optional[str] = None, message: str = '', username: Optional[str] = None, avatar_url: Optional[str] = None, tts: bool = False, proxy: Optional[str] = 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) -- 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) -- 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) -- Override the default username of the webhook

  • avatar_url (str) -- Override the default avatar of the webhook

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

  • proxy (str) -- Proxy to use to make the Discord webhook call

_get_webhook_endpoint(self, http_conn_id: Optional[str], webhook_endpoint: Optional[str])[source]

Given a Discord http_conn_id, return the default webhook endpoint or override if a webhook_endpoint is manually supplied.

Parameters
  • http_conn_id -- The provided connection ID

  • webhook_endpoint -- The manually provided webhook endpoint

Returns

Webhook endpoint (str) to use

_build_discord_payload(self)[source]

Construct the Discord JSON payload. All relevant parameters are combined here to a valid Discord JSON payload.

Returns

Discord payload (str) to send

execute(self)[source]

Execute the Discord webhook call

Was this entry helpful?