Telegram bot that sends real-time notifications from Twitch with changes on streamers' channels. Telegram users can subscribe to their own list of streamers.
- Bot URL: t.me/twitchoba_bot
If you want to have no limits and have faster delivery you can run it locally or deploy to your own server
git clone https://github.com/swol1/twitch_telegram_bot.git
cd twitch_telegram_bot
- I want to run locally:
cp .env.local.template .env.local
- I want to deploy:
cp .env.template .env
Then fill in environment variables inside the .env.local or .env file.
You can use any token, for example:
openssl rand -hex 32
Generate tokens for:
TWITCH_MESSAGE_SECRET
TELEGRAM_SECRET_TOKEN
Generate secret values for database encryption (can be omitted):
DB_ENCRYPTION_PRIMARY_KEY
DB_ENCRYPTION_DETERMINISTIC_KEY
DB_ENCRYPTION_KEY_DERIVATION_SALT
-
Create a Twitch application at Twitch Developers Console and fill in the environment variables:
TWITCH_CLIENT_ID
TWITCH_CLIENT_SECRET
-
Create your bot using BotFather on Telegram and fill in:
TELEGRAM_TOKEN
For example, you can use ngrok:
- Create an account at ngrok and obtain your public URL.
- Fill in the environment variable:
PUBLIC_API_URL=https://1111-11-111-111-111.ngrok-free.app
- Start the web service:
bundle exec puma
- Start the Redis server:
redis-server
- Start the background jobs:
bundle exec sidekiq -r ./config/environment.rb
I used Kamal because I wanted to try it. I can't really recommend it mainly because random bugs occur. However, if you configure it properly, it can be quite convenient. Follow these steps to prepare for deployment:
KAMAL_REGISTRY_USER=your_docker_registry_login
KAMAL_REGISTRY_PASSWORD=your_docker_registry_password
PUBLIC_API_URL=https://example.com
HOST_IP=11.111.11.111
REDIS_PASSWORD=password
REDIS_URL=redis://:password@service-redis:6379/0
- Copy the deploy sample configuration:
cp config/deploy.sample.yml config/deploy.yml
- Fill in the configuration file (
config/deploy.yml
) with your own data.
Follow Kamal's Documentation for detailed deployment instructions
- Setup Let's Encrypt
mkdir -p /letsencrypt && touch /letsencrypt/acme.json && chmod 600 /letsencrypt/acme.json
- Create a directory for your database:
mkdir /db
chown 1000:1000 /db
- Create a Docker network for your services:
docker network create -d bridge private
- Deploy:
On first run:
kamal setup
On subsequent runs:
kamal deploy
Replace <TELEGRAM_TOKEN>
, <PUBLIC_URL>
, and <TELEGRAM_SECRET_TOKEN>
with your actual values:
curl -X POST "https://api.telegram.org/bot<TELEGRAM_TOKEN>/setWebhook?url=<PUBLIC_URL>/telegram/webhook&secret_token=<TELEGRAM_SECRET_TOKEN>"
Example:
curl -X POST "https://api.telegram.org/bot123456VERY-SECRET-TOKEN/setWebhook?url=https://1111-11-111-111-111.ngrok-free.app/telegram/webhook&secret_token=my_secret_token"
You can receive sentry reports by providing <SENTRY_DSN>
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request.