Skip to content

avivace/misterino

Repository files navigation

misterino

Developed by Denni Bevilacqua and Antonio Vivace.

Telegram bot notifying when your favorite streamers go live on Twitch.tv. Users can subscribe to Twitch streamers and receive a message when they go online (privately or in a group).

The telegram bot can function in polling or in webhook mode. Those modes are idem-potent and you should see the same results and behaviours.

Stack

We make use of

Webhook mode

The bot was developed to operate in webhook mode (this is also why it may seem over-engineered). Please understand that this requires additional work and maintenance. You need:

  • A public IP address and/or domain;
  • A SSL certificate;
  • A webhook listener;
  • A reverse proxy exposing the webhook listener, handling TLS1.0+ HTTPS-traffic.

We don't use the python-telegram-bot integrated webserver, but we listen for webhooks with Flask, then we dispatch the de-jsonified (is this even a word?) payloads to another thread, using a shared Queue.

During development, we use the polling mode to get the payload from messages sent to the bot, then pipe them to webhookTest.sh to simulate the Telegram server sending webhook to our listener.

FYI the Twitch events are received anyway listening for webhooks, the mode setting changes only the telegram bot operating mode. You don't need all the mentioned things for Twitch because it doesn't require an https enabled endpoint: as long as you have DMZ/open ports you are able to set your own IP as callback for the webhook subscriptions.

Get started

# System dependencies
apt install python3 python3-pip

# Get things ready
git clone git@github.com:avivace/misterino.git
cd misterino
python3 -m venv .
source bin/activate

# Python dependencies
pip3 install -r requirements.txt

You need a Telegram bot token (use BotFather), a Twitch Client ID and a Twitch Client Secret (register an application on the Twitch dev portal).

Create a config.json with the mentioned values:

{
    "mode": "polling",
    "botToken": "TELGRAM_BOT_TOKEN",
    "TwitchAppClientID": "TWITCH_APP_CLIENT_ID",
    "TwitchAppClientSecret": "TWITCH_APP_CLIENT_SECRET"
}

Start the bot

python3 main.py

If the script can't find config.json, it'll create a default one for you.

You can specify the configuration file to use using python3 main.py -c config2.json.

Bot is up and running, talk to it on Telegram.