X
X
xneizv2019-11-19 15:06:40
PHP
xneizv, 2019-11-19 15:06:40

Telegram bot freezes, what's the problem?

Hello, there is a problem with the telegram bot, I made a format script:

<?php
$botData = [
  // API ключ телеграм
  'apiKey' => '***',
  // Ссылка на бота
  'botUrl' => '***',
];

define("BOT_TOKEN", $botData['apiKey']);
define("BOT_URL", $botData['botUrl']);

$data = json_decode(file_get_contents('php://input'), true);
 
if (empty($data['message']['chat']['id'])) {
  exit();
}
  file_put_contents('me2.txt',serialize($data));

// Функция вызова методов API.
function sendTelegram($method, $response) {
  $ch = curl_init('https://api.telegram.org/bot' . BOT_TOKEN . '/' . $method);  
  curl_setopt($ch, CURLOPT_POST, 1);  
  curl_setopt($ch, CURLOPT_POSTFIELDS, $response);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HEADER, false);
  $res = curl_exec($ch);
  curl_close($ch);
 
  return $res;
}
// Ответ на текстовые сообщения.
if (!empty($data['message']['text'])) {
  $text = $data['message']['text'];
 
  if (mb_stripos($text, 'привет') !== false) {
    sendTelegram(
      'sendMessage', 
      array(
        'chat_id' => $data['message']['chat']['id'],
        'text' => 'Хай!'
      )
    );
  file_put_contents('me.txt',serialize($data));
    exit();	
  }
}

the script first sent messages, then stopped and started to freeze, photo in the cart:
cC0VKifEQMM.jpg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xneizv, 2019-11-19
@xneizv

The issue is resolved, who is interested in the solution, the problem was that I used hosting for PHP scripts - webhost1.ru (not advertising), and I forgot that api.telegram.org is not available in the Russian Federation, I changed hosting to VDS, everything worked. Do not use Russian hosting for telegrams, messages on this do not reach.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question