A python-telegram-bot setup to run on Raspberry pi
MIT License
This is my personal Telegram Bot to run on my RaspberryPi at home. It's supposed to be a proxy and an easy interface for all the home automation paraphernalia that we might end up getting in the future.
The bot can also be used in any system that has Python 3 support but the setup instructions provided are focused on getting it to work on the ARM architecture running on ArchLinux.
en
pt-br
This is a guide for the complete setup on ArchLinux, if you're just intested in running the script you can jump to Process management setup.
Remember to replace occurrences of username with your own user name.
A more complete step-by-step guide on how to set up ArchLinux on a RaspberryPi Zero is available here: https://gist.github.com/ruyadorno/08a04f5fcb37204767ce0942c9df8f91
systemctl enable iptables
sudo pacman -S python
sudo pacman -S python-pip
sudo pacman -S gcc
sudo pacman -S python-setuptools
sudo pip install circus
sudo pip install telegram-pi-bot
telegram-pi-bot /home/username/config.json
/home/username/circus.ini
file:[circus]
[watcher:telegram-pi-bot]
cmd = telegram-pi-bot /home/username/config.json
numprocesses = 1
/etc/systemd/system/circus.service
file for autoload on boot:[Unit]
Description=Circus process manager
After=syslog.target network.target nss-lookup.target
[Service]
Type=simple
ExecReload=/usr/bin/circusctl reload
ExecStart=/usr/bin/circusd /home/username/circus.ini
Restart=always
RestartSec=5
[Install]
WantedBy=default.target
systemctl --system daemon-reload
systemctl start circus
systemctl enable circus
sudo pacman -Syu
Updates the systemTelegram Pi Bot is configured through a json
file, in which you can set your bot token and configure webhooks/commands to invoke from your bot.
Here is an example of what a config.json
file looks like:
{
"bot_token": "<insert bot token>",
"chat_ids": [
"<insert chat id in which the bot should respond to>"
],
"language": "<bot language>",
"webhooks": [
{
"command_name": "dosomething",
"url": "https://example.com/dosomething",
"method": "POST",
"headers": {
"Content-Type": "application/json"
},
"data": { "value1": "%s" }
}
]
}
The config file will try to be loaded in the following order:
telegram-pi-bot /home/username/config.json
TELEGRAM_PI_BOT_CONFIG
environment variable:export TELEGRAM_PI_BOT_CONFIG=/home/username/config.json
config.json
placed inside the telegram_pi_bot
folderFor improved process handling:
systemctl start circus
systemctl stop circus
systemctl reload circus
Autostart on device boot:
systemctl enable circus
MIT © Ruy Adorno