79 lines
2.5 KiB
YAML
79 lines
2.5 KiB
YAML
name: Notify Telegram
|
|
description: Send a Telegram message about a workflow's outcome. Skips silently if secrets are missing.
|
|
|
|
inputs:
|
|
bot-token:
|
|
description: Telegram bot token
|
|
required: true
|
|
chat-id:
|
|
description: Telegram chat id
|
|
required: true
|
|
status:
|
|
description: "Workflow status — 'success' or 'failure'"
|
|
required: true
|
|
title:
|
|
description: Short label for the workflow (e.g. "RMS Ecosystem deploy", "TastyTalks build")
|
|
required: true
|
|
message:
|
|
description: Optional extra body line (commit message, error summary, etc)
|
|
required: false
|
|
default: ""
|
|
notify-on-success:
|
|
description: "Set to 'false' to skip Telegram on success (useful for chatty crons)"
|
|
required: false
|
|
default: "true"
|
|
|
|
runs:
|
|
using: composite
|
|
steps:
|
|
- name: Send Telegram message
|
|
shell: bash
|
|
env:
|
|
BOT_TOKEN: ${{ inputs.bot-token }}
|
|
CHAT_ID: ${{ inputs.chat-id }}
|
|
STATUS: ${{ inputs.status }}
|
|
TITLE: ${{ inputs.title }}
|
|
BODY: ${{ inputs.message }}
|
|
NOTIFY_SUCCESS: ${{ inputs.notify-on-success }}
|
|
COMMIT_SHA: ${{ github.sha }}
|
|
REPO: ${{ github.repository }}
|
|
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
|
|
run: |
|
|
if [ -z "$BOT_TOKEN" ] || [ -z "$CHAT_ID" ]; then
|
|
echo "Telegram credentials missing, skipping."
|
|
exit 0
|
|
fi
|
|
if [ "$STATUS" = "success" ] && [ "$NOTIFY_SUCCESS" != "true" ]; then
|
|
echo "notify-on-success=false, skipping success ping."
|
|
exit 0
|
|
fi
|
|
|
|
if [ "$STATUS" = "success" ]; then
|
|
icon="OK"
|
|
else
|
|
icon="FAIL"
|
|
fi
|
|
|
|
short_sha="${COMMIT_SHA:0:7}"
|
|
msg="[${icon}] ${TITLE}
|
|
Repo: ${REPO}@${short_sha}"
|
|
if [ -n "$BODY" ]; then
|
|
msg="${msg}
|
|
${BODY}"
|
|
fi
|
|
if [ "$STATUS" != "success" ]; then
|
|
msg="${msg}
|
|
Logs: ${RUN_URL}"
|
|
fi
|
|
|
|
# Install curl if missing (alpine images often lack it)
|
|
if ! command -v curl >/dev/null 2>&1; then
|
|
if command -v apk >/dev/null 2>&1; then apk add --no-cache curl >/dev/null
|
|
elif command -v apt-get >/dev/null 2>&1; then apt-get update -qq && apt-get install -y -qq curl >/dev/null
|
|
fi
|
|
fi
|
|
|
|
curl -sS -X POST "https://api.telegram.org/bot${BOT_TOKEN}/sendMessage" \
|
|
-d chat_id="${CHAT_ID}" \
|
|
--data-urlencode text="${msg}" \
|
|
-d disable_web_page_preview=true > /dev/null
|