Telegram-bot-sdk: Callback query and triggerCommand problems

Created on 18 Jan 2018  路  5Comments  路  Source: irazasyed/telegram-bot-sdk

Hello!

I've got some problems:

$telegram = new Api($key);
$commands = [
    \Startdev::class,
    \Help::class,
    \Cinemadev::class,
    \Theater::class
];

$telegram->addCommands($commands);
$commandsHandler = $telegram->commandsHandler(true);
$update = $telegram->getWebhookUpdate();
if (!empty($update)) {

    if ($update->isType('callback_query')) {

        $query = $update->getCallbackQuery();
        $data = $query->getData();
        $chid = $query->getFrom()->getId();

        $telegram->sendMessage([ 'chat_id' => $chid, 'text' => $data]);

//here is some troubles - message sending rather chaotic, instead of sending one uncontrolled number and always different data

        $responses = $telegram->answerCallbackQuery([
            'callback_query_id' => $query->getId()
        ]);


//this part of code don't work, exception clear,

//For example: $data = "cinema" trigger command, but command in chat "/cinema" works perfectly
        try {
            $telegram->triggerCommand($data, $commandsHandler);
        } catch (Exception $e) {
            $this->log($e->getMessage());
        }
    }
}

What it can be?

Ver:
"irazasyed/telegram-bot-sdk": "master-dev"

Composer updated on 16 Jan, 2018

Thank u!

Most helpful comment

triggerCommand doesn't work as well, but i used:

$commands = [...];

$telegram->addCommands($commands);
$commandsHandler = $telegram->commandsHandler(true);

//$command = "yourCommand" for example, $arguments = array of something
$res = $telegram->getCommandBus()->execute($command, $arguments, $commandsHandler);

@ahmadbadpey - hope that help you

All 5 comments

馃憢 Thanks for opening your first issue here! If you're reporting a 馃悶 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

To help make it easier for us to investigate your issue, please follow the contributing guidelines.

I have same problem. when message is type of a callback_query whenever call triggerCommand and send Update as second argument to it , I got this error :

Call to a member function getText() on null {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Call to a member function getText() on null at D:\\wamp\\www\\botshop\\vendor\\irazasyed\\telegram-bot-sdk\\src\\Api.php:1369)

triggerCommand doesn't work as well, but i used:

$commands = [...];

$telegram->addCommands($commands);
$commandsHandler = $telegram->commandsHandler(true);

//$command = "yourCommand" for example, $arguments = array of something
$res = $telegram->getCommandBus()->execute($command, $arguments, $commandsHandler);

@ahmadbadpey - hope that help you

@SergioZhidkov , yes it's worked for me. But what triggerCommand does not for calllback messages?

The reason is triggerCommand tries to supply command with arguments taken from $update->getMessage(), but in case of CallbackQuery message is null.
I would suggest the author to supply additional argument $arguments = "" to triggerCommand and substitute the argument list for command by this.

public function triggerCommand($name, Update $update, $arguments = "")
{
    return $this->getCommandBus()->execute($name, ($update->getMessage() && empty($arguments)) ? $update->getMessage()->getText() : $arguments, $update);
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

b10585 picture b10585  路  4Comments

jobs2008 picture jobs2008  路  3Comments

behnamazimi picture behnamazimi  路  3Comments

realtebo picture realtebo  路  4Comments

khalilst picture khalilst  路  3Comments