Skip to content

Sending message in Telegram chat when release drafted or published

License

Notifications You must be signed in to change notification settings

Ivan-Feofanov/github-release-bot

Repository files navigation

github-release-bot

lint-and-test

Getting started

Create telegram bot:

Just follow instruction

Fill environment variables:

.env file example:

ENVIRONMENT=production
TOKEN=your_bot_token
PROXY_URL=socks5:https://socks5_proxy_url:socks5_proxy_port
PROXY_USERNAME=socks5_proxy_username
PROXY_PASSWORD=socks5_proxy_url
SECRET_TOKEN=you_secret_token

If you don't need proxy just ignore proxy settings.
If you set ENVIRONMENT value not eqal to "production" bot will ignore security settings.

You can generate strong token with terminal command:

openssl rand -hex 32
Start your bot:
docker run --env-file .env -p 80:80 --name release-bot feofanov/github-release-bot

Release webhook example:

Create your bot url:
bot_url = https://where_you_bot.live/release/ + ?chat_id=you_chat_id&release_only=true
Set query param release_only in true if you don't want getting unpublished, created, edited, deleted, or prereleased events.

Chat id

First you should invite your bot in chat and then you can find your chat id in your bot api:
https://api.telegram.org/bot<you_bot_token>>/getUpdates

Github settings
  • Open you github project settings and find Webhook section
  • Add new webhook with params:
    • Payload URL = your bot url
    • Content type = application/json
    • Secret = you_secret_token
  • Choose Let me select individual events
  • Unselect Pushes and select Releases
  • Press Add webhook

Congratulations, you're perfect!

Release description example:

Since telegram can understand only part of markdown tags, bot tries to convert standard markdown into tg-markdowned message.
Right now bot can correctly format next tags:

  • header (###) (only three octothorps)
  • list (*)
  • link([link name](https://link.address)) Correct description example:
### Release part subtitle
* [first point title](https://link-tod-escriot.ion/)
* [second point title](https://link-tod-escriot.ion/)

Custom message

You also can send any custom messages via bot using POST-endpoint '/message/' This endpoint accepts next params:

{
  "text": "any string you wanna send to bot",
  "chat_id": "your chat id",
  "parse_mode": "markdown|html"
}

Custom message hook usage example:

#!/bin/bash
PROJECT_NAME="my-project-name"
GIT_TAG=$(git describe --tags --abbrev=0)
HOST="https://example.com"
PORT="80"
CHAT_ID="my_chat_id"
KEY="my_secret_key"

PAYLOAD=\
"{
    \"text\":\"Project *$PROJECT_NAME* was succefully deployed with tag *$GIT_TAG*\",
    \"chat_id\": \"$CHAT_ID\",
    \"parse_mode\": \"markdown\"
}"

SIGN="sha1="$(echo -n "$PAYLOAD" | openssl sha1 -hmac $KEY | sed -e 's/^.* //')

ADDRESS="${HOST}:${PORT}/message/"
curl -X POST $ADDRESS -H "X-Hub-Signature: $SIGN" -d "$PAYLOAD"

About

Sending message in Telegram chat when release drafted or published

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published