class OurBot extends WolfDispatcher { const CHATS_LOG_PATH = 'exports/allchats.log'; /** * Just reacts for user greeting personally * * @return void */ protected function actionHelloName() { $hisName = $this->receivedData['from']['first_name']; $this->reply(__('Hello') . ' ' . $hisName); } /** * Replies on photo posted in chat * * @return void */ protected function actionPhotoWow() { if ($this->isPhotoReceived()) { $message = $this->message(); //returns $this->receivedData copy if ($message['text']) { $replyText = 'Ого яка фотка! Це точно ' . $message['text'] . '?'; } else { $replyText = 'Нічогенька така картинка'; } $this->replyTo($replyText); } } /** * Just logs all chats non empty text messages to some log file * * @return void */ protected function handleAnyWay() { if (!empty($this->receivedData['text'])) { $logData = date("Y-m-d H:i:s", $this->receivedData['date']) . ' ' . $this->chatId . ' '; $logData .= $this->receivedData['from']['first_name'] . ' ' . $this->receivedData['text'] . PHP_EOL; file_put_contents(self::CHATS_LOG_PATH, $logData, FILE_APPEND); } } }