Exemple #1
0
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();
        $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();
Exemple #2
0
 /**
  * @param UserInterface $user
  * @param MessageInterface $message
  * @return bool
  */
 public function sendNotification(UserInterface $user, MessageInterface $message)
 {
     $this->telegramCli->msg($user->getPhoneNumber()->getValue(), $message->getText());
     return true;
 }
$phone = trim($_POST['phone']);
if (!preg_match("/^\\d{9,15}\$/", $phone)) {
    return Response::error('phone parameter does not seems a phone number');
}
$userStorage = new LocalFilesStorage('user');
$user = $userStorage->getById($phone);
if ($user) {
    return Response::error('phone exists already in this system');
}
$phoneRequested = isset($_SESSION['phone_requested']) ? json_decode($_SESSION['phone_requested'], true) : array();
if (isset($phoneRequested[$phone]) && intval(date("U")) < $phoneRequested[$phone]) {
    return Response::error('phone already requested, you must to wait 15 minutes');
}
$phoneRequested[$phone] = intval(date("U")) + 15 * 60 * 60;
$_SESSION['phone_requested'] = json_encode($phoneRequested);
$th = TelegramCliHelper::getInstance();
$t = new TelegramCliWrapper($th->getSocket(), $th->isDebug());
$user = User::createUser($phone, $phone, "");
$t->addContact($user);
// send message with code in order to validate phone
$r = uniqid();
$user->code = substr($r, rand(1, strlen($r) - 6), 6);
$userStorage->save($user);
$msg = <<<EOD
Welcome to the telegram-cli-wrapper proof of concept
This is the code to access system, please keep it secret.
Code: {$user->code}
*Note: If this message was not solicited by you, please do not take in account.
EOD;
$t->msg($user->phone, $msg);
return Response::ok();
Exemple #4
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");
}
if (!isset($_POST['text'])) {
    return Response::error("text parameter missing");
}
$th = TelegramCliHelper::getInstance();
$t = new TelegramCliWrapper($th->getSocket(), $th->isDebug());
$t->msg($user->phone, $_POST['text']);
return Response::ok();