telegram-pi-bot

A python-telegram-bot setup to run on Raspberry pi


Keywords
telegram, raspberrypi, bot, python-telegram-bot, arch-linux, chat, circus, iot, python, raspberry-pi, telegram-bot
License
Other
Install
pip install telegram-pi-bot==0.2.4

Documentation

Telegram Pi Bot

About

This is my personal Telegram Bot to run on my RaspberryPi 2 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.

Features

  • Answers to only pre-configured chat rooms
  • Webhooks configured via a JSON config file
    • Configures an endpoint to call for a given command
    • Works great with IFTTT Maker channel
  • Basic multilingual support
    • en pt-br
  • Runs on Python 3

Setup

Hardware requirements

  • RaspberryPi
  • Power cable
  • MicroSD card
  • Internet connection

Installing things

This is a guide for the complete setup on ArchLinux, if you're just intested in running the script you can jump

Base system setup

Python setup

  • Install Python: sudo pacman -S python
  • Install pip: sudo pacman -S python-pip

Process management setup

Finally, bot setup

  • sudo pip install telegram-pi-bot
  • Configure a ~/circus.ini file
[circus]

[watcher:telegram-pi-bot]
cmd = telegram-pi-bot
numprocesses = 1

[env]
TELEGRAM_PI_BOT_CONFIG = /home/username/config.json

Maintenance

  • sudo pacman -Syu Updates the system

Running the bot

Config file

Telegram 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" }
        }
    ]
}

Locate config file

The config file will try to be loaded from:

  • A location specified using the TELEGRAM_PI_BOT_CONFIG environment variable

or

  • A config.json file placed in the same folder as the main.py script

Using Circus

For improved process handling:

  • systemctl start circus
  • systemctl stop circus
  • systemctl reload circus

Autostart on device boot:

  • systemctl enable circus

Script

Clone this repo, then cd into its folder.

To just simply run as a Python script, just make sure your config.json file is accessible as previously explained, then just run:

python telegram_pi_bot

License

MIT © Ruy Adorno