A telegram bot to generate random stuff, I built this to chat with my friend randomly. Using pyTelegramBotAPI for talking with telegram server. The project structure is inspired by classic MVC web frameworks..
Install system dependencies:
ffmpeg
(for converting media),
nginx
(optional, for hosting static resources & proxy)
# this is an example for debian-based distros
sudo apt-get install ffmpeg
# optional but highly recommanded
sudo apt-get install nginx
Use pip to install dependencies in requirements.txt
python3 -m pip install -r requirements.txt
The bot uses webhook in production environment, you will need a server reachable for telegram server and has https
support (unless you want to use infinity polling...)
Here we go !!!!
This repo includes a config example .env.toml
.
Copy the example config and change it to meet your own environment:
# copy the config example, don't forget to change it
cp .env.toml env.toml
in env.toml
:
[bot]
token = "" # your token here
name = "" # your bot name, for webhook uri
environment = "prod" # "prod" for production environment
[server]
host = "example.com" # set your own
port = 8443
listen = "0.0.0.0"
[webhook]
host = ""
port = 443
[ssl]
cert = "/path/to/fullchain.pem"
priv = "/path/to/priv.pem"
run pytest
&& check if every test passes
python3 -m pytest
Static resources are hosted in public/
and the bot-generated contents are under storage/
, use link_storage.sh
to create a symlic:
./link_storage.sh
# to remove it:
# ./link_storage.sh remove
copy and change the config file to configure Nginx:
cp example.conf /etc/nginx/sites-available/example.com
# don't forget to change it !!
ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled
add map
block in nginx.conf
into your system nginx.conf
's http
block
http {
# other stuff ...
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
}
restart nginx.service
In the project directory, run python3
python3 bot.py
if you don't have https: telegram only allow webhooks with https, but you can still use
polling
: inenv.toml
,setbot.environment
to"dev"
:
[bot]
environment = "dev"
now you can run it !
(&%&^&(&%^(&)))