用于 PHP 的带有 Url InlineKeyboardButton 的 Telegram 机器人

Tol*_*maz 1 php telegram telegram-bot

$data = [
    'text' => 'your message here',
    'chat_id' => '@channelname'
];

file_get_contents("https://api.telegram.org/bot$token/sendMessage?" . http_build_query($data));
Run Code Online (Sandbox Code Playgroud)

我可以通过这种方式发送消息,但我想动态地在其中放置一个按钮(链接)。我能怎么做?

0st*_*ne0 5

<?php

    $token = '11345342......';
    $keyboard = json_encode([
        "inline_keyboard" => [
            [
                [
                    "text" => "Button 1",
                    "callback_data" => "1"
                ],
                [
                    "text" => "Button 2",
                    "callback_data" => "2"
                ]
            ]
        ]
    ]);

    $data = http_build_query([
        'text' => 'your message here',
        'chat_id' => '@channelname'
    ]);

    $url = "https://api.telegram.org/bot$token/sendMessage?{$data}&reply_markup={$keyboard}";
    $res = @file_get_contents($url);
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述