60 lines
2.0 KiB
YAML
60 lines
2.0 KiB
YAML
name: "Discord Webhook"
|
|
description: "Send a message to Discord via webhook using curl"
|
|
inputs:
|
|
webhook_url:
|
|
description: "Discord webhook URL"
|
|
required: true
|
|
message:
|
|
description: "Message to send"
|
|
required: true
|
|
username:
|
|
description: "Override the default username of the webhook"
|
|
required: false
|
|
default: ""
|
|
avatar_url:
|
|
description: "Override the default avatar of the webhook"
|
|
required: false
|
|
default: ""
|
|
color:
|
|
description: "Embed color (decimal number)"
|
|
required: false
|
|
default: ""
|
|
|
|
runs:
|
|
using: "composite"
|
|
steps:
|
|
- name: Send Discord notification
|
|
shell: bash
|
|
run: |
|
|
MESSAGE='${{ inputs.message }}'
|
|
|
|
if [ -n "${{ inputs.color }}" ]; then
|
|
# Send as embed with color
|
|
PAYLOAD=$(jq -n \
|
|
--arg content "$MESSAGE" \
|
|
--arg username "${{ inputs.username }}" \
|
|
--arg avatar "${{ inputs.avatar_url }}" \
|
|
--arg color "${{ inputs.color }}" \
|
|
'{
|
|
content: (if $content != "" then $content else null end),
|
|
username: (if $username != "" then $username else null end),
|
|
avatar_url: (if $avatar != "" then $avatar else null end),
|
|
embeds: (if $color != "" then [{description: $content, color: ($color | tonumber)}] else null end)
|
|
} | with_entries(select(.value != null))')
|
|
else
|
|
# Send as simple message
|
|
PAYLOAD=$(jq -n \
|
|
--arg content "$MESSAGE" \
|
|
--arg username "${{ inputs.username }}" \
|
|
--arg avatar "${{ inputs.avatar_url }}" \
|
|
'{
|
|
content: $content,
|
|
username: (if $username != "" then $username else null end),
|
|
avatar_url: (if $avatar != "" then $avatar else null end)
|
|
} | with_entries(select(.value != null))')
|
|
fi
|
|
|
|
curl -H "Content-Type: application/json" \
|
|
-d "$PAYLOAD" \
|
|
"${{ inputs.webhook_url }}"
|