Answer the question
In order to leave comments, you need to log in
There is a Telegram php bot code, but why doesn't it work?
Good day! Need help. I haven't been into this language for that long, so there are questions, and maybe a little silly ones. There is a ready-made Telegram php bot code. There is a local (as I understand it) server with the address " https://api.telegram.org/bot " my token "/getUpdates". Checked. Response results from the dialogue with the bot come. But I don't understand what else I haven't linked or synced since I don't get the most elementary: response to /start. The library has been downloaded and installed.
include('vendor/autoload.php');
use Telegram\Bot\Api;
$telegram = new Api('мойтокен');
$result = $telegram -> getWebhookUpdates();
$text = $result["message"]["text"];
$chat_id = $result["message"]["chat"]["id"];
$name = $result["message"]["from"]["username"];
$keyboard = ;
if($text){
if ($text == "/start") {
$reply = "Добро пожаловать в бота!";
$reply_markup = $telegram->replyKeyboardMarkup([ 'keyboard' => $keyboard, 'resize_keyboard' => true, 'one_time_keyboard' => false ]);
$telegram->sendMessage([ 'chat_id' => $chat_id, 'text' => $reply, 'reply_markup' => $reply_markup ]);
}elseif ($text == "/help") {
$reply = "Информация с помощью.";
$telegram->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' => "Описание." ]);
}elseif ($text == "Последние статьи") {
$html=simplexml_load_file('http://netology.ru/blog/rss.xml');
foreach ($html->channel->item as $item) {
$reply .= "\xE2\x9E\xA1 ".$item->title." (<a href='".$item->link."'>читать</a>)\n";
}
$telegram->sendMessage([ 'chat_id' => $chat_id, 'parse_mode' => 'HTML', 'disable_web_page_preview' => true, 'text' => $reply ]);
}else{
$reply = "По запросу \"<b>".$text."</b>\" ничего не найдено.";
$telegram->sendMessage([ 'chat_id' => $chat_id, 'parse_mode'=> 'HTML', 'text' => $reply ]);
}
}else{
$telegram->sendMessage([ 'chat_id' => $chat_id, 'text' => "Отправьте текстовое сообщение." ]);
}
Answer the question
In order to leave comments, you need to log in
Try wardumping the "$text" variable to see what is being assigned to it
var_dump($text);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question