Skip to content

Telegram on a self-hosted server

One Telegram bot serves every private group connected to this GitNotify instance.

Open @BotFather and follow these steps:

  1. Run /newbot, choose a display name, and choose a username ending in bot.
  2. Save the bot token.
  3. Run /setprivacy, choose the bot, and keep privacy mode Enabled.
  4. Run /setjoingroups, choose the bot, and keep group joining Enabled. GitNotify works in private groups.

Do not set the command list in BotFather. GitNotify registers its nine commands through the Bot API when it registers the webhook.

Set these variables. The username does not include @:

TELEGRAM_BOT_TOKEN=replace-with-the-bot-token
TELEGRAM_WEBHOOK_SECRET=replace-with-a-random-secret
TELEGRAM_BOT_USERNAME=your_gitnotify_bot

The webhook secret may contain letters, digits, _, and -, with at most 256 characters. A 32-byte hex value is valid:

Terminal window
openssl rand -hex 32

Apply the change with docker compose -f selfhosted/docker-compose.yml up -d gitnotify after setting the variables. Load ADMIN_TOKEN from the environment file, then call the local admin route:

Terminal window
ADMIN_TOKEN=$(grep '^ADMIN_TOKEN=' selfhosted/.env | cut -d= -f2-)
curl -fsS -X POST "http://127.0.0.1:8000/admin/telegram/webhook" \
-H "Authorization: Bearer $ADMIN_TOKEN"

The route calls setWebhook for ${PUBLIC_URL}/telegram/webhook and calls setMyCommands. A successful response is:

{"webhook":true,"commands":9}

The webhook asks Telegram to send only these update types:

  • message
  • callback_query
  • my_chat_member

The nine commands are /connect, /setup, /status, /repair, /link, /notify, /digest, /forget_me, and /help.

Read the registered webhook state with:

Terminal window
curl -fsS "http://127.0.0.1:8000/admin/telegram/webhook" \
-H "Authorization: Bearer $ADMIN_TOKEN"

The response includes the URL, pending update count, latest delivery error, and allowed updates. It does not return the bot token or webhook secret.

Create a private Telegram group and add the bot. If you want one activity topic and one deploy topic per repository, turn on Topics in the group settings and make the bot an administrator with Manage Topics. Without Topics, cards go to the group itself. Keep the group private. GitNotify refuses a group that has a public username.

GitNotify sends sign-in links only by private message, so each person who runs /connect or /link opens a private chat with the bot and presses Start once. If they have not, the bot answers in the group with a button that opens that chat. Then run /connect as a group administrator, choose repositories, and run /setup. Team members use /link for personal notifications. In a group with other bots, add your bot's username to each command, for example /connect@your_bot. The commands and setup steps are the same as on the hosted GitNotify: see Telegram.