Skip to content

TelegramBots platform #523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

BlackBaroness
Copy link
Contributor

@BlackBaroness BlackBaroness commented Feb 26, 2025

Hi there!

I implemented a basic support for TelegramBots (Telegram-recommended Java library). It's kinda finished in the current state, but, due to how different it is from more common platforms like Bukkit, there are some pitfalls.

Firstly, we have some limitations here:

  1. Receiving updates (using Long Poll) is separate from sending requests. Users create a separate listener and sender clients. In current implementation LiteCommands (kinda) has access to the listener part, as it doesn't send messages by itself (it can happen through result handlers etc., what can be coded by the library user).
  2. There is no auto complete in Telegram that can be dynamically changed by us. Library user can create commands and their descriptions in BotFather, it's impossible to do from code.
  3. There are no permissions in Telegram. As a simple solution, I created a BiPredicate in the settings of that platform, so the library user can implement it manually (it's a common thing for Telegram to have admin commands I believe).
  4. We cannot "inject" into the listener client directly (at least there is no convenient ways to do so). So the library user must store the platform reference and pass updates there when they think it's good time to do so.

My suggested setup:

TelegramBotsPlatform litecommands = LiteTelegramBotsFactory.builder(
  new LiteTelegramBotsSettings()
    .setPermissionChecker((user, permission) -> true)
);

new TelegramBotsLongPollingApplication().registerBot(Constants.TELEGRAM_TOKEN, (updates) ->
  for (Update update : updates) {
    // a place for the most critical logic

    if (litecommands.handleUpdate(update)) {
      // LiteCommands handled this update (it was a command), we can ignore it then
      return;
    }

    // a place for non-command logic
  }
};

Problems I see:

  • What to do if user entered just "/" without a command name? We return false currently.
  • Implement basic result handlers?
  • We need to pass Update, Message objects to the command handles and result handlers somehow. Otherwise the library user might not be able to send messages etc.

@BlackBaroness
Copy link
Contributor Author

BlackBaroness commented Feb 26, 2025

The build is successful btw, tests failed because of ProtocolLib what is unrelated

…mbots/LiteTelegramBotsSettings.java

Co-authored-by: Jakub Kędziora <[email protected]>
@BlackBaroness
Copy link
Contributor Author

BlackBaroness commented Feb 27, 2025

I need some thoughts and help about the "problems I see" section since I cannot solve it by myself

@Rollczi
Copy link
Owner

Rollczi commented Mar 30, 2025

Hi @BlackBaroness Thanks for you Pull request. What do you think about these changes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants