【发布时间】:2017-12-17 22:24:03
【问题描述】:
我想知道热门阅读并将与我的电报机器人聊天的用户单击的按钮的文本保存到变量中。
问题:
我有这段代码可以帮助我为我的机器人获取 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);
}
结果是 this.
但是我如何知道点击了哪个按钮,然后将按钮的文本保存到变量中?
我尝试在case下添加代码
case "/aggiungi":
sendMessageButtons($chatID, "Sample text", $keyboard);
**$ButtonText = $updates["message"]["text"];
sendMessage($chatID, $ButtonText);**
但结果是 this.
机器人返回“/aggiungi”的情况,在屏幕上打印最后一个文本(即“/aggiungi”),它不会等待我从键盘输入。
问题:
如何保存来自被点击按钮的文本?
希望您能理解问题并感谢大家的宝贵时间!
【问题讨论】:
-
看看这里 - stackoverflow.com/a/44645591/4269118。是你的情况吗?我认为这是相似的。所以尝试使用 ForseReply
标签: javascript php telegram telegram-bot php-telegram-bot