/gh-action-telegram-notify

Telegram notification action for GitHub Actions. This action sends a message to a Telegram chat using a bot.

gh-action-telegram-notify

This repository contains a simple setup for sending Telegram notifications through GitHub Actions. It allows you to stay informed about various events and activities related to your GitHub repository.


Professional related project: cslant/laravel-telegram-git-notifier

Information

How it works

The workflow in this repository is configured to trigger various events such as pushes, pull requests, issue updates, releases, comments, and more. When any of these events occur, a notification will be sent to your Telegram chat using a Telegram bot.

The notifications will provide relevant information about the event, such as the event type, repository name, user who initiated the event, commit SHA and other useful details. This can help you keep track of activities and changes happening in your repository, allowing for better collaboration and project management.

Setup

1. Create a bot using @BotFather.

Once all the details have been entered, you'll receive the confirmation message for your bot along with the details of the token. Copy the token key as we would be required later on. (It would be in the ##########:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx format, where # are numbers and x are alphanumeric characters)

After that, open the link of your bot in the message and press start. (There should be no response) This is to get the unique chat ID, which tells the telegram bot to notify only you.

Go to https://api.telegram.org/bot/getUpdates, and replace with the token you copied earlier. You should see a JSON response with a chat ID. Copy the chat ID.

2. Create Secret Variables

Go to your repository Settings > Secrets and variables and add the following environment variables:

  • TELEGRAM_TO: The chat ID of the user to notify.
  • TELEGRAM_TOKEN: The token of the bot created in the previous step.

image

3. Create a workflow

Create a .github/workflows/telegram-notify.yml file in your GitHub repo and add the following code:

name: Telegram Notification
on:
  push:
    branches:
      - main
      - develop
  pull_request:
    branches:
      - main
      - develop
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Send message to Telegram
        uses: appleboy/telegram-action@master
        with:
          to: ${{ secrets.TELEGRAM_TO }}
          token: ${{ secrets.TELEGRAM_TOKEN }}
          message: |  #https://help.github.com/en/actions/reference/contexts-and-expression-syntax-for-github-actions#github-context
            ${{ github.event_name }} commit in ${{ github.repository }} by "${{ github.actor }}". [${{github.sha}}@${{ github.ref }}]

Visit https://help.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions for more available environment variables.

You can also check my workflow for reference.

4. Push a commit to your repo

git add .
git commit -m "add telegram notification"
git push origin main

5. Check the action tab

image

6. Check the telegram message

image