我创建了一些带有for
循环的Telegram内联按钮。
for ($i = 1; $i < 35; $i++) {
$arr[] = array(array(
"text" => $i,
"callback_data" => "Test_".$i,
));
}
$bot->sendKeyboard($chat_id, $reply, $arr);
public function sendKeyboard($chat_id, $text, $keyboard = Array())
{
$action = 'sendMessage';
$param = array(
'chat_id' => $chat_id,
'reply_markup' => json_encode(array("keyboard" => $keyboard, "one_time_keyboard" => true, "resize_keyboard" => true)),
'text' => $text
);
$res = $this->send($action, $param);
if (!$res['ok']) {
$result = Array("success" => 0, "info" => "Error: " . $res['description']);
} else {
$result = Array("success" => 1, "info" => "Keyboard show");
}
return $result;
}
例如,按钮文本是6,我希望Telegram在聊天中写Test_6
。
我需要做什么更改才能输出与按钮上的文本不同的文本?
1条答案
按热度按时间monwx1rj1#
按钮上的
text
是用户在Telegram中看到的。callback_data
是一个内部值,当有人按下按钮时会返回该值,因此可以使用它来处理click事件。你需要像这样创建按钮:
因此用户可以看到
Test_1
直到Test_35
。如果有人按下按钮,您将获得数据1
到35
的数字。