TelegramBots icon indicating copy to clipboard operation
TelegramBots copied to clipboard

Adding a default ability with with 'GROUP' locality renders all commands unavailable

Open Haarolean opened this issue 1 year ago • 2 comments

Hi, not sure what this repo state is in, considering the sheer amount of open & unanswered issues and PRs, but I'll try anyway:

The problem is that adding an ability as such:

        return Ability
                .builder()
                .name("default")
                .flag(TEXT)
                .locality(Locality.GROUP)
                .privacy(Privacy.PUBLIC)
                .action(this::checkLinks)
                .build();

makes all the other default commands/abilities inaccessible. The bot just replies with "Sorry, group-only feature.", since it's, well, a default ability. I have to use this particular set of options (locality, privacy) to check message contents. There's no way to further chain the event or make the other abilities in the list usable.

I propose to allow processing of the update further down the chain (replace Consumer in Ability with Function<MessageContext, Boolean and proceed to other abilities)

Haarolean avatar Jan 10 '24 13:01 Haarolean

Ah, I figured that since then I've changed the command prefix. With a proper prefix the commands work, buut if you type anything that doesn't start with a command prefix you get the same message in private messages, despite the ability was designed fro group messages. So, it seems, like there should be (?) a default ability per each privacy level?

Haarolean avatar Jan 10 '24 13:01 Haarolean

To solve that, currently a hack like this could be implemented:

  1. Replacing ability's locality from GROUP to ALL
  2. In action we have to check if it's non-group message and stop further processing the update:
.action(ctx -> {
                    if (!shouldProceed(ctx)) return;
                    yourAction();
                })
private boolean shouldProceed(MessageContext ctx) {
        var update = ctx.update();
        return !isUserMessage(update);
    }

Haarolean avatar Jan 10 '24 13:01 Haarolean