irazasyed/telegram-bot-sdk触发命令php
irazasyed/telegram-bot-sdk trigger command php
我正在使用irazasyed/telegram-bot-sdk,我需要通过文本触发命令。
这是代码示例:
$telegram = new Api($key);
$commands = [
\Startdev::class,
\Help::class,
\Cinema::class,
\Theater::class,
\Exhibition::class,
\Holidays::class,
\Sport::class
];
$telegram->addCommands($commands);
$commandsHandler= $telegram->commandsHandler(true);
$updates = $telegram->getWebhookUpdates();
if (!empty($updates)){
if ($updates->isType('callback_query')) {
$query = $updates->getCallbackQuery();
$data = $query->getData();
//$data - here is my command (for example - "cinema")
$telegram->answerCallbackQuery([
'callback_query_id' => $query->getId()
]);
try{
$telegram->triggerCommand($data,$commandsHandler);
} catch (Exception $e){
$this->log($e->getMessage());
}
}
}
什么都没发生。但是命令处理程序 /cinema
完美运行。
你能帮帮我或给点建议吗?
更多信息:
irazasyed/telegram-bot-sdk: master-dev
版本。
我无法回答为什么 triggerCommand
不起作用,但是这个代码示例工作得很好。
$commands = [...];
$telegram->addCommands($commands);
$commandsHandler = $telegram->commandsHandler(true);
//$command = "yourCommand" for example, $arguments = array of something
$res = $telegram->getCommandBus()->execute($command, $arguments, $commandsHandler);
希望对像我这样的人有用 =)
我正在使用irazasyed/telegram-bot-sdk,我需要通过文本触发命令。
这是代码示例:
$telegram = new Api($key);
$commands = [
\Startdev::class,
\Help::class,
\Cinema::class,
\Theater::class,
\Exhibition::class,
\Holidays::class,
\Sport::class
];
$telegram->addCommands($commands);
$commandsHandler= $telegram->commandsHandler(true);
$updates = $telegram->getWebhookUpdates();
if (!empty($updates)){
if ($updates->isType('callback_query')) {
$query = $updates->getCallbackQuery();
$data = $query->getData();
//$data - here is my command (for example - "cinema")
$telegram->answerCallbackQuery([
'callback_query_id' => $query->getId()
]);
try{
$telegram->triggerCommand($data,$commandsHandler);
} catch (Exception $e){
$this->log($e->getMessage());
}
}
}
什么都没发生。但是命令处理程序 /cinema
完美运行。
你能帮帮我或给点建议吗?
更多信息:
irazasyed/telegram-bot-sdk: master-dev
版本。
我无法回答为什么 triggerCommand
不起作用,但是这个代码示例工作得很好。
$commands = [...];
$telegram->addCommands($commands);
$commandsHandler = $telegram->commandsHandler(true);
//$command = "yourCommand" for example, $arguments = array of something
$res = $telegram->getCommandBus()->execute($command, $arguments, $commandsHandler);
希望对像我这样的人有用 =)