-
Notifications
You must be signed in to change notification settings - Fork 117
v0.14 announcement
I'm happy to present new 0.14 release. This one differs from several previous minor releases because it brings some important changes. So this is the first telegram-bot's update with it's own announcement :)
Gem's API getting more stable with every minor update and I expect next version be a major release. However there was some issues that had to be addressed before first major release. So 0.14 version goes with some breaking changes. This update is going to make bots more secure and their source-code more consistent, trying to keep code clean and simple - this is what we like Ruby for.
The most important change in this update is related to handling commands. I always felt that there was something wrong with mapping command directly to action. Some of issues are:
- there was a workaround for name conflicts with payload types,
- specially crafted update could call other actions with unexpected arguments,
- there was no way to distinct actions for commands from other actions,
- etc.
Developers have to keep all this in mind and use workarounds. I saw two ways to solve it:
-
Add some helper to call it explicitly to mark method as command handler like this
command :cmd_name
orcommand def cmd_name(*)
. I don't like this way because it does not follow Convention-Over-Configuration principle, and module with shared actions can not be simply included (it requiresself.included
to mark command actions in target class). -
Add prefix/suffix to command when mapping it to method name:
/cmd_name => _cmd_name or cmd_name!
. It would be much better if ruby supporteddef /start(*)
, but it's not the case. I was thinking about any textual prefix/suffix that would essentially fit most of commands.
Finally I decided to proceed with bang-methods, because they are supported by ruby syntax, and does not require any additional efforts from developers to make them work even from included modules.
This decision also allows to simplify MessageContext. context_handler
was used to avoid conflicts in naming action methods for contexts and commands. With new naming convention it gets redundant, along with context_to_action!
. So context handlers are usual Ruby methods now.
Other big scope of changes are related to testing bots. New release brings missing support for testing bots in poller-mode and rack apps (without Rails). It also unifies API for unit and integration tests. This going to make it less confusing, simplify code-base and make test helpers reusable.
Please see upgrade guide for easy migration. If you have any feedback, suggestions or just want to say hi, feel free to post a comment to related issue.
I hope all this changes will make writing bots even more simple, secure and fun.
Happy coding!