Skip to content

Bot for Telegram to create sticker sets/packs with aiogram

License

Notifications You must be signed in to change notification settings

RoLO0u/sticker-bot

Repository files navigation

Sticker packs telegram bot

GitHub GitHub last commit GitHub code size in bytes Python Version GitHub watchers

Try it right now!

@paces_bot

Installation

Bot simply can be installed by running code on machine using required variables in .env file

If you're using webhooks, you should set up reverse proxy. You can start with aiogram documentation or read tutorial on webhooks (the tutorial is in ukrainian🇺🇦). Both use nginx and tutorial uses certbot.

Installation guide step by step

  1. Requirements
  1. Clone project
git clone https://github.com/RoLO0u/sticker-bot.git
  1. Install python requirements
pip install -r requirements.txt

⚠️ when having problems installing psycopg2: try running

on debian:

sudo apt-get install libpq-dev

on arch:

sudo pacman -Sy postgresql-libs

source

on Amazon Linux:

sudo yum -y install gcc python-setuptools python-devel postgresql-devel

source

  1. Set environment variables

Environment variables can be seen in Required variables part or in .env.example file

  1. Run programm

To run programm use simple command depending on your configuration:

python main.py

If you want to save logs in main.log, you can use --log-file arg

python main.py --log-file

Or use virtual environment variables AND docker

Required variables

Database configuration

  • DB - db name, which will be used for bot to store users info.

In current version either "mongodb" or "postgresql"

If you're using mongodb

  • MONGO_URI ─ uri to your mongo database

⚠️ mongodb isn't being tested: try on your own risk

If you're using postgresql

  • PGDATABASE - database information will be stored in. e.g. aiogram, to create use
CREATE DATABASE aiogram; -- or another database name
  • PGHOST - your address to the postgresql. On local machines should be 127.0.0.1
  • PGPORT - port to your postgresql server. Most likely 5432
  • PGUSER - user who will be used to execute commands with (e.g. postgres).
  • PGPASSWORD - password to user

Telegram bot configuration

  • BOT_TOKEN ─ token bot will use to interact with telegram API

Use @BotFather to get bot token

Long polling

  • Just setting DEBUG to True allows the bot to use long polling

Additionally, this mode shows DEBUG level of logs

Webhook

  • Setting DEBUG to False tells the bot to use webhooks

Additionally, this mode shows WARNING level of logs

  • WEBHOOK_SECRET ─ a string of random characters
  • BASE_WEBHOOK_URL ─ an URL to which telegram will send updates to

If you're using self-signed certificate you should add certificate file to set_webhook method in launch.py file

  • WEBHOOK_SSL_CERT ─ path to your public sertificate
  • WEBHOOK_SSL_PRIV ─ path to your private/secret sertificate

Make sure your user can read the file, otherwise the PermissionError will be raised

If you're encountering issues, read aiogram documentation or official telegram documentation

Migration, database testing, updating

Run db_cli.py script to execute sql from "sql_queries" folder.

When using choose script to execute by entering its number or quit by entering "q"

Resources