php-telegram-bot / core

PHP Telegram Bot based on the official Telegram Bot API
MIT License
3.87k stars 951 forks source link

Disable botan reporting per message basis. #400

Closed chuv1 closed 7 years ago

chuv1 commented 7 years ago

Is there any way to disable reporting in GenericmessageCommand, for example? I'd like to track by botan just some messages (ex. starting with defined words) and not all of them.

chuv1 commented 7 years ago

And one more question. Is there any way to send a defined "event" to botan, instead of message? For example I'd like to track all meaningless (for a bot) messages from public chat as 'empty_message'.

jacklul commented 7 years ago

Is there any way to disable reporting in GenericmessageCommand, for example? I'd like to track by botan just some messages (ex. starting with defined words) and not all of them.

I believe placing Botan::$command = 'somethingstupidthatisntgenericcommand'; before returning in Genericcommand should do the trick. If you call other commands within Genericcommand you should change that variable to empty instead so the executed command can be tracked (if you want).

And one more question. Is there any way to send a defined "event" to botan, instead of message? For example I'd like to track all meaningless (for a bot) messages from public chat as 'empty_message'.

Currently there is not, you could only call Botan::track() by yourself inside a command and provide a fake/modified update to it and custom command name as a second argument.

chuv1 commented 7 years ago

I believe placing Botan::$command = 'somethingstupidthatisntgenericcommand'; before returning in Genericcommand should do the trick. If you call other commands within Genericcommand you should change that variable to empty instead so the executed command can be tracked (if you want).

Since I'm talking about GenericmessageCommand.php (to disable chit-chat messages tracking) I'm considering to add 'disableBotan' method.

What if I'll add that code to to Telegram.php and call it when needed? Will it disable botan tracking if placed prior to Request::anyMethod?

    /**
     * Disable Botan.io integration
     *
     * @param  $token
     *
     * @return \Longman\TelegramBot\Telegram
     * @throws \Longman\TelegramBot\Exception\TelegramException
     */
    public function disableBotan()
    {
        $this->botan_enabled = false;

        return $this;
    }
jacklul commented 7 years ago

Yes, it will. Still, I specifically made Botan::$command public so the developers can filter what gets tracked, I still think it's a fine solution.

chuv1 commented 7 years ago

Yes, it will. Still, I specifically made Botan::$command public so the developers can filter what gets tracked, I still think it's a fine solution.

Sorry, probably I got you wrong. So you mean

placing Botan::$command = 'somethingstupidthatisntgenericcommand'; before returning

will not send any data to botan, except that string? No message text, entities, or any other message associated data?

jacklul commented 7 years ago

It won't send anything when Botan::$command does not match a command executed with Telegram::executeCommand().

chuv1 commented 7 years ago

Thanks a lot! Definitely got you wrong, after your first reply. I thought that it will replace command name,but still send data.