微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

电报Bot回调查询

如何解决电报Bot回调查询

我正在尝试使用电报机器人进行包裹跟踪。

Rn机器人向您发送了一个包含跟踪信息的inlineKeyboard,现在我想使用跟踪API向用户提供有关其跟踪信息的更新。

问题是我无法确定用户为api选择的号码,我只能获取回调查询数据。

也许代码可以帮助您理解我的问题:

// Get the Callback from the inline keyboard

$update = json_decode(file_get_contents("PHP://input"),TRUE);
$cq = $update["callback_query"]["data"];
$cqId = $update["callback_query"]["from"]["id"];
$cqText = $update["callback_query"]["message"]["reply_markup"]["inline_keyboard"]["text"];

// send user the inline keyboard with his input tracking numbers

$inline_button0 = array("text"=> $trackingnumber0,"callback_data" =>'result0');
$inline_button1 = array("text"=> $trackingnumber1,"callback_data" =>'result1');
$inline_button2 = array("text"=> $trackingnumber2,"callback_data" =>'result2');
$inline_keyboard = [[$inline_button0,$inline_button1,$inline_button2]];
$keyboard=array("inline_keyboard"=>$inline_keyboard);
$replyMarkup = json_encode($keyboard);
$nachricht = urlencode("Choose a tracking number!");                            
$return = sendInlineKeyboard($cqId,$nachricht,$replyMarkup)

// Using my tracking api

$response = \APITracking\Single::get($cqText,$shipper);
$response = urlencode($response);
sendMessage($cqId,$response);

我认为$ cqText不起作用,有什么主意吗?

解决方法

使用text,您可以访问“按钮”标签,并使用callback_data来获取与按下的按钮关联的值

$cqVal = $update["callback_query"]["message"]["reply_markup"]["inline_keyboard"]["callback_data"];

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。