Skip to content
On this page

Self-building Guide

Requirements:

  • A domain name
  • A server that can access Telegram
  • Basic knowledge of Linux

Create a Telegram Bot

Click @BotFather and follow the steps to create your own Bot and obtain the Token.

Create a sqlite3 Database

Go to the directory where the database file will be stored.

bash
cd /opt

Create a database named pushbot.db

bash
sqlite3 pushbot.db

Create a database table

bash
sqlite> CREATE TABLE users (chatId int unique, chatToken text unique);

Exit the database command line

bash
sqlite> .quit

Deploy using Docker

Replace the content of <TOKEN>, <DOMAIN>, and the database path.

docker-compose

yaml
version: '3.7'
services:
  pushbot:
    image: pupilcc/pushbot
    container_name: pushbot
    restart: unless-stopped
    volumes:
      # Path of the created database
      - /opt/pushbot.db:/app/pushbot/pushbot.db
    ports:
      - "25701:25701"
    environment:
      # Bot Token
      - BOT_TOKEN=<TOKEN>
      # Your domain
      - BOT_DOMAIN=<DOMAIN>

docker run

bash
docker run -d \
    --name pushbot \
    --restart unless-stopped \
    -p 25701:25701 \
    -e BOT_TOKEN=<TOKEN> \
    -e BOT_DOMAIN=<DOMAIN> \
    -v /opt/pushbot.db:/app/pushbot/pushbot.db \
    pupilcc/pushbot

Use Nginx as Reverse Proxy

Add reverse proxy at port 443 in the nginx configuration file corresponding to the domain.

# Reverse proxy Docker specified port
location / {
    proxy_pass         http://127.0.0.1:25701;
    proxy_set_header   Host             $host;
    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
}

Set WebHook

Replace {botToken} with your Bot Token and {domian} with your own domain in the following link. After replacing, visit the link in your browser.

https://api.telegram.org/bot{botToken}/setWebhook?url={domain}/webhook/{botToken}

If you receive the following message, it means the setting is successful, and you can enjoy it.

json
{
  "ok": true,
  "result": true,
  "description": "Webhook was set"
}