我需要从内联按钮编辑数据库中的记录。
$query->getData() 包含动作和记录 ID,如 action=edit&id=3
单击内联按钮后如何获取用户输入?
//hook.php
CallbackqueryCommand::addCallbackHandler(function($query) use ($telegram) {
...
case 'myaction':
return $telegram->executeCommand('edit');
}
// EditCommand.php
public function execute()
{
if ($this->getCallbackQuery() !== null) {
$message = $this->getCallbackQuery()->getMessage();
}
else {
$message = $this->getMessage();
}
$this->conversation = new Conversation($user_id, $chat_id, $this->getName());
$notes = &$this->conversation->notes;
!is_array($notes) && $notes = [];
$state = 0;
if (isset($notes['state'])) {
$state = $notes['state'];
}
$result = Request::emptyResponse();
switch ($state) {
case 0:
if ($text === '') {
$notes['state'] = 0;
$this->conversation->update();
$data['text'] = 'Choose button';
$data['reply_markup'] = $keyboard;
$result = Request::sendMessage($data);
break;
}
$notes['laundry'] = $text;
$text = '';
case 1:
...
然后在 EditCommand execute() 中只触发一次。我认为因为来自用户的第二条消息不是回调。
解决了。对话必须像
$this->conversation = new Conversation(null !== $this->getCallbackQuery() ? $chat_id : $user_id, $chat_id, $this->getName());
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句