Answer the question
In order to leave comments, you need to log in
Why can't I install a webhook when creating a telegram bot?
I want to create a simple bot. Installed on a virtual server https://github.com/TelegramBot/Api
Created a bot in BotFather
Registered a domain Installed Lets Encrypte to be https
I am writing this code:
<?php
header('Content-Type: text/html; charset=utf-8');
echo('Отправили заголовки');
require_once("vendor/autoload.php");
echo('Подключили Telegram API');
$token = "мой_токен";
$bot = new \TelegramBot\Api\Client($token);
if(!file_exists("registered.trigger")){
/**
* файл registered.trigger будет создаваться после регистрации бота.
* если этого файла нет значит бот не зарегистрирован
*/
// URl текущей страницы
$page_url = "https://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
echo($page_url);
$result = $bot->setWebhook($page_url);
if($result){
file_put_contents("registered.trigger",time()); // создаем файл дабы прекратить повторные регистрации
}
}
// обязательное. Запуск бота
$bot->command('start', function ($message) use ($bot) {
$answer = 'Добро пожаловать!';
$bot->sendMessage($message->getChat()->getId(), $answer);
});
// помощ
$bot->command('help', function ($message) use ($bot) {
$answer = 'Команды:
/help - помощ';
$bot->sendMessage($message->getChat()->getId(), $answer);
});
// запускаем обработку
$bot->run();
?>
Answer the question
In order to leave comments, you need to log in
And how to check it then?
Like this?
<?
$wait = 1; // wait Timeout In Seconds
$host = 'api.telegram.org';
$ports = [
'http' => 80,
'https' => 443,
'ftp' => 21,
];
foreach ($ports as $key => $port) {
$fp = @fsockopen($host, $port, $errCode, $errStr, $wait);
echo "Ping $host:$port ($key) ==> ";
if ($fp) {
echo 'SUCCESS';
fclose($fp);
} else {
echo "ERROR: $errCode - $errStr";
}
echo PHP_EOL;
};
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question