Telegram on a self-hosted server
One Telegram bot serves every private group connected to this GitNotify instance.
Create the bot
Section titled “Create the bot”Open @BotFather and follow these steps:
- Run
/newbot, choose a display name, and choose a username ending inbot. - Save the bot token.
- Run
/setprivacy, choose the bot, and keep privacy mode Enabled. - 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-tokenTELEGRAM_WEBHOOK_SECRET=replace-with-a-random-secretTELEGRAM_BOT_USERNAME=your_gitnotify_botThe webhook secret may contain letters, digits, _, and -, with at most 256 characters. A 32-byte hex value is valid:
openssl rand -hex 32Register the webhook and commands
Section titled “Register the webhook and commands”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:
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:
messagecallback_querymy_chat_member
The nine commands are /connect, /setup, /status, /repair, /link, /notify, /digest, /forget_me, and /help.
Read the registered webhook state with:
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.
Add the bot to a group
Section titled “Add the bot to a group”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.