Telegram Notification Server

This Golang application serves as a Telegram bot server that allows users to subscribe and receive messages sent through different endpoints. The server leverages the Gin web framework for handling HTTP requests, and the Telegram Bot API for interacting with Telegram.

Features

Dependencies

Configuration

Configuration is done through a TOML file specified by the -conf flag (default: config.toml). The configuration file contains the following fields:

Database path is specified by the -db flag (default: subscriptions.db).

Example config.toml:

telegram_token = "your-telegram-bot-token"
telegram_api_url = "https://api.telegram.org/bot%s/%s"
gin_address = ":8080"
post_url = "http://example.com"

Usage

  1. Compile and run the server.
  2. Interact with the Telegram bot to subscribe and receive a UUID and AES key.
  3. Use the provided endpoints to send messages or files to the subscribed Telegram user.

The following endpoints are available for interacting with the server:

For channel, you need to add the bot as admin, then forward a channel message to the bot. Then, a inline keyboard will show, follow the keyboard.

For group, you need to add the bot as admin, too.

Building

To build the project, ensure you have Go installed and run:

go mod download
go build

This will generate an executable file in the project directory.

Running

cp confg.example.toml config.toml

Modify the config.toml and put your configurations.

./server -conf config.toml -db subscriptions.db

Using Docker

We provide a Dockerfile to run application, you can use with prebuilt docker nerdneils/simple-telegram-notification-bot:latest .

docker run -it --rm -p 7888:7888 -v ${PWD}/config.toml:/etc/notification-bot/config.toml -v ${PWD}/data:/data nerdneils/simple-telegram-notification-bot:latest  ./server -conf /etc/notification-bot/config.toml -db /data/notification-bot.db

You can also use the docker-compose to deoply your application, we provide a example docker-compose.yml, which use Traefik as the API proxy:

version: '3.3'

networks:
  proxy:
    external: true

services:
  notification-bot:
    image: nerdneils/simple-telegram-notification-bot:latest
    networks:
      - proxy
    command: ./server -conf /etc/notification-bot/config.toml -db /data/notification-bot.db
    volumes:
      - ./config.toml:/etc/notification-bot/config.toml
      - ./data:/data
    labels:
      - traefik.enable=true
      - traefik.docker.network=proxy
      - "traefik.http.routers.tg-notification.entrypoints=http"
      - "traefik.http.routers.tg-notification.rule=Host(`tg-notification.example.org`)"
      - "traefik.http.middlewares.https-redirect.redirectscheme.scheme=https"
      - "traefik.http.routers.tg-notification.middlewares=https-redirect@docker"
      - traefik.http.routers.tg-notification-secure.entrypoints=https
      - "traefik.http.routers.tg-notification-secure.rule=Host(`tg-notification.example.org`)"
      - traefik.http.routers.tg-notification-secure.tls=true
      - traefik.http.routers.tg-notification-secure.tls.certresolver=cloudflare
      - "traefik.http.services.tg-notification.loadbalancer.server.port=7888"
Fork me on GitHub