Saturday, May 30, 2015

Early Preview: telegram-pybot - A Telegram Bot based on Plugins, written in Python

We have all used and loved Yago's telegram-bot written in Lua as an extension for Vitaly Valtman's tg-cli for making funny Telegram bots. But Lua was keeping a lot of people away from making meaningful plugins.

Alternate approaches included adding a --json flag to vysheng's tg-cli and parsing that data or building wholly native APIs for Telegram in java or other languages. Liberbot is an excellent example.

Now, the developers at Datamachine Studios have come up with a Python interface for building bots. I have tested it and it works very well, even at this very early stage.

Screenshot of the bot listing its plugins on command
What?
Spartanly named "telegram-pybot" (for now, hopefully), what these people have created is a wrapper around vysheng's tg-cli. They did this by patching the cli with Python interfaces and contributing to the upstream (that's the beauty of free software).

Why not native Python API?
Apparently, the developers of telegram-pybot started out making plugins for the Lua bot. Later when they realized they wanted to switch to Python, it was easier to mimic the Lua binding API in Python rather than deal with the whole logic of Telegram (which keeps updating the schemas every now and then too). And many people are trying their hand in developing a pure Python API, should any of them become stable telegram-pybot is in a good space to switch to such a native interface with very little work in the future.

"It's kind of a pipe dream of mine to work on a python API, but one thing at a time right now" says Phillip Lopo who's one of the two main forces behind the bot.

Python vs Lua
In my experience, Lua can only be at best called a scripting language, albeit a powerful one, while Python is a power packed, complete programming language. The sheer number of libraries available in Python and the pythonic way of doing things makes development in Python much more easy compared to Lua. Also, threading is a huge weakness in Lua which has mostly been solved in telegram-pybot already.

Plugins
The sweetest feature of telegram-pybot is its plugin management system. It is promising even while currently undergoing heavy development. Plugins are organized by repositories. One can search, list, install, update, etc the plugins available in a repository. Soon multiple repositories will be supported so that anyone can maintain their own list of plugins in a repository and others can easily get hold of more plugins, thus also avoiding a single point of failure.

And the plugins themselves run quite smoothly, and cause no trouble even when they crash. Installing new plugins, restarting the bot, etc can be done over a Telegram chat thereby making them super easy to use (even for a non-developer)

License
Licensing bots, especially when they are powered by plugins is a confusing affair (read about the licensing of Yago's bot). GPL offers no protection to bots that run over the network and therefore if one has to choose a copyleft license, it must be AGPL.

But the developers of telegram-pybot want to give away as much freedom as possible. "I want people to use it, and I want the option for people to write private plugins for private communities" says Vincent Castellano, the co-developer. So there's a good chance they will settle for MIT or BSD license when they finish their primary work on the code.


With all that said, the bot is still in active development, as their readme says:
"While already very capable, this bot is still in relatively early development. Some plugin names, or plugin API calls may be modifed. However, we are starting to settle on our stable APIs."

But you should check it out already -- github.com/datamachine/telegram-pybot


When I discovered telegram-pybot last night, I was very excited. And I developed a plugin which we're enjoying in our FSM-K Telegram group. It is so easy to build that I want anyone with a computer to try, and therefore I've written a tutorial on my website.


If you like what you're reading, subscribe!

Get posts via email:

No comments :




One more time, subscribe via email: