core icon indicating copy to clipboard operation
core copied to clipboard

Commands directed to other bots are mistakenly handled by Genericmessage

Open jacklul opened this issue 9 years ago • 8 comments

Before ~0.37 they were correctly handled by Genericcommand, I think since now my code for 'stalking' other bot commands in Genericcommand doesn't generate any reports.

The same in private chat and groups. Image for visualization: https://i.imgur.com/eXfV5AQ.jpg

jacklul avatar Dec 29 '16 18:12 jacklul

I thought it is correct behavior. Multicast command for those who can handle it.... And if you have to handle unsupported command you need to generate empty response in group chats.

chuv1 avatar Dec 30 '16 00:12 chuv1

My point is those messages still carry bot_command entity so they should be handled as command, not message.

jacklul avatar Dec 30 '16 07:12 jacklul

Not quite sure I understand.

On 0.35 ->type = "Message" ->text = "/c@b" When I try sending a message to a "foreign" bot within my bot, it gets executed as a text message type, not a command. That's because here the command isn't meant for my bot. So it returns false and is regarded as a normal text message.

On 0.38.1 Same thing happens here.

Only messages sent with /xyz and without @bot_name get the command type, thus forwarding it to GenericCommand.

Am I missing something here?

Would you be expecting GenericCommand to kick in for /cmd and /cmd@not_my_bot?

noplanman avatar Dec 30 '16 14:12 noplanman

Well that's interesting, either I had some own modifications or else I don't know.

Would you be expecting GenericCommand to kick in for /cmd and /cmd@not_my_bot?

Yes, since as I previously said, even if it's not meant for the bot it's still a command, not text message!

jacklul avatar Dec 30 '16 15:12 jacklul

Yes, you're right, should still be considered a command.

Looking at a nice way to implement this, but it's not that easy I think 😕 The problem is the part that I've linked to in my previous comment. If it is a command but not meant for our bot, we should return something else than the command itself, as it would otherwise be executed as if it was meant for our bot. It's also kind of out of scope of the getCommand method. We probably need to introduce an extra method or something called isThisBot.

Open to any suggestions you might have.

noplanman avatar Dec 30 '16 18:12 noplanman

I guess not a priority until we can have clean and nice way to implement this.

jacklul avatar Dec 30 '16 20:12 jacklul

@jacklul is this already fixed?

akalongman avatar May 10 '18 17:05 akalongman

Nope, bot still answers to messages not directed to him.

In one of my bots I'm using this as a solution:


    /**
     * @param $command
     *
     * @return ServerResponse|mixed
     * @throws TelegramException
     */
    public function executeCommand($command)
    {
        if ($message = $this->update->getMessage()) {
            $entities = $message->getEntities();
            
            if (count($entities) > 0) {
                $first_entity = $message->getEntities()[0];
                if ($first_entity->getType() === 'bot_command' && $message->getCommand() === null) {
                    return Request::emptyResponse();
                }
            }
        }

        return parent::executeCommand($command);
    }

Maybe we could think about doing entity = bot_command check in Message::getType() and then return Request::emptyResponse() when getCommand() is null ?

jacklul avatar May 10 '18 19:05 jacklul