我想知道热门阅读并将与我的电报机器人聊天的用户单击的按钮的文本保存到变量中。
问题:
我有这段代码可以帮助我为我的机器人获取 webhook 响应。
$getupdates = file_get_contents("php://input");
$updates = json_decode($getupdates, TRUE);
然后我将与我的机器人聊天的用户的 chat_id 保存到一个变量 ($chatID) 中,另一个变量 $text 是消息的文本。
然后我添加这个开关
switch($text)
{
case "/aggiungi":
sendMessageButtons($chatID, "Sample text", $keyboard);
}
$keyboard 是我的数组数组,其中包含我的 ReplyKeyboardMarkup 键盘。
我的函数“sendMessageButtons”如下:
function sendMessageButtons($chatID, $message, $keyboard)
{
$url = $GLOBALS['website']."/sendMessage?chat_id=".$chatID."&text=".urlencode($message)."&reply_markup=".$keyboard;
file_get_contents($url);
}
结果是 这样的。
但是我怎么知道点击了哪个按钮,然后将按钮的文本保存到变量中呢?
我尝试在案例下添加代码
case "/aggiungi":
sendMessageButtons($chatID, "Sample text", $keyboard);
**$ButtonText = $updates["message"]["text"];
sendMessage($chatID, $ButtonText);**
但结果是 这样的。
机器人返回“/aggiungi”的情况,在屏幕上打印最后一个文本(即“/aggiungi”),它不会等待我从键盘输入。
问题:
如何保存来自单击按钮的文本?
我希望你能理解这个问题,并感谢大家的宝贵时间!