Nikoro
Nikoro copied to clipboard
Pass Telegram API to plugins
I investigate the code of project and I think it will be better if instead of creating telegram API https://github.com/crisbal/Telegram-Bot-Node/blob/3677ee4cad2ede0ebae07422e5579472eed33d0c/src/Bot.js#L26 and then binding it's method to master plugin https://github.com/crisbal/Telegram-Bot-Node/blob/3677ee4cad2ede0ebae07422e5579472eed33d0c/src/PluginManager.js#L22 we will should pass telegramAPI instance to plugins directly, it will be transparently and plugins will be easily to test
What is the advantage to doing this? The interface will be just as powerful but more verbose, since plugins can't use this.sendMessage but must use this.api.sendMessage instead.
this.apiwith it's own methods clear solution, because with current concept we have to bind all of these methods
https://github.com/crisbal/Telegram-Bot-Node/blob/3677ee4cad2ede0ebae07422e5579472eed33d0c/src/Plugin.js#L134 https://github.com/crisbal/Telegram-Bot-Node/blob/3677ee4cad2ede0ebae07422e5579472eed33d0c/src/Plugin.js#L142 https://github.com/crisbal/Telegram-Bot-Node/blob/3677ee4cad2ede0ebae07422e5579472eed33d0c/src/Plugin.js#L146 https://github.com/crisbal/Telegram-Bot-Node/blob/3677ee4cad2ede0ebae07422e5579472eed33d0c/src/Plugin.js#L150
and so on..
- We could mock API Instance for unit tests for bot plugins, by the way now API method bind for
MasterPlugininstance