Skip to content
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

TelegramBots platform #523

Open
wants to merge 3 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

@@ -32,7 +32,7 @@ If you don’t update, **permissions will default to OR behavior** in the new ve
[![Java](https://raw.githubusercontent.com/intergrav/devins-badges/v3/assets/cozy/built-with/java8_vector.svg)](https://www.java.com/)

### LiteCommands
Annotation based command framework for Velocity, Bukkit, Paper, BungeeCord, Minestom, Sponge, Fabric, JDA and future implementations.
Annotation based command framework for Velocity, Bukkit, Paper, BungeeCord, Minestom, Sponge, Fabric, JDA, TelegramBots and future implementations.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably make it a bullet list now 😮

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a bullet list below already, I guess we shouldn't make a second one

…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

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.

2 participants