cbrgm / telegram-github-action

Send (text) messages to a Telegram chat from GitHub Actions
https://cbrgm.net
Apache License 2.0
7 stars 1 forks source link
action gihub-actions github go message telegram

Telegram GitHub Action

Send (text) messages to a Telegram chat from GitHub Actions.

GitHub release Go Report Card go-lint-test go-binaries container

Inputs

Workflow Usage

name: Send Telegram Message

on: [push]

jobs:
  notify:
    runs-on: ubuntu-latest
    steps:
      - name: Send Telegram Message
        uses: cbrgm/telegram-github-action@v1
        with:
          token: ${{ secrets.TELEGRAM_TOKEN }}
          to: ${{ secrets.TELEGRAM_CHAT_ID }}
          message: "New commit pushed to repository"

Example Workflow: Inline Messages and Variable Templating

This workflow triggers a Telegram message notification when a new tag is published in the repository.

name: Inline Message Workflow

on:
  push:
    branches: [main]

jobs:
  send-inline-message:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Send Inline Telegram Message
        uses: cbrgm/telegram-github-action@v1
        with:
          token: ${{ secrets.TELEGRAM_TOKEN }}
          to: ${{ secrets.TELEGRAM_CHAT_ID }}
          message: |
            New commit by ${{ github.actor }}!
            Commit: ${{ github.event.head_commit.message }}
            Repository: ${{ github.repository }}
            View changes: https://github.com/${{ github.repository }}/commit/${{ github.sha }}

Example Workflow: Notification on New GitHub Release

This workflow triggers a Telegram message notification when a new release is published in the repository.

name: Release Notification

on:
  release:
    types: [published]

jobs:
  notify-on-release:
    runs-on: ubuntu-latest
    steps:
      - name: Send Telegram Notification on New Release
        uses: cbrgm/telegram-github-action@v1
        with:
          token: ${{ secrets.TELEGRAM_TOKEN }}
          to: ${{ secrets.TELEGRAM_CHAT_ID }}
          message: |
            πŸš€ New Release Published!
            Release Name: ${{ github.event.release.name }}
            Tag: ${{ github.event.release.tag_name }}
            Actor: ${{ github.actor }}
            Repository: ${{ github.repository }}
            Check it out: ${{ github.event.release.html_url }}j

Creating a Telegram Bot and Obtaining a Token

  1. Chat with BotFather on Telegram.
  2. Follow prompts to name your bot and get a token.
  3. Store the token as a GitHub secret (TELEGRAM_TOKEN).

Obtaining the Chat ID

Run the following command:

curl https://api.telegram.org/bot<token>/getUpdates

Replace with your bot's token to find your chat_id (TELEGRAM_CHAT_ID).

Local Development

You can build this action from source using Go:

make build

Contributing & License