doniyorbekm
@doniyorbekm
Yii-шник

Почему телеграм отправляет сообщения бесконечно?

Ребят, и всё же почему мой бот отправляет сообщения бесконечно?

Класс для работы с Телеграмм:
class Telegram {

    public $token;
    const BASE_API_URL = 'https://api.telegram.org/bot' ;

    public function __construct($token) {
        $this->token = $token;
    }

    public function sendMessage($chatID, $message, $reply_markup = null) {
        $params['chat_id'] = $chatID ;
        $params['text'] = $message;
        $params['parse_mode'] = "HTML";
        if(!empty($reply_markup)) {
            $params['reply_markup'] = $reply_markup;
        }
        $url = $this->buildUrl('sendMessage').'?'.http_build_query($params) ;
        $data = file_get_contents($url) ;
        return json_decode($data, true) ;
    }

    private function buildUrl($methodName) {
        return self::BASE_API_URL.$this->token.'/'.$methodName ;
    }
}


Код в экшене контроллера:
public function actionGetUpdates() {
		
		$telegram = new Telegram('484152800:A**********************************');
		
        $updates = json_decode(file_get_contents('php://input'), true);
		$user_id = $updates['message']['chat']['id'];
		
		
        if($updates['update_id']) {
            switch($updates['message']['text']) {
                case '/start':
                    $telegram->sendMessage(
					$user_id,
					'Выберите язык | Choose language',
					json_encode([
						'inline_keyboard'=>[
							[
								['text'=>"\xf0\x9f\x87\xb7\xf0\x9f\x87\xba Русский язык",'callback_data'=> '/setlang_russian'],
								['text'=>"\xf0\x9f\x87\xba\xf0\x9f\x87\xbf English",'callback_data'=> '/setlang_english'],
							]
						]
					]));
					
                    break;
					
                default:
                    $telegram->sendMessage($user_id, "Команда \"".$updates['message']['text']."\" не найдена");
                    break;
            }
        }
    }


На адрес https://mywebsite.com/telegram/get-updates установлен webhook
  • Вопрос задан
  • 830 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы