use TelegramCliWrapper\Response; use TelegramCliWrapper\Models\User; use TelegramCliWrapper\Services\Weather\OpenWeatherApi; use TelegramCliWrapper\Services\Media\MediaSelector; use TelegramCliWrapper\Services\Joke\IcndbApi; if (!isset($_SESSION['user'])) { return Response::error("illegal request"); } $userStorage = new LocalFilesStorage('user'); $user = $userStorage->getById($_SESSION['user']); if (!$user) { return Response::error("user does not exist"); } $th = TelegramCliHelper::getInstance(); $t = new TelegramCliWrapper($th->getSocket(), $th->isDebug()); $messages = $t->getHistory($user->phone, 1); if (count($messages) < 1) { return Response::error('no messages received'); } $message = $messages[0]; if (intval($message->unread) != 1) { return Response::error("no unread messages"); } $text = strtolower(trim($message->text)); $response = ""; switch ($text) { case "help": $response = "These are the things you can ask me:\n" . "help => this info\n" . "remove me => remove my phone number from the system\n" . "send me a photo => invite system to send a photo\n" . "tell me a joke => I send to you something funny\n" . "say me the time => I send to you the current time on my timezone\n" . "weather => I send to you the weather where I live\n"; break; case "weather": $weather = new OpenWeatherApi();
<?php if (!isset($argv[1])) { die("You have to call this program with the peer you want to see current messages\n"); } include_once __DIR__ . '/../vendor/autoload.php'; use TelegramCliWrapper\TelegramCliWrapper; use TelegramCliWrapper\TelegramCliHelper; use TelegramCliWrapper\Models\Dialog; $th = TelegramCliHelper::getInstance(); $t = new TelegramCliWrapper($th->getSocket(), $th->isDebug()); $peer = trim($argv[1]); $n = isset($argv[2]) ? intval($argv[2]) : 5; print "The last {$n} messages with '{$peer}' are " . PHP_EOL . Dialog::getTitles() . PHP_EOL; $history = $t->getHistory($peer, $n); foreach ($history as $historyItem) { print $historyItem . PHP_EOL; } $t->quit();