Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Latest commit

 

History

History
72 lines (45 loc) · 5.05 KB

readme.md

File metadata and controls

72 lines (45 loc) · 5.05 KB

uva-stalker Telegram logo UVa logo

License GitHub release

uva-stalker is a Telgram bot to stalk submissions from UVa Online Judge users.

You simply tell it which users you want to follow, and it will send you notifications every time a user makes a new submission.

An instance of the bot is already running and can be interacted with by chatting to UVaStalkerBot, or you can clone this repo and set up the bot in your own server.

NOTE: Due to decreased usage of the bot (no new users in 2021) and decreasing popularity of https://onlinejudge.org/ (no new problems, unmaintained website functionality...), the bot has been shut down on January 1, 2022. The code still works and you may set it up in a new Telegram bot account if you wish.

UVaStalker screenshot 1 UVaStalker screenshot 2

Installation

Follow these instructions to set up the bot in a development environment and test that it works correctly. You can then deploy it to a server.

Creating your own Telegram bot

Chat with BotFather to generate an authorization token for your new bot. Head over to the Telegram documentation for detailed instructions if you're new to creating bots.

Local installation

uva-stalker uses the telegram-bot-sdk library in a Laravel environment using a (tested in Postgres) database.

After cloning the repo and installing dependencies with composer install, you may configure the database credentials in the project folder in a .env file, as well as your APP_KEY (or use php artisan key:generate to fill it in). You must also fill in the variable TELEGRAM_BOT_TOKEN with your authorization token. This project comes with (optional) minimal Bugsnag error reporting, which you may enable by filling in the BUGSNAG_API_KEY and BUGSNAG_APP_VERSION variables. When you're done with the .env file, install the migrations and execute them to build the database tables.

$ cp .env.example .env
$ nano .env # (edit variables)
$ php artisan migrate:install
$ php artisan migrate

The bot needs to be able to write to Laravel's public disk in order to store the PDFs from UVa OJ. The PDFs will be downloaded whenever a UVa OJ user tracked by the bot solves a problem, and immediately deleted after informing all bot users that stalk that UVa OJ user. By default, the public disk uses the local driver and stores these files in storage/app/public. You should create a symbolic link from public/storage to storage/app/public. To create the symbolic link, you may use php artisan storage:link.

Finally, run daemon.php to listen for messages sent to your bot. This script uses long-polling to request updates with curl every second from the Telegram Bot Api using the getUpdates method. It will forward the payloads to the Laravel application, which will process them under the /api/<authorization_token route, where <authorization_token> is the authorization token which BotFather provided you when you created your bot.

$ php daemon.php
Starting bot with config {"id":356029581,"first_name":"UVaStalker","username":"UVaStalkerBot"}

Start polling Telegram api (will poll for updates every 1000 ms)

Poll took 0 ms (slept 1000000 µs)
Poll took 0 ms (slept 1000000 µs)
...

Any incoming updates will be printed to the console.

Deployment to a server

If the bot works normally using long polling, you may want to deploy it to a server and set a webhook so that incoming updates are pushed to you. By default, the Laravel application is listening for updates on /api/<authorization_token, so you should set up the webhook at

https://your-domain-name.com/api/<authorization_token>

Note that you need a domain name with a valid SSL certificate in order to set up the webhook.

If you have a domain name but you don't have a valid SSL certificate, a very easy way to get one is from Let's Encrypt, and install it on a Caddy web server. Don't forget to update the APP_URL environment variable to https://your-domain-name.

All that's left to do is set up your webhook. You may do so using the setWebhook() method of the Bot Api. Telegram has a fantastic guide on webhooks for detailed instructions.