3stadt / lajujabot

a telegram bot for twitch live notifications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

This Telegram bot sends notifications when selected Twitch streamers go live. It works both in private chats and in group chats.

How it works

We make use of python-telegram-bot & Twitch subscriptions via twitchAPI. Basically the twitchAPI library sets up a webhook which will make Twitch report go-live events to a public domain under your control. When the alert reaches your side (usually 30-60s after the streamer actually goes live), it triggers the bot into sending a message to every chat which subscribed to the related Twitch channel.

These subscriptions are persistent, meaning that the bot should automatically restore them after a crash.

What it needs

If you've already got control over a domain served with TLS 1.2+ (from standard port 443; this is a Twitch requirement), you only need to proxy the webhook traffic to this application e.g. on port 15151.

With nginx, this would mean adding to your listen 443 ssl server block something like:

location /lajujabot-webhook/ {
    proxy_pass http://127.0.0.1:15151/; }

Start the bot

# System dependencies
sudo apt install python3 python3-pip
pip3 install virtualenvwrapper

# Get things ready
git clone https://github.com/ria4/lajujabot
cd lajujabot
mkvirtualenv -p /usr/bin/python3 lajujabot

# Python dependencies
(lajujabot)$ pip3 install -r requirements.txt

Then, edit config.json with your own parameters. You may hardcode them into the configuration file.

{
    "TelegramBotToken": "$LAJUJABOT_TELEGRAMBOTTOKEN",
    "TwitchAppClientID": "$LAJUJABOT_TWITCHAPPCLIENTID",
    "TwitchAppClientSecret": "$LAJUJABOT_TWITCHAPPCLIENTSECRET",
    "CallbackURL": "$LAJUJABOT_CALLBACKURL",
    "ListeningPort": "15151",
    "PersistenceFile": "/opt/lajujabot/subscriptions.pickle",
    "LogFile": "/opt/lajujabot/error.log",
    "MaintenanceMode": "False"
}

Alternatively, you may declare environment variables. They will be transparently loaded. For instance, you could add export LAJUJABOT_CALLBACKURL='https://mydomain.tld/lajujabot-webhook/' to your .bashrc.

It's sensible to keep the persistence and log files in the bot directory, but you can get creative if you want.

The bot should be able to start now:

python3 main.py

Note that you can specify an alternative configuration file using python3 main.py -c config2.json.

TODO

  • Leverage drop_chat/user_data method when python-telegram-bot v14 is out

Credits

This bot is a rework of misterino, by Denni Bevilacqua and Antonio Vivace.

It is mostly indebted to the twitchAPI implementation by Lena 'Teekeks' During.

About

a telegram bot for twitch live notifications

License:GNU General Public License v3.0


Languages

Language:Python 100.0%