Exemple #1
0
 /**
  * @return string
  */
 public function getPath()
 {
     if ($this->path == null) {
         $this->path = Telegram::filePath(Telegram::api('getFile', ['file_id' => $this->file_id])['result']['file_path']);
     }
     return $this->path;
 }
<?php

use NielsBot\Core\NielsBot;
use NielsBot\Telegram\Telegram;
use NielsBot\Telegram\TelegramUpdate;
spl_autoload_register(function ($cls) {
    $path = __DIR__ . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $cls) . '.php';
    if (file_exists($path)) {
        require_once $path;
    }
});
Telegram::setToken(file_get_contents(__DIR__ . '/BOT_TOKEN'));
$updates = Telegram::api('getUpdates');
if (!isset($updates['ok']) || !$updates['ok']) {
    die(json_encode($updates));
}
$bot = new NielsBot();
$latestUpdate = null;
foreach ($updates['result'] as $update) {
    $latestUpdate = $update['update_id'];
    new TelegramUpdate($update['message']);
}
if ($latestUpdate != null) {
    Telegram::api('getUpdates', ['offset' => $latestUpdate + 1]);
}
Exemple #3
0
 /**
  * @param CURLFile $file
  * @param string|null $caption = null
  */
 public function sendPhoto($file, $caption = null)
 {
     Telegram::api('sendPhoto', ['chat_id' => $this->id, 'photo' => $file, 'caption' => $caption]);
 }