telegramBot::sendMessage PHP Method

sendMessage() public method

Send text messages.
public sendMessage ( integer $chat_id, string $text, string $parse_mode = null, boolean $disable_web_page_preview = false, integer $reply_to_message_id = null, KeyboardMarkup $reply_markup = null ) : Array
$chat_id integer
$text string
$parse_mode string
$disable_web_page_preview boolean
$reply_to_message_id integer
$reply_markup KeyboardMarkup
return Array
    public function sendMessage($chat_id, $text, $parse_mode = null, $disable_web_page_preview = false, $reply_to_message_id = null, $reply_markup = null)
    {
        $params = compact('chat_id', 'text', 'parse_mode', 'disable_web_page_preview', 'reply_to_message_id', 'reply_markup');
        return $this->sendRequest('sendMessage', $params);
    }

Usage Example

Example #1
0
 } else {
     file_put_contents($fileOfLastUpdate, "0");
     $lastUpdateId = 0;
 }
 // Делаем long-poll запрос 60 секунд к серверу телеграм
 $updates = $tg->pollUpdates($lastUpdateId, 60);
 // Обрабатываем Updates, если они есть.
 foreach ($updates['result'] as $data) {
     $updateId = $updates['result'][count($updates['result']) - 1]['update_id'];
     $message = $data['message']['text'];
     $chatId = $data['message']['chat']['id'];
     // Эта команда для дебага, чтобы не перезапускать apache каждый раз, когда нужно перезапустить tbServer.php
     // Отправляешь боту команду /reboot и сервер останавливается.
     // В рабочей версии - нужно закоментить этот IF(){}
     if ($message == "/reboot") {
         $tg->sendMessage($chatId, 'Сервер будет перезапущен в течение минуты!');
         file_put_contents($fileOfLastUpdate, $updateId);
         exit;
     }
     $db = tbDatabase();
     // Проверим, авторизован ли пользователь
     $sth = $db->prepare("SELECT count(*) as count FROM tbManagers WHERE mBotChatId=:mBotChatId");
     $sth->execute(array(":mBotChatId" => $chatId));
     $answer = $sth->fetch();
     if ($answer["count"] > 0) {
         $isAuth = true;
     } else {
         $isAuth = false;
     }
     if ($isAuth === false) {
         if ($message == $tbManagerPassword) {
All Usage Examples Of telegramBot::sendMessage