#!/bin/bash
# Test Discord webhook delivery
# This script sends a test webhook event with valid signature
set -e
# Configuration
WEBHOOK_SECRET="${GITHUB_WEBHOOK_SECRET:-test_secret_12345}"
DISCORD_WEBHOOK_URL="${DISCORD_WEBHOOK_URL:-}"
PORT="${PORT:-9999}"
URL="http://localhost:${PORT}/webhooks/github"
# Check if server is running
if ! curl -s "http://localhost:${PORT}/health" > /dev/null 2>&1; then
echo "❌ Server not running on port ${PORT}"
echo "Start it with: source ~/.openclaw/secrets/github.env && node dist/server-http.js"
exit 1
fi
echo "✓ Server is running"
if [ -z "$DISCORD_WEBHOOK_URL" ]; then
echo "⚠️ DISCORD_WEBHOOK_URL not set - delivery will be skipped but message will be formatted"
fi
# Test payload - release event
PAYLOAD='{
"action": "published",
"release": {
"tag_name": "v1.2.3",
"name": "Test Release v1.2.3",
"html_url": "https://github.com/test-user/test-repo/releases/tag/v1.2.3",
"body": "This is a test release with some notes.\n\n## Changes\n- Feature A\n- Bug fix B",
"author": {
"login": "test-user"
}
},
"repository": {
"full_name": "test-user/test-repo",
"html_url": "https://github.com/test-user/test-repo"
},
"sender": {
"login": "test-user",
"html_url": "https://github.com/test-user"
}
}'
# Generate HMAC signature
SIGNATURE="sha256=$(echo -n "$PAYLOAD" | openssl dgst -sha256 -hmac "$WEBHOOK_SECRET" | sed 's/^.* //')"
echo ""
echo "Sending test release webhook..."
echo "Event: release"
echo "Action: published"
echo ""
# Send webhook
RESPONSE=$(curl -s -w "\n%{http_code}" -X POST "$URL" \
-H "Content-Type: application/json" \
-H "X-GitHub-Event: release" \
-H "X-GitHub-Delivery: test-$(date +%s)" \
-H "X-Hub-Signature-256: $SIGNATURE" \
-d "$PAYLOAD")
HTTP_CODE=$(echo "$RESPONSE" | tail -n1)
BODY=$(echo "$RESPONSE" | head -n-1)
echo "Response (HTTP $HTTP_CODE):"
echo "$BODY" | jq -r '.' 2>/dev/null || echo "$BODY"
if [ "$HTTP_CODE" = "200" ]; then
echo ""
echo "✅ Webhook processed successfully!"
DELIVERED=$(echo "$BODY" | jq -r '.delivered' 2>/dev/null || echo "unknown")
if [ "$DELIVERED" = "true" ]; then
echo "✅ Message delivered to Discord"
elif [ "$DELIVERED" = "false" ]; then
echo "⚠️ Message formatted but not delivered (check DISCORD_WEBHOOK_URL)"
fi
else
echo ""
echo "❌ Webhook failed"
fi