Maharlikan
Maharlikan

Reputation: 63

Telegram Bot API SetChatMenuButton using PHP

anyone can help on how can I implement changing the telegram menu button using PHP, I'm totally new using and understanding it. Any help is well appreciated. TIA. Here's what I'd done, I'm doubting about JSON serialize i'm making here. Looking forward for any help. Here's the API documentation SetChatMenuButton

$data = [
    'menu_button' => array (
        "MenuButtonWebApp" => array (
            "type" => "web_app",
            "text" => "New Menu",
            "web_app" => array (
                "url" => "MYWEBSITE"
                )
            )
        )
    
    ];
   $response = file_get_contents("https://api.telegram.org/botMYAPITOKEN/setChatMenuButton? chat_id=MYCHATID&".http_build_query($data));
   print_r($response);```


Response: However I dont see any changes or additional error log if im missing something.

{"ok":true,"result":true}

Upvotes: 0

Views: 2697

Answers (1)

seymourg
seymourg

Reputation: 11

Try this

$data = [
        "chat_id"   => $chatId,
        'menu_button' => json_encode(
            array (
                    "type" => "web_app",
                    "text" => "Menu",
                    "web_app" => array (
                        "url" => "MYWEBSITE"
                    )
            )
        )
    ];
$response = Http::get("https://api.telegram.org/botMYAPITOKEN/setChatMenuButton?"
        .http_build_query($data));

Upvotes: 1

Related Questions