Botlib: C Telegram bot framework
github.com
github.com
This code started as the Telegram bot Stonky, it's on Github, and you'll see the bot does a lot of financial analysis things, including Montecarlo simulations. I really needed the speed. Later my daughter was diagnosed with scoliosis, and requires to wear a corset. To take track of the time she wears it was a pita, so I wrote another bot (not released so far) and put it in our family channel.
Then... I needed another bot. And I finally extracted the common parts from the two. So:
1. For Stonky, speed was essential, but not for my next bot.
2. Once I needed to write the new bot for the corset I tried the Python lib. And... I started to have the first code compatibility issues (accross versions) of the modern software stack (context here: https://twitter.com/antirez/status/1726305869032570992).
3. Meanwhile Stocky was no longer able to work because I did the unescapable error of basing it on the Yahoo Finance API, now retired :( So I told myself, I don't want to relay on a software stack that will make this bot unable to work or obsolete in 2/3 years because all the libraries will change fast (and, if you check, you will see there was a lot of work that went into Stonky back in the couple of weeks when I worked at it constantly).
On top of that, with Stonky I decided to serve each request with a thread, and not in multiplexing. In the specific case of a Telegram bot this is basically able to simplify many things: many bot requests are long living, because you want to call an LLM API, or Whisper to transcribe, or do a Montecarlo simulation on a stock history, (btw the Whisper thing will be one of the official examples of this library) and so forth. Now in Stonky this approach worked so well because it's written in C, so each thread consumes only minimaul resources associated with the OS thread creation.
Finally: With SDS lib, my JSON and Sqlite3 wrapper (the wrappers are the interesting part of the project IMHO) it is not so different than writing Python code. So, I said, why not?
P.S. this library is just a work in progress, hacked while I'm doing many other stuff. I hope it will improve in the next weeks. I use Telegram for more than 10 years now, with all my friends and family. So it is very likely I'll require to write more bots in the future :D
If you want to reach out and ask me any questions about life with scoliosis (or anything else for that matter), feel free to reach out to me:
https://www.twitter.com/evildojo666
Your project is pretty cool...I can see myself integrating IRC support so I can bridge communications between telegram and IRC. I already do a lot of bot-like stuff using Sopel (Python) and notify (golang), but love working in C/C++.
antirez is a bright guy and worth paying attention to, but I think this is just him having some fun.
Edit: aha, here's what he's actually using it for.
In terms of binary size, memory usage, you probably can't beat a slim C project.
Difficulty of clean code/memory leaks/security aside, I think everyone should read or write some C every once in a while. Fix that software that doesn't work quite right on wine. Learn the linux kernel enough to fix a bug for hardware you own. Start some project like this. You might learn something, or strengthen some old mental muscles.
Zig can and do routinely beat it
Source: Run a bot that aggregates and translates several Russian channels for transparency reasons. ~100k msgs processed until now, including hour-long documentaries
Signal and WhatsApp (to a degree) have E2EE, but zero support for any kinds of bots, making them mostly useless for what I need chat applications for.
If I was managing a large chat group on a topic I could possibly see having a bit welcome new sign ups as beneficial ...
Either way I don't get the point so want to learn.
For example Midjourney is just a Discord bot you can invite to your own server and use it there.
I also ported an old IRC bot that had some specific functionality for a group to a basic Discord bot pretty much in one evening.
As for Telegram, I've get most of my server and software notifications via a single Telegram bot. A simple command just calls the API and sends the message to the bot
I also have an Octoprint bot on Telegram that I can use to monitor and control my 3D printer remotely.
Additionally we have a family channel in Telegram, and a home automation bot sits there. When someone forgets to close a door (front, fridge, freezer) the bot will complain in there. Same with temperature/humidity warnings and notifications. I'll add actual two-way controls when I get around to it, so that we could control the for example AC via the bot.
It's been a while since I played with telegram bots, but I remember thinking it is one of the best APIs I've used. So simple to register a bot directly through the chat interface with the not father, and a 5 second job to add message posting to a bash script etc.
I've used both Discord's bot API as well, and can say it was way more convoluted to get up and going. Telegram's API was a joy to build in. This was in Node.js.
I have had so much fun integrating with Telegram from Elixir. There is a lib (not in hex unfortunately) that makes it all quite straightforward.
I even gave a remote talk about it with an interactive demo: https://youtu.be/DFGHaER6_j4?si=sooEsiyVTmfXPqNs
Telegram is a mile simpler to get going with than the others.
I poked around with doing a Slack bot recently and the hoops for an app were many and confusing. Not Google credentials level but more than I cared for.
on a separate note, does anyone know of a stable telegram api (not bot api) in javascript that doesn't require polyfills?