Answer the question
In order to leave comments, you need to log in
How to send buttons to Telegram bot?
I found a ready-made code that works with the telegram-bot-sdk
library. The task was to refuse to use the library, below I give the code that I have redone with the original code commented out.
The problem arose with the creation of buttons, everything works, but the buttons do not appear when the bot starts / start. Only the welcome message is displayed: Name, thanks for getting me started!
Please help fix the error.
Thank you!
<?php
//include('vendor/autoload.php'); //Подключаем библиотеку
//use Telegram\Bot\Api;
//$telegram = new Api('375466075:AAEARK0r2nXjB67JiB35JCXXhKEyT42Px8s'); //Устанавливаем токен, полученный у BotFather
//$result = $telegram -> getWebhookUpdates(); //Передаем в переменную $result полную информацию о сообщении пользователя
//определим константы
define('BOT_TOKEN','...');
define('API_URL', 'https://api.telegram.org/bot'.BOT_TOKEN.'/');
//получаем информацию от бота
$content = file_get_contents("php://input");
//расшифровываем её
$update = json_decode($content, true);
$text = $update["message"]["text"]; //Текст сообщения
$chat_id = $update["message"]["chat"]["id"]; //Уникальный идентификатор пользователя
$name = $update["message"]["from"]["first_name"];
$keyboard = ; //Клавиатура
if($text){
if ($text == "/start") {
$reply = $name.", спасибо, что запустили меня! ";
//$reply_markup = $telegram->replyKeyboardMarkup([ 'keyboard' => $keyboard, 'resize_keyboard' => true, 'one_time_keyboard' => false ]);
$reply_markup = API_URL . "replyKeyboardMarkup?keyboard=" . $keyboard . "&resize_keyboard=true&one_time_keyboard=false";
//$telegram->sendMessage([ 'chat_id' => $chat_id, 'text' => $reply, 'reply_markup' => $reply_markup ]);
$telegram = API_URL . "sendmessage?chat_id=" . $chat_id . "&text=" . $reply . "&reply_markup:" . $reply_markup;
}elseif ($text == "/help") {
$reply = "Информация с помощью.";
//$telegram->sendMessage([ 'chat_id' => $chat_id, 'text' => $reply ]);
$telegram = API_URL . "sendmessage?chat_id=" . $chat_id . "&text=" . $reply;
}elseif ($text == "Картинка") {
$url = "https://68.media.tumblr.com/6d830b4f2c455f9cb6cd4ebe5011d2b8/tumblr_oj49kevkUz1v4bb1no1_500.jpg";
//$telegram->sendPhoto([ 'chat_id' => $chat_id, 'photo' => $url, 'caption' => "Описание." ]);
$telegram = API_URL . "sendPhoto?chat_id=" . $chat_id . "&photo=" . $url . "&caption=Описание.";
}elseif ($text == "Гифка") {
$url = "https://68.media.tumblr.com/bd08f2aa85a6eb8b7a9f4b07c0807d71/tumblr_ofrc94sG1e1sjmm5ao1_400.gif";
//$telegram->sendDocument([ 'chat_id' => $chat_id, 'document' => $url, 'caption' => "Описание." ]);
$telegram = API_URL . "sendPhoto?chat_id=" . $chat_id . "&photo=" . $url . "&caption=Описание.";
}elseif ($text == "Последние статьи") {
$html=simplexml_load_file('https://eda.show/rss/');
foreach ($html->channel->item as $item) {
$reply .= " <a href='".$item->link."'>".$item->title."</a>";
}
//$telegram->sendMessage([ 'chat_id' => $chat_id, 'parse_mode' => 'HTML', 'disable_web_page_preview' => true, 'text' => $reply ]);
$telegram = API_URL . "sendmessage?chat_id=" . $chat_id . "&text=" . $reply . "&parse_mode=HTML";
}else{
$reply = "По запросу \"<b>".$text."</b>\" ничего не найдено.";
//$telegram->sendMessage([ 'chat_id' => $chat_id, 'parse_mode'=> 'HTML', 'text' => $reply ]);
$telegram = API_URL . "sendmessage?chat_id=" . $chat_id . "&text=" . $reply . "&parse_mode=HTML";
}
}else{
//$telegram->sendMessage([ 'chat_id' => $chat_id, 'text' => "Отправьте текстовое сообщение." ]);
$telegram = API_URL . "sendmessage?chat_id=" . $chat_id . "&text=Отправьте текстовое сообщение.";
}
file_get_contents($telegram);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question