labnotes

Telegram Build Bot

Easier notifications

tags
github
telegram

Create the bot

Go to the botfather and create a bot.

/newbot

I named mine "the focus build bot" and "thefocus_build_bot"

Save the secret somewhere careful. In TELEGRAM_BOT_TOKEN say.

Get a chat id

Send a message in your bot’s chat:

  1. In Telegram, search for your newly created bot by its username (the one ending in “bot”).
  2. Press Start to initiate the chat.
  3. Send a short message, like “Hello.”

Then go to https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates in your browser. You should be able to see the chat id there.

Save it in TELEGRAM_CHAT_ID

Send a test message from your machine

1
2
3
4
5
  export TELEGRAM_BOT_TOKEN="$(op read "op://Development/Focus Bot Secret/notesPlain")"
  export TELEGRAM_CHAT_ID="$(op read "op://Development/Focus Bot Chat Id/notesPlain")"
  curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
        -d chat_id="${TELEGRAM_CHAT_ID}" \
        -d text="❌ BOOM ❌" | jq .
{
  "ok": true,
  "result": {
    "message_id": 6,
    "from": {
      "id": 8073526226,
      "is_bot": true,
      "first_name": "Focus Build Bot",
      "username": "thefocus_build_bot"
    },
    "chat": {
      "id": 5920486792,
      "first_name": "Will",
      "last_name": "Schenk",
      "type": "private"
    },
    "date": 1741645616,
    "text": "❌ BOOM ❌"
  }
}

Add the secrets to your repository

1
2
3
4
5
  export TELEGRAM_BOT_TOKEN="$(op read "op://Development/Focus Bot Secret/notesPlain")"
  export TELEGRAM_CHAT_ID="$(op read "op://Development/Focus Bot Chat Id/notesPlain")"

  gh secret set TELEGRAM_BOT_TOKEN --body "${TELEGRAM_BOT_TOKEN}"
  gh secret set TELEGRAM_CHAT_ID --body "${TELEGRAM_CHAT_ID}"

And you can to go

1
  gh browse

Settings > Secrets and Variables > Actions to see if they are there.

Adding to the github action

Inside of whatever your github action is, put this at the end of the build set.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
    - name: Send Telegram Success
      if: success()
      run: |
        curl -s -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" \
        -d chat_id="${{ secrets.TELEGRAM_CHAT_ID }}" \
        -d text="✅ Build succeeded for ${{ github.repository }}!"

    - name: Send Telegram Failure
      if: failure()
      run: |
        curl -s -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" \
        -d chat_id="${{ secrets.TELEGRAM_CHAT_ID }}" \
        -d text="❌ Build failed for ${{ github.repository }}!"

Deploy and enjoy

Push and see that alert come in!

Previously

fragments

Mistral AI is Le French

tags