英文:
inline keyboard button make action change user url using php?
问题
如果我按下两个按钮中的一个,我想将用户重定向到另一个页面,看看我的代码是否正常工作,但我不知道如何在内联键盘上执行此操作。
if ($telegram == "on"){
$keyboard = json_encode([
"inline_keyboard" => [
[
[
"text" => "✅ ADMINPAGE ✅",
"url" => "https://your_admin_page_url_here"
],
[
"text" => "❌ HOMEPAGE ❌",
"url" => "https://your_home_page_url_here"
],
]
]
]);
$parameters = array(
"chat_id" => $chat_id,
"text" => $txt,
'reply_markup' => $keyboard
);
$send = ($parameters);
$website_telegram = "https://api.telegram.org/bot{$bot_url}";
$ch = curl_init($website_telegram . '/sendMessage');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ($send));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
}
在代码中,我添加了url
属性,并将其设置为要重定向到的页面的URL。当用户按下按钮时,它将打开相应的链接。请将https://your_admin_page_url_here
和https://your_home_page_url_here
替换为实际的管理员页面和主页的URL。
英文:
i have a php code for telegram bot inline keyboard i want when i press one of the two buttons
i want to redirect the user to another page, look at my code is working but i dont know how to do this action on the inline keyboard
if ($telegram == "on"){
$keyboard = json_encode([
"inline_keyboard" => [
[
[
"text" => "✅ ADMINPAGE ✅",
"callback_data" => "callbackone"
],
[
"text" => "❌ HOMEPAGE ❌",
"callback_data" => "callbacktwo"
],
]
]
]);
$parameters = array(
"chat_id" => $chat_id,
"text" => $txt,
'reply_markup' => $keyboard
);
$send = ($parameters);
$website_telegram = "https://api.telegram.org/bot{$bot_url}";
$ch = curl_init($website_telegram . '/sendMessage');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ($send));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
}
答案1
得分: 0
InlineKeyboardButton
接受一个url
参数:
> url
>
> 可选。按钮被按下时要打开的HTTP
或tg://
URL。
> 可以使用tg://user?id=<user_id>
链接来提及用户的ID,而不使用用户名,如果其隐私设置允许的话。
所以你需要像这样做:
$keyboard = json_encode([
"inline_keyboard" => [
[
[
"text" => "✅ 管理页面 ✅",
"url" => "https://example.com/admin"
],
[
"text" => "❌ 主页 ❌",
"url" => "https://example.commin"
]
]
]
]);
英文:
The InlineKeyboardButton
accepts an url
parameter:
> url
>
> Optional. HTTP
or tg://
URL to be opened when the button is pressed.
> Links tg://user?id=<user_id>
can be used to mention a user by their ID without using a username, if this is allowed by their privacy settings.
So you'll need something like:
$keyboard = json_encode([
"inline_keyboard" => [
[
[
"text" => "✅ ADMINPAGE ✅",
"url" => "https://example.com/admin"
],
[
"text" => "❌ HOMEPAGE ❌",
"url" => "https://example.commin"
]
]
]
]);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论