DEV Community

Cover image for Get notified via telegram when pull request is raised
Nikhil Vemula
Nikhil Vemula

Posted on

Get notified via telegram when pull request is raised

Telegram is cool messaging platform with lot of developer friendly capabilities. I wondered if i could get a notification whenever a pull request is raised to my GitHub public repository.

Leveraging git hub actions

GitHub Actions can be used to do all sorts of automation on your GitHub repositories.

Quickly doing some google search found an action which I can use to send telegram notifications when ever a pull request is raised.

Create new a GitHub workflow

  • Under your repository home page, create a new workflow
  • Select the simple workflow later we can modify this accordingly

New GitHub Workflow

# This is a basic workflow to help you get started with Actions

name: Telegram notification

# Controls when the action will run. Triggers the workflow on pull request
on:
  pull_request:
    branches: [ develop ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2

      # Runs the telegram notify action to send a notification
      - name: Telegram Notify
        uses: appleboy/telegram-action@master
        with:
          to: ${{ secrets.TELEGRAM_TO }}
          token: ${{ secrets.TELEGRAM_TOKEN }}
          format: markdown
          message: |
            A new PR is raised [View all PR's](https://github.com/<user>/<repo>/pulls)
Enter fullscreen mode Exit fullscreen mode

Getting the telegram bot token and group unique id

  • Use Telegram Bot Father to create a new bot.
  • When a bot is created it returns token, save it.
  • Create a telegram group and add this bot to the group.
  • Add a test message to this group.
  • To get a unique id of the group.

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

  • Find the group unique id under chat.id

Create the necessary secrets required for the workflow

  • Go to settings under repository
  • Under secrets
  • Create a new secret called TELEGRAM_TOKEN with the token value from above.
  • Create a new secret called TELEGRAM_TO with unique id of the group.

Yipeyy!! When a pull request is raised a notification is sent to the group.

GitHub logo appleboy / telegram-action

GitHub Action that sends a Telegram message.

Top comments (2)

Collapse
 
mohammedaijaaz profile image
MohammedAijaaz

Great article!

Collapse
 
hilmaulanaa profile image
Hilman Maulana

thanks for this article