行内键盘按钮通过使用PHP更改用户URL的操作?

huangapple go评论70阅读模式
英文:

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_herehttps://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
>
> 可选。按钮被按下时要打开的HTTPtg:// 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=&lt;user_id&gt; 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([
    &quot;inline_keyboard&quot; =&gt; [
        [
            [
                &quot;text&quot; =&gt; &quot; ADMINPAGE &quot;,
                &quot;url&quot; =&gt; &quot;https://example.com/admin&quot;
            ],

            [
                &quot;text&quot; =&gt; &quot; HOMEPAGE &quot;,
                &quot;url&quot; =&gt; &quot;https://example.commin&quot;
            ]
        ]
    ]
]);

huangapple
  • 本文由 发表于 2023年1月9日 03:49:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/75050798.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定