sendMessage() 공개 메소드

Use this method to send text messages. On success, the sent \TelegramBot\Api\Types\Message is returned.
public sendMessage ( integer | string $chatId, string $text, string | null $parseMode = null, boolean $disablePreview = false, integer | null $replyToMessageId = null, TelegramBot\Api\Types\ReplyKeyboardMarkup | TelegramBot\Api\Types\ReplyKeyboardHide | TelegramBot\Api\Types\ForceReply | null $replyMarkup = null, boolean $disableNotification = false ) : Message
$chatId integer | string
$text string
$parseMode string | null
$disablePreview boolean
$replyToMessageId integer | null
$replyMarkup TelegramBot\Api\Types\ReplyKeyboardMarkup | TelegramBot\Api\Types\ReplyKeyboardHide | TelegramBot\Api\Types\ForceReply | null
$disableNotification boolean
리턴 TelegramBot\Api\Types\Message
 /**
  * ЦСКА
  */
 public function actionCskanews()
 {
     $cska = Yii::$app->params['cska'];
     $bot = new BotApi($cska['token']);
     $host = 'https://www.sports.ru';
     $dom = Html::load($cska['html']);
     $divs = $dom->getElementsByTagName('div');
     foreach ($divs as $div) {
         if ($div->getAttribute('class') == 'news') {
             $links = $div->getElementsByTagName('a');
             foreach ($links as $link) {
                 if ($link->getAttribute('class') == 'short-text') {
                     $url = Url::findOne(['channel' => 'cska', 'url' => $host . $link->getAttribute('href')]);
                     if ($url === null) {
                         $message = $link->nodeValue . "\n" . $host . $link->getAttribute('href');
                         try {
                             $bot->sendMessage($cska['chat_id'], $message);
                         } catch (Exception $e) {
                             echo $e->getMessage() . "\n";
                         }
                         $url = new Url(['channel' => 'cska', 'url' => $host . $link->getAttribute('href')]);
                         $url->save();
                     }
                 }
             }
         }
     }
 }
 /**
  * Проверка замен перед дедлайном
  */
 public function actionCheck()
 {
     $bot = new BotApi(Yii::$app->params['token']);
     $time = time() + 2 * 60 * 60;
     $tournaments = Tournament::find()->where(['checked' => false])->andWhere(['<', 'deadline', date('Y-m-d H:i:s', $time)])->all();
     foreach ($tournaments as $tournament) {
         foreach ($tournament->teams as $team) {
             if ($team->user->notification) {
                 $transfers = $team->getTransfers();
                 if ($transfers == $tournament->transfers) {
                     $message = 'Ты ещё не сделал замены, скоро дедлайн:';
                     $date = new DateTime($tournament->deadline, new DateTimeZone(Yii::$app->timeZone));
                     $message .= "\n" . $date->format('H:i') . '  ' . $tournament->name;
                     try {
                         $bot->sendMessage($team->user->chat_id, $message);
                     } catch (Exception $e) {
                         Yii::info($e->getMessage(), 'send');
                     }
                 }
             }
         }
         $tournament->checked = true;
         $tournament->save();
     }
 }
예제 #3
0
 /**
  * Отправляет сообщение
  */
 public function send($chatId, $message)
 {
     $bot = new BotApi(Yii::$app->params['token']);
     try {
         $bot->sendMessage($chatId, $message);
     } catch (Exception $e) {
         Yii::info(print_r($e, true), 'send');
     }
 }