Example #1
0
<?php

session_start();
include_once __DIR__ . '/../vendor/autoload.php';
use TelegramCliWrapper\TelegramCliWrapper;
use TelegramCliWrapper\TelegramCliHelper;
use TelegramCliWrapper\Storage\LocalFilesStorage;
use TelegramCliWrapper\Response;
use TelegramCliWrapper\Models\User;
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, 100);
$result = array();
foreach ($messages as $message) {
    $result[] = array('text' => nl2br($message->text), 'from' => $message->from->phone, 'to' => $message->to->phone, 'date' => date("y.m.d H:j:s", $message->date));
}
return Response::ok(array('messages' => $result));
Example #2
0
    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();
        $response = $weather->getWeatherInfoAsString();
        break;
    case "say me the time":
        $response = sprintf("The current time here is %s", date("l, F jS Y h:ia"));
        break;
    case "tell me a joke":
        $response = IcndbApi::getAJoke();
        break;
    case "remove me":
        $t->msg($user->phone, "You have been deleted from my contact list");
        $t->del_contact($user->phone);
        $userStorage->remove($user->phone);
        unset($_SESSION['user']);
        header("location: index.php");
        die;
        break;
    case "send me a photo":
        $t->send_photo($user->phone, MediaSelector::getRandomPicture());
        break;
    default:
        $response = "I'm so sorry.\nI'm not ready yet to understand you";
        break;
}
$t->msg($user->phone, $response);
return Response::ok();
Example #3
0
<?php

session_start();
include_once __DIR__ . '/../vendor/autoload.php';
use TelegramCliWrapper\TelegramCliWrapper;
use TelegramCliWrapper\TelegramCliHelper;
use TelegramCliWrapper\Storage\LocalFilesStorage;
use TelegramCliWrapper\Response;
use TelegramCliWrapper\Models\User;
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());
$user = $t->getUserInfo($user->phone);
$result = array('phone' => $user->phone, 'last_name' => $user->last_name, 'first_name' => $user->first_name, 'print_name' => $user->print_name, 'id' => $user->id, 'flags' => $user->flags);
return Response::ok(array('user' => $result));