I wrote a telegram bot in rust - a brief story and bot description
Hi!
I'm in the process of learning rust, and since I'm the kind of person that learns by doing I've started creating different projects.
My first project was bacup - an easy-to-use backup tool designed for servers.
My second project is RaF - a bot for creating referral-based contests for your Telegram channels, groups, and supergroups.
This has been the first time I had the need to work with a fork of a rust project. In fact, I started creating RaF depending upon telexide but the project was abandoned and it was lacking certain features I needed (and it has some bugs too - I created a pull request but it has been completely ignored :( ).
So, I forked it, and thanks to the flexibility of Cargo I've been able to work depending on the git repository.
I learned only at the end - when I decided to publish RaF on crates.io - that it wasn't possible to publish a crate that was depending on a git repository - because it has no fixed version, potentially. So I also had to publish the crate of the fork (I don't know if there's a cleaner way, but it seems the only way for doing it), and rename all the modules and dependencies (originally I was depending on telexide while using my fork from git, and I had to rename everything to telexide_fork when I started depending on the published crate).
Overall developing the bot has been easy, the language itself was just a different tool (I wrote other bots in Python and Go). The main difficulty was the creation of a state machine that handles contest management. The state machine creation was forced by how telexide works - I guess I could have used another library to create a well-defined and better-designed state machine, but I found it difficult to integrate any state machine library with the telexide structure (everything should be handled in a single "callback handler").
For the persistence layer I used Rusqlite and r2d2-sqlite for creating a connection pool.
All these libraries, I have to say it, work extremely well. Perhaps it's the language, or perhaps I've been lucky, but I've just been able to integrate them all without any effort and everything worked fine on the first try.
RaF is a telegram bot designed for channels and group owners, that gives the possibility of registering a channel/group to RaF and use RaF to create contests based on the referral strategy.
The bot posts on the channel/group a message with a link that starts RaF and identified the channel/group and the contest.
Every user can - by following that link - generate its own link that identifies the user that's referring, the channel, and the contest. This is the link to share to refer to the channel and climb the leaderboard. When the contest ends, the user that referred most (real) users will be contacted by the channel/group admin and it will get a price (every contest has a price).
Here's a running instance: https://t.me/RefafBot
Here's the code: https://github.com/galeone/raf
I used clippy as a helper for writing idiomatic rust-code, but I guess if someone more experienced does a code review it would be a better way to improve.
Moreover, if you find RaF a good idea and you want to contribute I'd be happy to talk about the features.
Thanks for reading!