// -----------------------------
// Завантаження налаштувань
// -----------------------------
$settings = include "../settings.dat";
$bot_token = $settings['bot_token'];
$web_app_url = $settings['web_app_url'];
$api_url = "https://api.telegram.org/bot{$bot_token}";
// -----------------------------
// Очистка меню
// -----------------------------
function deleteChatMenuButton() {
global $api_url;
$url = $api_url . '/deleteChatMenuButton';
$options = [
'http' => [
'header' => "Content-Type: application/json\r\n",
'method' => 'POST',
'content' => json_encode([]),
],
];
$context = stream_context_create($options);
return file_get_contents($url, false, $context);
}
// -----------------------------
// Встановлення кнопки Open App
// -----------------------------
function setChatMenuButton($web_app_url) {
global $api_url;
$menuButtonData = [
'menu_button' => [
'type' => 'web_app',
'text' => 'Open App',
'web_app' => ['url' => $web_app_url],
],
];
$url = $api_url . '/setChatMenuButton';
$options = [
'http' => [
'header' => "Content-Type: application/json\r\n",
'method' => 'POST',
'content' => json_encode($menuButtonData),
],
];
$context = stream_context_create($options);
return file_get_contents($url, false, $context);
}
// -----------------------------
// Виконання
// -----------------------------
deleteChatMenuButton(); // Очистка меню
$result = setChatMenuButton($web_app_url); // Встановлення Open App
// Вивід результату
//var_dump($result);