AshDispatch.Transports.Slack (AshDispatch v0.1.4)

View Source

Slack webhook transport.

Sends messages to Slack channels via webhooks (async via Oban).

Configuration

Requires webhook_url in channel metadata or via callback:

# Inline configuration
event :order_created,
  channels: [
    [
      transport: :slack,
      audience: :team,
      metadata: [
        webhook_url: "https://hooks.slack.com/services/..."
      ]
    ]
  ]

# Or via callback module
def channels(context) do
  [
    %Channel{
      transport: :slack,
      audience: :team,
      metadata: %{
        webhook_url: get_slack_webhook_url(:orders)
      }
    }
  ]
end

Content

Slack messages support:

  • notification_message - Simple text content (supports Slack mrkdwn)
  • slack_blocks - Block Kit layout blocks for rich formatting
  • slack_attachments - Legacy attachment format
  • slack_username - Override bot username
  • slack_icon_emoji - Override bot icon with emoji
  • slack_icon_url - Override bot icon with image URL

Example with blocks:

content: [
  notification_message: "New order received!",
  slack_blocks: [
    %{
      type: "header",
      text: %{type: "plain_text", text: "Order {{id}} Created"}
    },
    %{
      type: "section",
      fields: [
        %{type: "mrkdwn", text: "*Customer:*\n{{user.name}}"},
        %{type: "mrkdwn", text: "*Total:*\n${{total}}"}
      ]
    }
  ]
]

Slack Message Formatting

Slack uses mrkdwn (markdown-like) formatting:

  • *bold* - Bold text
  • _italic_ - Italic text
  • ~strikethrough~ - Strikethrough
  • `code` - Inline code
  • code block - Code block
  • <url|text> - Hyperlink

Summary

Functions

Delivers Slack notification by enqueueing SendWebhook worker.

Functions

deliver(receipt, context, channel, event_config)

Delivers Slack notification by enqueueing SendWebhook worker.

Receipt Content

Expected content structure:

  • notification_message - Message text (required, supports mrkdwn)
  • slack_blocks - Block Kit blocks (optional)
  • slack_attachments - Legacy attachments (optional)
  • slack_username - Bot username override (optional)
  • slack_icon_emoji - Bot icon emoji (optional, e.g., ":robot_face:")
  • slack_icon_url - Bot icon URL (optional)

Channel Metadata

Expected metadata:

  • webhook_url - Slack webhook URL (required)