-
Notifications
You must be signed in to change notification settings - Fork 26
Refactor Telegram workflow for custom message broadcast #1899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,109 +1,58 @@ | ||||||||||||||||||||||||||||||||||||||||||||
| name: Telegram Send Message All Groups | ||||||||||||||||||||||||||||||||||||||||||||
| name: Telegram Broadcast Custom Message | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| on: | ||||||||||||||||||||||||||||||||||||||||||||
| workflow_call: | ||||||||||||||||||||||||||||||||||||||||||||
| workflow_dispatch: | ||||||||||||||||||||||||||||||||||||||||||||
| inputs: | ||||||||||||||||||||||||||||||||||||||||||||
| message: | ||||||||||||||||||||||||||||||||||||||||||||
| description: "Message to send to all Telegram groups" | ||||||||||||||||||||||||||||||||||||||||||||
| description: 'The message to send to Telegram' | ||||||||||||||||||||||||||||||||||||||||||||
| required: true | ||||||||||||||||||||||||||||||||||||||||||||
| type: string | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
3
to
9
|
||||||||||||||||||||||||||||||||||||||||||||
| parse_mode: | ||||||||||||||||||||||||||||||||||||||||||||
| description: "Parse mode for Telegram message (HTML or Markdown)" | ||||||||||||||||||||||||||||||||||||||||||||
| required: false | ||||||||||||||||||||||||||||||||||||||||||||
| type: string | ||||||||||||||||||||||||||||||||||||||||||||
| default: "HTML" | ||||||||||||||||||||||||||||||||||||||||||||
| test_mode: | ||||||||||||||||||||||||||||||||||||||||||||
| description: "If true, only send to testing group" | ||||||||||||||||||||||||||||||||||||||||||||
| required: false | ||||||||||||||||||||||||||||||||||||||||||||
| type: boolean | ||||||||||||||||||||||||||||||||||||||||||||
| default: false | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| jobs: | ||||||||||||||||||||||||||||||||||||||||||||
| send-message: | ||||||||||||||||||||||||||||||||||||||||||||
| broadcast: | ||||||||||||||||||||||||||||||||||||||||||||
| name: Broadcast Message | ||||||||||||||||||||||||||||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| steps: | ||||||||||||||||||||||||||||||||||||||||||||
| - name: Send message to Telegram groups | ||||||||||||||||||||||||||||||||||||||||||||
| - name: Send Telegram Message | ||||||||||||||||||||||||||||||||||||||||||||
| env: | ||||||||||||||||||||||||||||||||||||||||||||
| MESSAGE_CONTENT: ${{ inputs.message }} | ||||||||||||||||||||||||||||||||||||||||||||
| # This pulls the token and chat IDs from your GitHub Secrets | ||||||||||||||||||||||||||||||||||||||||||||
| TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} | ||||||||||||||||||||||||||||||||||||||||||||
| # Keeping multiple IDs if you have a list, otherwise it will just use the main one | ||||||||||||||||||||||||||||||||||||||||||||
| TELEGRAM_CHAT_IDS: ${{ secrets.TELEGRAM_CHAT_IDS }} | ||||||||||||||||||||||||||||||||||||||||||||
| MESSAGE: ${{ github.event.inputs.message }} | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+19
to
+23
|
||||||||||||||||||||||||||||||||||||||||||||
| PARSE_MODE: "Markdown" | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+19
to
+24
|
||||||||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||||||||
| # Pocket Network Bot Testing Group | ||||||||||||||||||||||||||||||||||||||||||||
| CHAT_1="-1002895286734" | ||||||||||||||||||||||||||||||||||||||||||||
| # BitGet <> Pocket Network (POKT) | ||||||||||||||||||||||||||||||||||||||||||||
| CHAT_2="-4954094158" | ||||||||||||||||||||||||||||||||||||||||||||
| # ByBit <> POKT | ||||||||||||||||||||||||||||||||||||||||||||
| CHAT_3="-1002730340404" | ||||||||||||||||||||||||||||||||||||||||||||
| # CoinEx <> POKT | ||||||||||||||||||||||||||||||||||||||||||||
| CHAT_4="-1001946726820" | ||||||||||||||||||||||||||||||||||||||||||||
| # Mr. Yang <> Grove / POKT | ||||||||||||||||||||||||||||||||||||||||||||
| CHAT_5="-1002038833795" | ||||||||||||||||||||||||||||||||||||||||||||
| # MEXC <> POKT | ||||||||||||||||||||||||||||||||||||||||||||
| CHAT_6="-1002815210935" | ||||||||||||||||||||||||||||||||||||||||||||
| # OKX <> Pocket Network | ||||||||||||||||||||||||||||||||||||||||||||
| CHAT_7="-1001901668586" | ||||||||||||||||||||||||||||||||||||||||||||
| # OrangeX <> Grove (POKT) | ||||||||||||||||||||||||||||||||||||||||||||
| CHAT_8="-1002030782436" | ||||||||||||||||||||||||||||||||||||||||||||
| # POKT & Gate.io | ||||||||||||||||||||||||||||||||||||||||||||
| CHAT_9="-1001717732565" | ||||||||||||||||||||||||||||||||||||||||||||
| # POKT Network | AscendEX | ||||||||||||||||||||||||||||||||||||||||||||
| CHAT_10="-4565872373" | ||||||||||||||||||||||||||||||||||||||||||||
| # Uphold <> Grove (POKT) | ||||||||||||||||||||||||||||||||||||||||||||
| CHAT_11="-1002227693360" | ||||||||||||||||||||||||||||||||||||||||||||
| # Pokt <> Kraken {EF introduction} | ||||||||||||||||||||||||||||||||||||||||||||
| CHAT_12="-1002405763552" | ||||||||||||||||||||||||||||||||||||||||||||
| # Bitrue & Pocket Network | ||||||||||||||||||||||||||||||||||||||||||||
| CHAT_13="-618542738" | ||||||||||||||||||||||||||||||||||||||||||||
| # HTX <> POKT | ||||||||||||||||||||||||||||||||||||||||||||
| CHAT_14="-1002898513049" | ||||||||||||||||||||||||||||||||||||||||||||
| # POKT <> Upbit | ||||||||||||||||||||||||||||||||||||||||||||
| CHAT_15="-1002653157934" | ||||||||||||||||||||||||||||||||||||||||||||
| # KuCoin <> POKT | ||||||||||||||||||||||||||||||||||||||||||||
| CHAT_16="-775612675" | ||||||||||||||||||||||||||||||||||||||||||||
| # Korbit <> POKT | ||||||||||||||||||||||||||||||||||||||||||||
| CHAT_17="-1002811115444" | ||||||||||||||||||||||||||||||||||||||||||||
| # The Poktopus Den | ||||||||||||||||||||||||||||||||||||||||||||
| CHAT_18="-1001461397826" | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # Get the message and parse mode from the workflow inputs | ||||||||||||||||||||||||||||||||||||||||||||
| MESSAGE="$MESSAGE_CONTENT" | ||||||||||||||||||||||||||||||||||||||||||||
| PARSE_MODE="${{ inputs.parse_mode }}" | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # Function to send message to a chat | ||||||||||||||||||||||||||||||||||||||||||||
| send_message() { | ||||||||||||||||||||||||||||||||||||||||||||
| local chat_id="$1" | ||||||||||||||||||||||||||||||||||||||||||||
| local chat_name="$2" | ||||||||||||||||||||||||||||||||||||||||||||
| echo "Sending to $chat_id ($chat_name)" | ||||||||||||||||||||||||||||||||||||||||||||
| curl -s -X POST https://api.telegram.org/bot7267336172:AAEYaEeY0i7DfbL7SsRjPf09N67mvLo8WC4/sendMessage \ | ||||||||||||||||||||||||||||||||||||||||||||
| echo "Sending message to Chat ID: $chat_id" | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # Use the variable instead of the hardcoded token | ||||||||||||||||||||||||||||||||||||||||||||
| RESPONSE=$(curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \ | ||||||||||||||||||||||||||||||||||||||||||||
| -d chat_id="$chat_id" \ | ||||||||||||||||||||||||||||||||||||||||||||
| -d parse_mode="$PARSE_MODE" \ | ||||||||||||||||||||||||||||||||||||||||||||
| --data-urlencode text="$MESSAGE" | ||||||||||||||||||||||||||||||||||||||||||||
| echo | ||||||||||||||||||||||||||||||||||||||||||||
| --data-urlencode text="$MESSAGE") | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # Check if the Telegram API returned an error | ||||||||||||||||||||||||||||||||||||||||||||
| if echo "$RESPONSE" | grep -q '"ok":false'; then | ||||||||||||||||||||||||||||||||||||||||||||
| echo "Error sending to $chat_id: $RESPONSE" | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
| echo "Error sending to $chat_id: $RESPONSE" | |
| error_code=$(echo "$RESPONSE" | sed -n 's/.*"error_code":\([0-9]*\).*/\1/p') | |
| description=$(echo "$RESPONSE" | sed -n 's/.*"description":"\([^"]*\)".*/\1/p') | |
| echo "Error sending to $chat_id: code=${error_code:-unknown}, description=${description:-unavailable}" |
Copilot
AI
Feb 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error detection treats any response that does not contain '"ok":false' as success. If curl returns a non-JSON body (proxy error/HTML), an empty response, or a JSON error formatted differently, this can be reported as success. Consider checking the HTTP status/curl exit code and positively validating success (e.g., parse JSON and require ok == true).
| # Check if the Telegram API returned an error | |
| if echo "$RESPONSE" | grep -q '"ok":false'; then | |
| echo "Error sending to $chat_id: $RESPONSE" | |
| return 1 | |
| else | |
| echo "Success: Message sent to $chat_id" | |
| CURL_EXIT_CODE=$? | |
| # First, check if curl itself failed | |
| if [ "$CURL_EXIT_CODE" -ne 0 ]; then | |
| echo "Error sending to $chat_id: curl exited with code $CURL_EXIT_CODE" | |
| return 1 | |
| fi | |
| # Then, positively validate that the Telegram API returned ok == true | |
| if echo "$RESPONSE" | jq -e '.ok == true' > /dev/null 2>&1; then | |
| echo "Success: Message sent to $chat_id" | |
| else | |
| echo "Error sending to $chat_id: $RESPONSE" | |
| return 1 |
Copilot
AI
Feb 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
id=$(echo $id | xargs) should quote $id to avoid word-splitting/globbing surprises. Using a quoted expansion here makes the trimming robust even if the secret contains unexpected whitespace or characters.
| id=$(echo $id | xargs) | |
| id=$(echo "$id" | xargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This workflow now has the same
name:as.github/workflows/telegram-broadcast.yml(“Telegram Broadcast Custom Message”). In the GitHub Actions UI this makes it hard to distinguish which workflow ran. Consider giving each workflow a distinct name (e.g., one for the dispatcher UI entrypoint vs the reusable sender).