Code Monkey home page Code Monkey logo

telega's Introduction

=telega=

HTTP proxy for sending messages to Telegram group chats

Build Status Dockerhub License: MIT

Motivation

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 ๐Ÿ‘Œ.

Features

  • Written in Go โค๏ธ
  • Lightweight static binary: ~2.3 MB zipped
  • Cloud-native friendly: Docker + k8s
  • Secure: Basic authentication (optional)

How it works

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!!!" }

Installation

$ go test
$ go build -ldflags="-s -w"

$ go build -ldflags="-s -w" && upx telega

Usage

  • 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

$ 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!"}'

Kubernetes

$ kubectl apply -f k8s
$ kubectl set env deploy telega \
   BOT_TOKEN=1234567890abcdef \
   CHAT_ID=-12345 \
   USERNAME=maslick \
   PASSWORD=12345

Heroku

$ 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

telega's People

Contributors

maslick avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.