HTTP proxy for sending messages to Telegram group chats
As you probably know, Telegram
was blocked by Russian authorities a while ago, meaning one cannot access https://api.telegram.org
from within Russia.
The solution is to run a proxy outside of Russia or use VPN. In fact, there are many proxies out there (primarily SOCKS). Their main disadvantage is these proxies come and go, and you simply don't have control over this process. If you need a stable connection, you would eventually run your own server.
This simple HTTP
proxy can be run on any cloud provider e.g. Heroku (free 🍺).
Its primary use-case is sending build success
and failure
notifications from CI (e.g. Jenkins) to a group chat. It can also send messages to individual users. Just that, no more no less 👌.
- Written in Go ❤️
- Lightweight static binary: ~2.3 MB zipped
- Cloud-native friendly: Docker + k8s
- Secure: Basic authentication (optional)
You simply run telega
server with two env. variables: $BOT_TOKEN
and $CHAT_ID
.
You get the BOT_TOKEN
while creating your bot via @BotFather
.
CHAT_ID
is the id of the group (or user) you want to send messages to.
After this, fire a POST
request to /send
and provide a simple json:
{ "text": "Hello world!!!" }
$ go test
$ go build -ldflags="-s -w"
$ go build -ldflags="-s -w" && upx telega
- Without authentication:
$ export BOT_TOKEN=1234567890abcdef
$ export CHAT_ID=-12345
$ ./telega
Starting server on port 8080 ...
$ curl -s -X POST localhost:8080/send --data "{\"text\": \"Hello world\"}"
$ http POST :8080/send <<< '{"text": "Hi folks!"}'
$ wget -q -O- --post-data="{\"text\":\"Yo, guys\"}" localhost:8080/send
- With Basic authentication:
$ export BOT_TOKEN=1234567890abcdef
$ export CHAT_ID=-12345
$ export USERNAME=maslick
$ export PASSWORD=12345
$ export PORT=4000
$ ./telega
Starting server on port 4000 ...
$ curl -s -H "Authorization: Basic bWFzbGljazoxMjM0NQ==" -X POST localhost:4000/send --data "{\"text\": \"Hello world\"}"
$ http -a maslick:12345 POST :4000/send <<< '{"text": "Hi folks!"}'
$ wget --header="Authorization: Basic bWFzbGljazoxMjM0NQ==" -q -O- --post-data="{\"text\":\"Yo, guys\"}" localhost:4000/send
$ docker build -t maslick/telega .
$ docker run -d \
-e BOT_TOKEN=1234567890abcdef \
-e CHAT_ID=-12345 \
-p 8081:8080 \
maslick/telega
$ docker run -d \
-e BOT_TOKEN=1234567890abcdef \
-e CHAT_ID=-12345 \
-e USERNAME=maslick \
-e PASSWORD=12345 \
-p 8082:8080 \
maslick/telega
$ http POST `docker-machine ip default`:8081/send <<< '{"text": "Hi folks!"}'
$ http -a maslick:12345 POST `docker-machine ip default`:8082/send <<< '{"text": "Hi folks!"}'
$ kubectl apply -f k8s
$ kubectl set env deploy telega \
BOT_TOKEN=1234567890abcdef \
CHAT_ID=-12345 \
USERNAME=maslick \
PASSWORD=12345
$ git clone https://github.com/maslick/telega.git
$ cd telega
$ export HEROKU_APP_NAME=hello-world-app
$ heroku login
$ heroku create $HEROKU_APP_NAME
$ git push heroku master
$ heroku config:set BOT_TOKEN=$BOT_TOKEN
$ heroku config:set CHAT_ID=$CHAT_ID
$ heroku config:set USERNAME=$USERNAME
$ heroku config:set PASSWORD=$PASSWORD
$ open https://$HEROKU_APP_NAME.herokuapp.com/health