AshDispatch.Workers.SendWebhook (AshDispatch v0.5.0)
View SourceOban worker for sending webhooks asynchronously.
This worker:
- Fetches the DeliveryReceipt by ID
- Marks receipt as
:sending - Sends HTTP POST to webhook URL
- Marks receipt as
:sentor:failed
Usage
Jobs are enqueued automatically by webhook transports (Discord, Slack, generic Webhook):
# Discord transport enqueues job
Discord.deliver(receipt, context, channel, event_config)
# Worker processes job asynchronously
%{
"receipt_id" => "...",
"webhook_url" => "https://discord.com/api/webhooks/...",
"payload" => %{
"content" => "Order #1234 created",
"embeds" => [...]
},
"headers" => %{
"Content-Type" => "application/json"
}
}Retries
Oban handles retries automatically:
- Max 5 attempts (configurable)
- Exponential backoff (configurable)
- Failed jobs can be manually retried
HTTP Client
Uses Req for HTTP requests with:
- Automatic retries for network errors
- Timeout handling (10 seconds default)
- JSON encoding/decoding
- Comprehensive error reporting
Webhook Formats
Discord and Slack use different JSON formats:
Discord
{
"content": "Message text",
"embeds": [{
"title": "Order Created",
"description": "Order #1234",
"color": 5814783
}]
}Slack
{
"text": "Message text",
"blocks": [{
"type": "section",
"text": {"type": "mrkdwn", "text": "Order #1234"}
}]
}
Summary
Functions
Processes webhook sending job.