xabgesagtx / telegram-spring-boot-starter-example

Example project for telegram-spring-boot-starter
MIT License
26 stars 23 forks source link

Possible dependency cycle in future #4

Closed Miha-x64 closed 4 years ago

Miha-x64 commented 4 years ago

Hello. Your ExampleBot is a callback for updates and also a place where you can call some API methods. Thus, if you try to move any logic outside of the bot, you end up having a cycle:

public class ExampleBot extends TelegramLongPollingBot {
    private final SomeFeature feature;
    public ExampleBot(SomeFeature feature) { ... }

    @Override public void onUpdateReceived(Update update) {
        feature.onUpdate(update);
    }
}
...
public class SomeFeature {
    private final TelegramLongPollingBot bot;
    public SomeFeature(TelegramLongPollingBot bot) { ... }
    public void onUpdate(Update update) {
        ...
        bot.execute(new SendMessage()...);
    }
}
xabgesagtx commented 4 years ago

Hey, I'm not sure that I understand you correctly. This sounds to me like a basic programming issue, you are talking about.

  1. This is a starter that should make the usage of an already existing API (the TelegramBots library) with spring easier. TelgramPollingBot is an existing interface that is implemented here. You can implement it however you want to.
  2. Why do you want to inject the bot in your feature? Your feature could return a meaningful value (String, custom class etc) instead of void and the bot sends the message. This has the additional benefit that you are not mixing conecerns: telegram domain and your business logic.
Miha-x64 commented 4 years ago
  1. Right. Just a suggestion about what could go wrong when people copy-paste tutorials into their production and try to implement their features.
  2. Yep, I like the idea of returning Effects here. Like StreamEx<BotApiMethod<?>>, maybe. Thank you.