Nikoro icon indicating copy to clipboard operation
Nikoro copied to clipboard

Pass Telegram API to plugins

Open ufocoder opened this issue 8 years ago • 2 comments

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

ufocoder avatar Oct 03 '17 13:10 ufocoder

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.

CapacitorSet avatar Oct 03 '17 14:10 CapacitorSet

  1. this.api with 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..

  1. We could mock API Instance for unit tests for bot plugins, by the way now API method bind for MasterPlugin instance

ufocoder avatar Oct 03 '17 14:10 ufocoder