我正在使用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
版本。
答案 0 :(得分:0)
我无法回答为什么triggerCommand
无效,但这段代码完美无缺。
$commands = [...];
$telegram->addCommands($commands);
$commandsHandler = $telegram->commandsHandler(true);
//$command = "yourCommand" for example, $arguments = array of something
$res = $telegram->getCommandBus()->execute($command, $arguments, $commandsHandler);
希望它对像我这样的人有用=)