├── .gitattributes ├── .gitignore ├── CHANGELOG.md ├── README.md ├── composer.json ├── index.php └── src ├── Addons ├── Calendar.php ├── Control.php ├── Functions.php ├── Inline │ ├── Article.php │ ├── Audio.php │ ├── Base │ │ ├── Base.php │ │ ├── InlineQueryResult.php │ │ └── InputMessageContent.php │ ├── Contact.php │ ├── Document.php │ ├── Game.php │ ├── Gif.php │ ├── InputContactMessageContent.php │ ├── InputLocationMessageContent.php │ ├── InputTextMessageContent.php │ ├── InputVenueMessageContent.php │ ├── Location.php │ ├── Mpeg4Gif.php │ ├── Photo.php │ ├── Result.php │ ├── Sticker.php │ ├── Venue.php │ ├── Video.php │ └── Voice.php ├── Keyboard.php ├── MediaGroup.php ├── Payment.php └── Scene.php ├── Core ├── API.php ├── Bot.php ├── Context.php └── Eventer.php ├── Interfaces └── UserInterface.php └── Types ├── Animation.php ├── Audio.php ├── Base └── Base.php ├── CallbackQuery.php ├── Chat.php ├── ChatMember.php ├── ChatPhoto.php ├── ChosenInlineResult.php ├── Contact.php ├── Document.php ├── EncryptedCredentials.php ├── EncryptedPassportElement.php ├── File.php ├── Game.php ├── InlineQuery.php ├── Invoice.php ├── Location.php ├── MaskPosition.php ├── Message.php ├── MessageEntity.php ├── OrderInfo.php ├── PassportData.php ├── PassportFile.php ├── PhotoSize.php ├── PreCheckoutQuery.php ├── ShippingAddress.php ├── ShippingQuery.php ├── Sticker.php ├── SuccessfulPayment.php ├── Update.php ├── User.php ├── UserProfilePhotos.php ├── Venue.php ├── Video.php ├── VideoNote.php └── Voice.php /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea/* 2 | /vendor/* 3 | *.lock -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [2.0.4.2] - 2019-01-13 2 | ### Added 3 | - Добавлен метод api в класс Bot. 4 | - Добавлено уведомление о том, что была вызвана несуществующая сцена. 5 | - Добавлен пресет {STR_S} - обозначающий строку символов с пробелами. 6 | - Добавлен пресет {ANY} - обозначающий строку из любых символов. 7 | ### Deleted 8 | - Удалена папка vendor с пакета. 9 | ## [2.0.4.1] - 2018-12-29 10 | ### Changed 11 | - Исправление багов. 12 | ## [2.0.4] - 2018-12-27 13 | ### Added 14 | - Добавлен метод **loop** (_Bot_), выполняющийся перед каждой обработкой событий(хендлеров). 15 | - Добавлены типы данных Telegram в виде классов. 16 | ### Changed 17 | - Убран дубликат кода связан с биндами событий(хендлеров) для сцен. 18 | - Теперь метод (_Context_) **setUserControl** принимает интерфейс _UserInterface_. 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Telebot 2 | 3 | ### Examples 4 | 5 | ```php 6 | $settings = [ 7 | 'api_token' => '', 8 | 'base_url' => 'https://api.telegram.org/', 9 | 'username' => '', 10 | 'use_proxy' => false, 11 | 'run_type' => 0, // 0 - Polling, 1 - Webhook 12 | 'hook_reply' => true, 13 | 'debug_mode' => false, 14 | 'timing' => false, 15 | 'log_mode' => false, 16 | 'log_path' => __DIR__ . DIRECTORY_SEPARATOR . 'tb_log', 17 | 'proxy' => [ 18 | 'authorization' => '', 19 | 'server' => '', 20 | 'proxy_type' => '', 21 | ] 22 | ]; 23 | 24 | use Telebot\Core\Bot, 25 | Telebot\Core\Context; 26 | 27 | $bot = new Bot($settings); 28 | $bot->cmd('start', function(Context $ctx){ 29 | $ctx->reply('Hi! Send me a sticker'); 30 | }); 31 | 32 | $bot->onMessage('sticker', function (Context $ctx){ 33 | $ctx->reply('Nice:)'); 34 | }); 35 | 36 | $bot->hears('bye', function (Context $ctx){ 37 | $ctx->reply('bye bye...'); 38 | }); 39 | 40 | $bot->txt('say {text:str}', function (Context $ctx){ 41 | $ctx->reply($ctx->params['text']); 42 | }); 43 | 44 | $bot->run(); 45 | ``` 46 | 47 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "monarkhov/telebot", 3 | "description": "Telebot Framework", 4 | "type": "library", 5 | "license": "MIT", 6 | "version": "2.0.4.2", 7 | "keywords": ["telegram", "telebot", "bot", "PHP", "video", "stickers", "audio", "files"], 8 | "authors": [ 9 | { 10 | "name": "Askold Monarkhov", 11 | "email": "askold.monarkhov@gmail.com" 12 | } 13 | ], 14 | "require": { 15 | "php": ">=7.1.0", 16 | "gabordemooij/redbean": "dev-master" 17 | }, 18 | "minimum-stability": "stable", 19 | "autoload": { 20 | "psr-4": { 21 | "Telebot\\": "src" 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | loop(function($update) { 28 | //var_dump($update); 29 | }); 30 | $bot->onMessage('sticker', function (Context $ctx){ 31 | $ctx->reply('Nice:)'); 32 | }); 33 | 34 | $bot->run(); -------------------------------------------------------------------------------- /src/Addons/Calendar.php: -------------------------------------------------------------------------------- 1 | ctx = $ctx; 24 | $this->caption = $caption; 25 | $this->menuHandler = new Keyboard(Keyboard::INLINE); 26 | $this->allMonth = $allMonth; 27 | } 28 | 29 | public function ignoreDateRange($startDate, $endDate) 30 | { 31 | $this->ignoreList[] = ['start' => $startDate, 'end' => $endDate]; 32 | } 33 | 34 | public function ignoreDay($day) 35 | { 36 | $this->ignoreDateRange(mktime(0, 0, 0, date('m', $day), date('d', $day), date('Y', $day)), mktime(23, 59, 59, date('m', $day), date('d', $day), date('Y', $day))); 37 | } 38 | 39 | private function compareWithIgnoreList($date) 40 | { 41 | foreach ($this->ignoreList as $dateRange) { 42 | if ($dateRange['start'] <= $date and $date <= $dateRange['end']) return true; // попал в список игнорирования 43 | } 44 | return false; // не попал в список игнорирования 45 | } 46 | 47 | public function build($time = null) 48 | { 49 | $time = ($time == null) ? time() : $time; 50 | $today = mktime(0, 0, 0, date('m', $time), date('d', time()), date('Y', $time)); 51 | $this->menuHandler->row(Keyboard::btn(date('F', $today) . ' ' . date('Y', $today), 'calendar.ignore')); 52 | $this->menuHandler->row(Keyboard::btn('Пн', 'calendar.ignore'), Keyboard::btn('Вт', 'calendar.ignore'), Keyboard::btn('Ср', 'calendar.ignore'), Keyboard::btn('Чт', 'calendar.ignore'), Keyboard::btn('Пт', 'calendar.ignore'), Keyboard::btn('Сб', 'calendar.ignore'), Keyboard::btn('Вс', 'calendar.ignore')); 53 | for ($posMonth = 1; $posMonth <= date('t', $today);) { 54 | $format = [ 55 | 'Mon' => '', 56 | 'Tue' => '', 57 | 'Wed' => '', 58 | 'Thu' => '', 59 | 'Fri' => '', 60 | 'Sat' => '', 61 | 'Sun' => '', 62 | ]; 63 | foreach ($format as $day => $value) { 64 | if (date('D', mktime(0, 0, 0, date('m', $today), $posMonth, date('Y', $today))) == $day AND $posMonth <= date('t', $today)) { 65 | //$format[$day] = Keyboard::btn($posMonth, 'calendar.d/'.mktime(0, 0, 0, date('m', $today), $posMonth, date('Y', $today))); 66 | $currentDay = mktime(0, 0, 0, date('m', $today), $posMonth, date('Y', $today)); 67 | if ($this->compareWithIgnoreList($currentDay)) $format[$day] = Keyboard::btn(' ', 'calendar.ignore'); 68 | else $format[$day] = Keyboard::btn($posMonth, 'calendar.d/' . $currentDay); 69 | if ($posMonth <= date('t', $today)) $posMonth++; 70 | } else $format[$day] = Keyboard::btn(' ', 'calendar.ignore'); 71 | 72 | } 73 | $this->menuHandler->arrayRow($format); 74 | } 75 | if ($this->allMonth) { 76 | $this->menuHandler->row(Keyboard::btn('<', 'calendar.m/' . strtotime('-1 month', $today)), Keyboard::btn(' ', 'calendar/ignore'), Keyboard::btn('>', 'calendar.m/' . strtotime('+1 month', $today))); 77 | /*$navButtons = []; 78 | $prev = strtotime('-1 month', $today); 79 | if($this->compareWithIgnoreList($prev)) $navButtons[] = Keyboard::btn('<', 'calendar.m/'.$prev); 80 | else $navButtons[] = Keyboard::btn(' ', 'calendar.ignore'); 81 | $navButtons[] = Keyboard::btn(' ', 'calendar.ignore'); 82 | $next = strtotime('+1 month', $today); 83 | if($this->compareWithIgnoreList($next)) $navButtons[] = Keyboard::btn('>', 'calendar.m/'.$next); 84 | else $navButtons[] = Keyboard::btn(' ', 'calendar.ignore'); 85 | $this->menuHandler->arrayRow($navButtons);*/ 86 | } 87 | return $this->menuHandler; 88 | } 89 | } -------------------------------------------------------------------------------- /src/Addons/Control.php: -------------------------------------------------------------------------------- 1 | getUserID()]); #- Привело к багу 18 | R::useWriterCache(true); 19 | //$user = R::convertToBean('tgusers', R::getRow('select * from tgusers where user_id = ?', [$ctx->getUserID()])); 20 | if($user==null) { 21 | $user = R::dispense('tgusers'); 22 | $user->user_id = $ctx->getUserID(); 23 | $user->state = ''; 24 | $user->storage = $this->initStorage(); 25 | $user = R::load('tgusers', R::store($user)); 26 | 27 | } 28 | $this->__user = $user; 29 | $this->openStorage(); 30 | } 31 | 32 | public function initStorage() 33 | { 34 | return json_encode([]); 35 | } 36 | 37 | private function openStorage() 38 | { 39 | $this->__storage = json_decode($this->__user->storage, true); 40 | } 41 | 42 | public function addToStorage($element, $value) { 43 | $this->__storage[$element] = $value; 44 | return $this; 45 | } 46 | 47 | public function getFromStorage($element) { 48 | $el = explode('.', $element); 49 | $output = $this->__storage; 50 | foreach ($el as $e) { 51 | if(isset($output[$e])) $output = $output[$e]; 52 | else $output = null; 53 | } 54 | return $output; 55 | } 56 | 57 | public function delStorageElement($element) { 58 | unset($this->__storage[$element]); 59 | return $this; 60 | } 61 | 62 | /** 63 | * @return $this 64 | */ 65 | public function clearStorage() { 66 | $this->__storage = []; 67 | return $this; 68 | } 69 | 70 | /** 71 | * @return string 72 | */ 73 | public function getState() { 74 | return $this->state; 75 | } 76 | 77 | public function setState($key) { 78 | $this->state = $key; 79 | } 80 | 81 | public function saveStorage() { 82 | $this->storage = json_encode($this->__storage); 83 | } 84 | 85 | public function set(array $components, $values) 86 | { 87 | if (is_array($values)) { 88 | if(count($components)==count($values)) { 89 | foreach ($components as $k => $component) { 90 | $this->__user->$component = $values[$k]; 91 | } 92 | $this->save(); 93 | } 94 | } else { 95 | foreach ($components as $k => $component) { 96 | $this->__user->$component = $values; 97 | } 98 | $this->save(); 99 | } 100 | } 101 | 102 | public function __get($component) 103 | { 104 | return $this->__user->$component; 105 | } 106 | 107 | public function __set($component, $value) 108 | { 109 | $this->__user->$component = $value; 110 | $this->save(); 111 | } 112 | 113 | private function save() 114 | { 115 | R::store($this->__user); 116 | } 117 | } -------------------------------------------------------------------------------- /src/Addons/Functions.php: -------------------------------------------------------------------------------- 1 | 4 && $number %100 < 20) ? 2 : $cases[min($number%10, 5)] ]; 12 | } 13 | 14 | public static function genLetters($length){ 15 | $code = ''; 16 | $letters = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890"; 17 | while($length--) 18 | $code .= $letters{rand(0,strlen($letters)-1)}; 19 | return $code; 20 | } 21 | 22 | public static function ctime($name){ 23 | if(isset($GLOBALS['microtime'][$name])){ 24 | $start = $GLOBALS['microtime'][$name]; 25 | unset($GLOBALS['microtime'][$name]); 26 | return '('.round(microtime(true) - $start, 3)." sec)"; 27 | }else{ 28 | $GLOBALS['microtime'][$name] = microtime(true); 29 | } 30 | } 31 | 32 | public static function is_int2($var){ //Проверяет состоит ли текст только из чисел 33 | return (bool)!strcmp((int)$var,$var); 34 | } 35 | 36 | public static function time_difference($time, $params='ymdhis') 37 | { 38 | $YEAR = 31536000; 39 | $MONTH = 2592000; 40 | $WEEK = 604800; 41 | $DAY = 86400; 42 | $HOUR = 3600; 43 | $MINUTE = 60; 44 | $result = []; 45 | 46 | if($time < 0) 47 | { 48 | $result['invert'] = false; 49 | }else{ 50 | $result['invert'] = true; 51 | } 52 | 53 | $time = abs($time); 54 | 55 | if(strpos($params, 'y') !== false) 56 | { 57 | $result['y'] = floor( $time / $YEAR ); 58 | $time = $time - ( $result['y'] * $YEAR ); 59 | } 60 | 61 | if(strpos($params, 'm') !== false) 62 | { 63 | $result['m'] = floor( $time / $MONTH ); 64 | $time = $time - ( $result['m'] * $MONTH ); 65 | } 66 | 67 | if(strpos($params, 'w') !== false) 68 | { 69 | $result['w'] = floor( $time / $WEEK ); 70 | $time = $time - ( $result['w'] * $WEEK ); 71 | } 72 | 73 | if(strpos($params, 'd') !== false) 74 | { 75 | $result['d'] = floor( $time / $DAY ); 76 | $time = $time - ( $result['d'] * $DAY ); 77 | } 78 | 79 | if(strpos($params, 'h') !== false) 80 | { 81 | $result['h'] = floor( $time / $HOUR ); 82 | $time = $time - ( $result['h'] * $HOUR ); 83 | } 84 | 85 | if(strpos($params, 'i') !== false) 86 | { 87 | $result['i'] = floor( $time / $MINUTE ); 88 | $time = $time - ( $result['i'] * $MINUTE ); 89 | } 90 | 91 | if(strpos($params, 's') !== false) 92 | { 93 | $result['s'] = $time; 94 | } 95 | 96 | return $result; 97 | } 98 | 99 | public static function time_difference_string($time, $params='ymdhis'){ 100 | $diff = self::time_difference($time, $params); 101 | 102 | foreach($diff AS $key => $value) 103 | { 104 | switch($key){ 105 | case 's': 106 | if(!$value) break; 107 | $add[] = self::declofnum($value, ['секунда', 'секунды', 'секунд']); 108 | break; 109 | case 'i': 110 | if(!$value) break; 111 | $add[] = self::declofnum($value, ['минута', 'минуты', 'минут']); 112 | break; 113 | case 'h': 114 | if(!$value) break; 115 | $add[] = self::declofnum($value, ['час', 'часа', 'часов']); 116 | break; 117 | case 'd': 118 | if(!$value) break; 119 | $add[] = self::declofnum($value, ['день', 'дня', 'дней']); 120 | break; 121 | case 'w': 122 | if(!$value) break; 123 | $add[] = self::declofnum($value, ['неделя', 'недели', 'недель']); 124 | break; 125 | case 'm': 126 | if(!$value) break; 127 | $add[] = self::declofnum($value, ['месяц', 'месяца', 'месяцев']); 128 | break; 129 | case 'y': 130 | if(!$value) break; 131 | $add[] = self::declofnum($value, ['год', 'года', 'лет']); 132 | break; 133 | } 134 | } 135 | $text = ''; 136 | $count = count($add); 137 | for($i=0;$i<$count;$i++) 138 | { 139 | if($i+2==$count) 140 | { 141 | $text .= $add[$i].' и '; 142 | }elseif($i+1==$count) 143 | { 144 | $text .= $add[$i]; 145 | }else{ 146 | $text .= $add[$i].', '; 147 | } 148 | } 149 | return $text; 150 | } 151 | 152 | public static function strtosec($string){ 153 | $YEAR = 31536000; 154 | $MONTH = 2592000; 155 | $WEEK = 604800; 156 | $DAY = 86400; 157 | $HOUR = 3600; 158 | $MINUTE = 60; 159 | 160 | $result = 0; 161 | 162 | $number = 0; 163 | $symb = null; 164 | foreach(explode(' ', $string) AS $str){ 165 | if(strpos($str, '+') === 0) 166 | { 167 | $symb = true; 168 | $number = substr($str, 1); 169 | }elseif(strpos('-', $str) === 0){ 170 | $symb = false; 171 | $number = substr($str, 1); 172 | }elseif(strpos($str, 'second') === 0){ 173 | if($symb) 174 | { 175 | $result += $number; 176 | }else{ 177 | $result -= $number; 178 | } 179 | }elseif(strpos($str, 'minute') === 0){ 180 | if($symb) 181 | { 182 | $result += $MINUTE*$number; 183 | }else{ 184 | $result -= $MINUTE*$number; 185 | } 186 | }elseif(strpos($str, 'hour') === 0){ 187 | if($symb) 188 | { 189 | $result += $HOUR*$number; 190 | }else{ 191 | $result -= $HOUR*$number; 192 | } 193 | }elseif(strpos($str, 'day') === 0){ 194 | if($symb) 195 | { 196 | $result += $DAY*$number; 197 | }else{ 198 | $result -= $DAY*$number; 199 | } 200 | }elseif(strpos($str, 'week') === 0){ 201 | if($symb) 202 | { 203 | $result += $WEEK*$number; 204 | }else{ 205 | $result -= $WEEK*$number; 206 | } 207 | }elseif(strpos($str, 'month') === 0){ 208 | if($symb) 209 | { 210 | $result += $MONTH*$number; 211 | }else{ 212 | $result -= $MONTH*$number; 213 | } 214 | }elseif(strpos($str, 'year') === 0){ 215 | if($symb) 216 | { 217 | $result += $YEAR*$number; 218 | }else{ 219 | $result -= $YEAR*$number; 220 | } 221 | } 222 | } 223 | return $result; 224 | } 225 | 226 | } -------------------------------------------------------------------------------- /src/Addons/Inline/Article.php: -------------------------------------------------------------------------------- 1 | out['type'] = 'article'; 14 | $this->out['id'] = $id; 15 | } 16 | 17 | public function title($title) 18 | { 19 | $this->out['title'] = $title; 20 | return $this; 21 | } 22 | 23 | public function url($url) 24 | { 25 | $this->out['url'] = $url; 26 | return $this; 27 | } 28 | 29 | public function hideUrl(bool $hide_url) 30 | { 31 | $this->out['hide_url'] = $hide_url; 32 | return $this; 33 | } 34 | 35 | public function description($description) 36 | { 37 | $this->out['description'] = $description; 38 | return $this; 39 | } 40 | 41 | public function thumbUrl($thumb_url) 42 | { 43 | $this->out['thumb_url'] = $thumb_url; 44 | return $this; 45 | } 46 | 47 | public function thumbWidth($thumb_width) 48 | { 49 | $this->out['thumb_width'] = $thumb_width; 50 | return $this; 51 | } 52 | 53 | public function thumbHeight($thumb_height) 54 | { 55 | $this->out['thumb_height'] = $thumb_height; 56 | return $this; 57 | } 58 | } -------------------------------------------------------------------------------- /src/Addons/Inline/Audio.php: -------------------------------------------------------------------------------- 1 | out['type'] = 'audio'; 13 | $this->out['id'] = $id; 14 | } 15 | 16 | public function audioUrl($audioUrl) 17 | { 18 | $this->out['audio_url'] = $audioUrl; 19 | return $this; 20 | } 21 | 22 | public function audioFileID($audioFileID) 23 | { 24 | $this->out['audio_file_id'] = $audioFileID; 25 | return $this; 26 | } 27 | 28 | public function title($title) 29 | { 30 | $this->out['title'] = $title; 31 | return $this; 32 | } 33 | 34 | public function caption($caption) 35 | { 36 | $this->out['caption'] = $caption; 37 | return $this; 38 | } 39 | 40 | public function parseMode($parseMode) 41 | { 42 | $this->out['parse_mode'] = $parseMode; 43 | return $this; 44 | } 45 | 46 | public function performer($performer) 47 | { 48 | $this->out['performer'] = $performer; 49 | return $this; 50 | } 51 | 52 | public function audioDuration($audioDuration) 53 | { 54 | $this->out['audio_duration'] = $audioDuration; 55 | return $this; 56 | } 57 | } -------------------------------------------------------------------------------- /src/Addons/Inline/Base/Base.php: -------------------------------------------------------------------------------- 1 | out; 13 | } 14 | } -------------------------------------------------------------------------------- /src/Addons/Inline/Base/InlineQueryResult.php: -------------------------------------------------------------------------------- 1 | out['input_message_content'] = $input_message_content->getAsObject(); 11 | return $this; 12 | } 13 | 14 | public function keyboard(array $keyboard) 15 | { 16 | $this->out['reply_markup'] = $keyboard; 17 | return $this; 18 | } 19 | } -------------------------------------------------------------------------------- /src/Addons/Inline/Base/InputMessageContent.php: -------------------------------------------------------------------------------- 1 | out['type'] = 'contact'; 13 | $this->out['id'] = $id; 14 | } 15 | 16 | public function phoneNumber($phoneNumber) 17 | { 18 | $this->out['phone_number'] = $phoneNumber; 19 | return $this; 20 | } 21 | 22 | public function firstName($firstName) 23 | { 24 | $this->out['first_name'] = $firstName; 25 | return $this; 26 | } 27 | 28 | public function lastName($lastName) 29 | { 30 | $this->out['last_name'] = $lastName; 31 | return $this; 32 | } 33 | 34 | public function vcard($vcard) 35 | { 36 | $this->out['vcard'] = $vcard; 37 | return $this; 38 | } 39 | 40 | public function thumbUrl($thumb_url) 41 | { 42 | $this->out['thumb_url'] = $thumb_url; 43 | return $this; 44 | } 45 | 46 | public function thumbWidth($thumb_width) 47 | { 48 | $this->out['thumb_width'] = $thumb_width; 49 | return $this; 50 | } 51 | 52 | public function thumbHeight($thumb_height) 53 | { 54 | $this->out['thumb_height'] = $thumb_height; 55 | return $this; 56 | } 57 | } -------------------------------------------------------------------------------- /src/Addons/Inline/Document.php: -------------------------------------------------------------------------------- 1 | out['type'] = 'document'; 13 | $this->out['id'] = $id; 14 | } 15 | 16 | public function title($title) 17 | { 18 | $this->out['title'] = $title; 19 | return $this; 20 | } 21 | 22 | public function caption($caption) 23 | { 24 | $this->out['caption'] = $caption; 25 | return $this; 26 | } 27 | 28 | public function parseMode($parseMode) 29 | { 30 | $this->out['parse_mode'] = $parseMode; 31 | return $this; 32 | } 33 | 34 | public function documentUrl($documentUrl) 35 | { 36 | $this->out['document_url'] = $documentUrl; 37 | return $this; 38 | } 39 | 40 | public function documentFileID($documentFileID) 41 | { 42 | $this->out['document_file_id'] = $documentFileID; 43 | return $this; 44 | } 45 | 46 | 47 | public function mimeType($mimeType) 48 | { 49 | $this->out['mime_type'] = $mimeType; 50 | return $this; 51 | } 52 | 53 | public function description($description) 54 | { 55 | $this->out['description'] = $description; 56 | return $this; 57 | } 58 | 59 | public function thumbUrl($thumb_url) 60 | { 61 | $this->out['thumb_url'] = $thumb_url; 62 | return $this; 63 | } 64 | 65 | public function thumbWidth($thumb_width) 66 | { 67 | $this->out['thumb_width'] = $thumb_width; 68 | return $this; 69 | } 70 | 71 | public function thumbHeight($thumb_height) 72 | { 73 | $this->out['thumb_height'] = $thumb_height; 74 | return $this; 75 | } 76 | } -------------------------------------------------------------------------------- /src/Addons/Inline/Game.php: -------------------------------------------------------------------------------- 1 | out['type'] = 'game'; 13 | $this->out['id'] = $id; 14 | } 15 | 16 | public function gameShortName($gameShortName) 17 | { 18 | $this->out['game_short_name'] = $gameShortName; 19 | return $this; 20 | } 21 | } -------------------------------------------------------------------------------- /src/Addons/Inline/Gif.php: -------------------------------------------------------------------------------- 1 | out['type'] = 'gif'; 13 | $this->out['id'] = $id; 14 | } 15 | 16 | public function gifUrl($GifUrl) 17 | { 18 | $this->out['gif_url'] = $GifUrl; 19 | return $this; 20 | } 21 | 22 | public function gifFileID($gifFileID) 23 | { 24 | $this->out['gif_file_id'] = $gifFileID; 25 | return $this; 26 | } 27 | 28 | public function gifWidth($gifWidth) 29 | { 30 | $this->out['gif_width'] = $gifWidth; 31 | return $this; 32 | } 33 | 34 | public function gifHeight($gifHeight) 35 | { 36 | $this->out['gif_height'] = $gifHeight; 37 | return $this; 38 | } 39 | 40 | public function gifDuration($gifDuration) 41 | { 42 | $this->out['gif_duration'] = $gifDuration; 43 | return $this; 44 | } 45 | 46 | public function thumbUrl($thumb_url) 47 | { 48 | $this->out['thumb_url'] = $thumb_url; 49 | return $this; 50 | } 51 | 52 | public function title($title) 53 | { 54 | $this->out['title'] = $title; 55 | return $this; 56 | } 57 | 58 | public function caption($caption) 59 | { 60 | $this->out['caption'] = $caption; 61 | return $this; 62 | } 63 | 64 | public function parseMode($parseMode) 65 | { 66 | $this->out['parse_mode'] = $parseMode; 67 | return $this; 68 | } 69 | } -------------------------------------------------------------------------------- /src/Addons/Inline/InputContactMessageContent.php: -------------------------------------------------------------------------------- 1 | out['phone_number'] = $phoneNumber; 13 | return $this; 14 | } 15 | 16 | public function firstName($firstName) 17 | { 18 | $this->out['first_name'] = $firstName; 19 | return $this; 20 | } 21 | 22 | public function lastName($lastName) 23 | { 24 | $this->out['last_name'] = $lastName; 25 | return $this; 26 | } 27 | 28 | public function vcard($vcard) 29 | { 30 | $this->out['vcard'] = $vcard; 31 | return $this; 32 | } 33 | } -------------------------------------------------------------------------------- /src/Addons/Inline/InputLocationMessageContent.php: -------------------------------------------------------------------------------- 1 | out['latitude'] = $latitude; 13 | return $this; 14 | } 15 | 16 | public function longitude($longitude) 17 | { 18 | $this->out['longitude'] = $longitude; 19 | return $this; 20 | } 21 | 22 | public function livePeriod($livePeriod) 23 | { 24 | $this->out['live_period'] = $livePeriod; 25 | return $this; 26 | } 27 | } -------------------------------------------------------------------------------- /src/Addons/Inline/InputTextMessageContent.php: -------------------------------------------------------------------------------- 1 | out['message_text'] = $text; 13 | return $this; 14 | } 15 | 16 | public function parseMode($parse_mode) 17 | { 18 | $this->out['parse_mode'] = $parse_mode; 19 | return $this; 20 | } 21 | 22 | public function disableWebPagePreview(bool $disable_web_page_preview) 23 | { 24 | $this->out['disable_web_page_preview'] = $disable_web_page_preview; 25 | return $this; 26 | } 27 | } -------------------------------------------------------------------------------- /src/Addons/Inline/InputVenueMessageContent.php: -------------------------------------------------------------------------------- 1 | out['latitude'] = $latitude; 13 | return $this; 14 | } 15 | 16 | public function longitude($longitude) 17 | { 18 | $this->out['longitude'] = $longitude; 19 | return $this; 20 | } 21 | 22 | public function title($title) 23 | { 24 | $this->out['title'] = $title; 25 | return $this; 26 | } 27 | 28 | public function address($address) 29 | { 30 | $this->out['address'] = $address; 31 | return $this; 32 | } 33 | 34 | public function foursquareID($foursquareID) 35 | { 36 | $this->out['foursquare_id'] = $foursquareID; 37 | return $this; 38 | } 39 | 40 | public function foursquareType($foursquareType) 41 | { 42 | $this->out['foursquare_type'] = $foursquareType; 43 | return $this; 44 | } 45 | } -------------------------------------------------------------------------------- /src/Addons/Inline/Location.php: -------------------------------------------------------------------------------- 1 | out['type'] = 'location'; 13 | $this->out['id'] = $id; 14 | } 15 | 16 | public function latitude($latitude) 17 | { 18 | $this->out['latitude'] = $latitude; 19 | return $this; 20 | } 21 | 22 | public function longitude($longitude) 23 | { 24 | $this->out['longitude'] = $longitude; 25 | return $this; 26 | } 27 | 28 | public function title($title) 29 | { 30 | $this->out['title'] = $title; 31 | return $this; 32 | } 33 | 34 | public function livePeriod($livePeriod) 35 | { 36 | $this->out['live_period'] = $livePeriod; 37 | return $this; 38 | } 39 | 40 | public function thumbUrl($thumb_url) 41 | { 42 | $this->out['thumb_url'] = $thumb_url; 43 | return $this; 44 | } 45 | 46 | public function thumbWidth($thumb_width) 47 | { 48 | $this->out['thumb_width'] = $thumb_width; 49 | return $this; 50 | } 51 | 52 | public function thumbHeight($thumb_height) 53 | { 54 | $this->out['thumb_height'] = $thumb_height; 55 | return $this; 56 | } 57 | } -------------------------------------------------------------------------------- /src/Addons/Inline/Mpeg4Gif.php: -------------------------------------------------------------------------------- 1 | out['type'] = 'mpeg4_gif'; 13 | $this->out['id'] = $id; 14 | } 15 | 16 | public function mpeg4Url($mpeg4Url) 17 | { 18 | $this->out['mpeg4_url'] = $mpeg4Url; 19 | return $this; 20 | } 21 | 22 | public function mpeg4FileID($mpeg4FileID) 23 | { 24 | $this->out['mpeg4_file_id'] = $mpeg4FileID; 25 | return $this; 26 | } 27 | 28 | public function mpeg4Width($mpeg4Width) 29 | { 30 | $this->out['mpeg4_width'] = $mpeg4Width; 31 | return $this; 32 | } 33 | 34 | public function mpeg4Height($mpeg4Height) 35 | { 36 | $this->out['mpeg4_height'] = $mpeg4Height; 37 | return $this; 38 | } 39 | 40 | public function mpeg4Duration($mpeg4Duration) 41 | { 42 | $this->out['mpeg4_duration'] = $mpeg4Duration; 43 | return $this; 44 | } 45 | 46 | public function thumbUrl($thumb_url) 47 | { 48 | $this->out['thumb_url'] = $thumb_url; 49 | return $this; 50 | } 51 | 52 | public function title($title) 53 | { 54 | $this->out['title'] = $title; 55 | return $this; 56 | } 57 | 58 | public function caption($caption) 59 | { 60 | $this->out['caption'] = $caption; 61 | return $this; 62 | } 63 | 64 | public function parseMode($parseMode) 65 | { 66 | $this->out['parse_mode'] = $parseMode; 67 | return $this; 68 | } 69 | } -------------------------------------------------------------------------------- /src/Addons/Inline/Photo.php: -------------------------------------------------------------------------------- 1 | out['type'] = 'photo'; 13 | $this->out['id'] = $id; 14 | } 15 | 16 | public function photoFileID($photoFileID) 17 | { 18 | $this->out['photo_file_id'] = $photoFileID; 19 | return $this; 20 | } 21 | 22 | public function photoUrl($photoUrl) 23 | { 24 | $this->out['photo_url'] = $photoUrl; 25 | return $this; 26 | } 27 | 28 | public function thumbUrl($thumb_url) 29 | { 30 | $this->out['thumb_url'] = $thumb_url; 31 | return $this; 32 | } 33 | 34 | public function photoWidth($photoWidth) 35 | { 36 | $this->out['photo_width'] = $photoWidth; 37 | return $this; 38 | } 39 | 40 | public function photoHeight($photoHeight) 41 | { 42 | $this->out['photo_height'] = $photoHeight; 43 | return $this; 44 | } 45 | 46 | public function title($title) 47 | { 48 | $this->out['title'] = $title; 49 | return $this; 50 | } 51 | 52 | public function description($description) 53 | { 54 | $this->out['description'] = $description; 55 | return $this; 56 | } 57 | 58 | public function caption($caption) 59 | { 60 | $this->out['caption'] = $caption; 61 | return $this; 62 | } 63 | 64 | public function parseMode($parseMode) 65 | { 66 | $this->out['parse_mode'] = $parseMode; 67 | return $this; 68 | } 69 | 70 | } -------------------------------------------------------------------------------- /src/Addons/Inline/Result.php: -------------------------------------------------------------------------------- 1 | addResult($result); 17 | } 18 | } 19 | 20 | public function addArray($results) 21 | { 22 | call_user_func_array([$this, 'add'], $results); 23 | } 24 | 25 | private function addResult(InlineQueryResult $result) 26 | { 27 | $this->results[] = $result->getAsObject(); 28 | } 29 | 30 | public function __toString() 31 | { 32 | return json_encode($this->results); 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /src/Addons/Inline/Sticker.php: -------------------------------------------------------------------------------- 1 | out['type'] = 'sticker'; 13 | $this->out['id'] = $id; 14 | } 15 | 16 | public function stickerFileID($stickerFileID) 17 | { 18 | $this->out['voice_file_id'] = $stickerFileID; 19 | return $this; 20 | } 21 | } -------------------------------------------------------------------------------- /src/Addons/Inline/Venue.php: -------------------------------------------------------------------------------- 1 | out['type'] = 'venue'; 13 | $this->out['id'] = $id; 14 | } 15 | 16 | public function latitude($latitude) 17 | { 18 | $this->out['latitude'] = $latitude; 19 | return $this; 20 | } 21 | 22 | public function longitude($longitude) 23 | { 24 | $this->out['longitude'] = $longitude; 25 | return $this; 26 | } 27 | 28 | public function title($title) 29 | { 30 | $this->out['title'] = $title; 31 | return $this; 32 | } 33 | 34 | public function livePeriod($livePeriod) 35 | { 36 | $this->out['live_period'] = $livePeriod; 37 | return $this; 38 | } 39 | 40 | public function thumbUrl($thumb_url) 41 | { 42 | $this->out['thumb_url'] = $thumb_url; 43 | return $this; 44 | } 45 | 46 | public function thumbWidth($thumb_width) 47 | { 48 | $this->out['thumb_width'] = $thumb_width; 49 | return $this; 50 | } 51 | 52 | public function thumbHeight($thumb_height) 53 | { 54 | $this->out['thumb_height'] = $thumb_height; 55 | return $this; 56 | } 57 | } -------------------------------------------------------------------------------- /src/Addons/Inline/Video.php: -------------------------------------------------------------------------------- 1 | out['type'] = 'video'; 13 | $this->out['id'] = $id; 14 | } 15 | 16 | public function videoFileID($videoFileID) 17 | { 18 | $this->out['video_file_id'] = $videoFileID; 19 | return $this; 20 | } 21 | 22 | public function videoUrl($videoUrl) 23 | { 24 | $this->out['video_url'] = $videoUrl; 25 | return $this; 26 | } 27 | 28 | public function mimeType($mimeType) 29 | { 30 | $this->out['mime_type'] = $mimeType; 31 | return $this; 32 | } 33 | 34 | public function thumbUrl($thumb_url) 35 | { 36 | $this->out['thumb_url'] = $thumb_url; 37 | return $this; 38 | } 39 | 40 | public function title($title) 41 | { 42 | $this->out['title'] = $title; 43 | return $this; 44 | } 45 | 46 | public function caption($caption) 47 | { 48 | $this->out['caption'] = $caption; 49 | return $this; 50 | } 51 | 52 | public function parseMode($parseMode) 53 | { 54 | $this->out['parse_mode'] = $parseMode; 55 | return $this; 56 | } 57 | 58 | public function videoWidth($videoWidth) 59 | { 60 | $this->out['video_width'] = $videoWidth; 61 | return $this; 62 | } 63 | 64 | public function videoHeight($videoHeight) 65 | { 66 | $this->out['video_height'] = $videoHeight; 67 | return $this; 68 | } 69 | 70 | public function videoDuration($videoDuration) 71 | { 72 | $this->out['video_duration'] = $videoDuration; 73 | return $this; 74 | } 75 | 76 | public function description($description) 77 | { 78 | $this->out['description'] = $description; 79 | return $this; 80 | } 81 | } -------------------------------------------------------------------------------- /src/Addons/Inline/Voice.php: -------------------------------------------------------------------------------- 1 | out['type'] = 'voice'; 13 | $this->out['id'] = $id; 14 | } 15 | 16 | public function voiceFileID($voiceFileID) 17 | { 18 | $this->out['voice_file_id'] = $voiceFileID; 19 | return $this; 20 | } 21 | 22 | public function voiceUrl($voiceUrl) 23 | { 24 | $this->out['voice_url'] = $voiceUrl; 25 | return $this; 26 | } 27 | 28 | public function title($title) 29 | { 30 | $this->out['title'] = $title; 31 | return $this; 32 | } 33 | 34 | public function caption($caption) 35 | { 36 | $this->out['caption'] = $caption; 37 | return $this; 38 | } 39 | 40 | public function parseMode($parseMode) 41 | { 42 | $this->out['parse_mode'] = $parseMode; 43 | return $this; 44 | } 45 | 46 | public function voiceDuration($voiceDuration) 47 | { 48 | $this->out['voice_duration'] = $voiceDuration; 49 | return $this; 50 | } 51 | } -------------------------------------------------------------------------------- /src/Addons/Keyboard.php: -------------------------------------------------------------------------------- 1 | type = $type; 17 | } 18 | 19 | public static function delete(bool $selective = false) 20 | { 21 | return json_encode(['remove_keyboard' => true, 'selective' => $selective]); 22 | } 23 | 24 | private function button($text, $t = false) 25 | { 26 | if ($t) return ['text' => $text, 'callback_data' => $text]; 27 | return ['text' => $text]; 28 | } 29 | 30 | public static function locationBtn($text) 31 | { 32 | return ['text' => $text, 'request_location' => true]; 33 | } 34 | 35 | public static function contactBtn($text) 36 | { 37 | return ['text' => $text, 'request_contact' => true]; 38 | } 39 | 40 | public static function urlBtn($text, $url) 41 | { 42 | return ['text' => $text, 'url' => $url]; 43 | } 44 | 45 | public static function payBtn($text) 46 | { 47 | return ['text' => $text, 'pay' => true]; 48 | } 49 | 50 | public static function btn($text, $data = null) 51 | { 52 | if (is_null($data)) $data = $text; 53 | return ['text' => $text, 'callback_data' => $data]; 54 | } 55 | 56 | public function row() 57 | { 58 | $buttons = func_get_args(); 59 | $row = []; 60 | foreach ($buttons as $button) { 61 | if (is_array($button)) { 62 | if ($this->type != self::INLINE AND isset($button['callback_data'])) unset($button['callback_data']); 63 | $row[] = $button; 64 | } else { 65 | if ($this->type == self::INLINE) $row[] = $this->button($button, true); 66 | else $row[] = $this->button($button); 67 | } 68 | } 69 | $this->out[$this->type][] = $row; 70 | return $this; 71 | } 72 | 73 | public function autoRows($buttons, $inLine) 74 | { 75 | $rows = array_chunk($buttons, $inLine); 76 | foreach ($rows as $row) { 77 | $tRow = []; 78 | foreach ($row as $button) { 79 | if (is_array($button)) { 80 | if ($this->type != self::INLINE AND isset($button['callback_data'])) unset($button['callback_data']); 81 | $tRow[] = $button; 82 | } else { 83 | if ($this->type == self::INLINE) $tRow[] = $this->button($button, true); 84 | else $tRow[] = $this->button($button); 85 | } 86 | } 87 | $this->out[$this->type][] = $tRow; 88 | } 89 | } 90 | 91 | public function arrayRow($buttons) 92 | { 93 | call_user_func_array([$this, 'row'], $buttons); 94 | } 95 | 96 | public function property($name, $value) 97 | { 98 | $this->out[$name] = $value; 99 | return $this; 100 | } 101 | 102 | public function build() { 103 | return json_encode($this->out); 104 | } 105 | 106 | public function getAsObject() 107 | { 108 | return $this->out; 109 | } 110 | 111 | public function __toString() 112 | { 113 | return $this->build(); 114 | } 115 | } -------------------------------------------------------------------------------- /src/Addons/MediaGroup.php: -------------------------------------------------------------------------------- 1 | MediaGroupType = $type; 25 | } 26 | 27 | public function add($media, $caption = '', $width = null, $height = null, $duration = null) 28 | { 29 | $MediaGroupNode = ['type' => $this->MediaGroupType, 'caption' => $caption]; 30 | if (file_exists($media)) $MediaGroupNode['media'] = $this->attach($media); 31 | else $MediaGroupNode['media'] = $media; 32 | if ($this->MediaGroupType == self::TYPE_VIDEO) { 33 | $MediaGroupNode['width'] = $width; 34 | $MediaGroupNode['height'] = $height; 35 | $MediaGroupNode['duration'] = $duration; 36 | 37 | } 38 | $this->MediaGroupArray[] = $MediaGroupNode; 39 | return $this; 40 | } 41 | 42 | private function attach($path) 43 | { 44 | $this->MediaGroupAttaches[basename($path)] = new \CURLFile($path); 45 | return 'attach://' . basename($path); 46 | } 47 | 48 | public function build(&$fields) 49 | { 50 | $fields['media'] = json_encode($this->MediaGroupArray); 51 | $fields = array_merge($fields, $this->MediaGroupAttaches); 52 | } 53 | 54 | } -------------------------------------------------------------------------------- /src/Addons/Payment.php: -------------------------------------------------------------------------------- 1 | data[] = ['label' => $label, 'amount' => $amount]; 27 | return $this; 28 | } 29 | 30 | public function build() 31 | { 32 | return json_encode($this->data); 33 | } 34 | } 35 | 36 | class ShippingOptionType 37 | { 38 | public $data = []; 39 | 40 | public function add($id, $title, $prices) 41 | { 42 | $query = ['id' => $id, 'title' => $title]; 43 | if (is_object($prices)) { 44 | $query['prices'] = $prices->data; 45 | } else $query['prices'] = $prices; 46 | 47 | $this->data[] = $query; 48 | return $this; 49 | } 50 | 51 | public function build() 52 | { 53 | return json_encode($this->data); 54 | } 55 | } -------------------------------------------------------------------------------- /src/Addons/Scene.php: -------------------------------------------------------------------------------- 1 | name = $name; 21 | } 22 | 23 | public function import() 24 | { 25 | return ['enter' => $this->enter, 'leave' => $this->leave, 'handlers' => $this->handlers]; 26 | } 27 | 28 | public function enter($func) 29 | { 30 | $this->enter = $func; 31 | } 32 | 33 | public function leave($func) 34 | { 35 | $this->leave = $func; 36 | } 37 | } -------------------------------------------------------------------------------- /src/Core/API.php: -------------------------------------------------------------------------------- 1 | '', 15 | 'base_url' => 'https://api.telegram.org/', 16 | 'username' => '', 17 | 'use_proxy' => false, 18 | 'run_type' => 0, 19 | 'hook_reply' => true, 20 | 'debug_mode' => false, 21 | 'timing' => false, 22 | 'log_mode' => false, 23 | 'log_path' => __DIR__ . DIRECTORY_SEPARATOR . 'tb_log', 24 | 'proxy' => [ 25 | 'authorization' => '', 26 | 'server' => '', 27 | 'proxy_type' => '', 28 | ], 29 | 'redbean_dsn' => '', 30 | 'redbean_user' => '', 31 | 'redbean_password' => '' 32 | ]; 33 | 34 | private $WH_BL = [ 35 | 'getChat', 36 | 'getChatAdministrators', 37 | 'getChatMember', 38 | 'getChatMembersCount', 39 | 'getFile', 40 | 'getFileLink', 41 | 'getGameHighScores', 42 | 'getMe', 43 | 'getUserProfilePhotos', 44 | 'getWebhookInfo' 45 | ]; 46 | 47 | private $ch; 48 | private $webhookreply_used = false; 49 | 50 | public function __construct($settings) 51 | { 52 | $this->settings = array_replace_recursive($this->settings, $settings); 53 | $this->initCurl(); 54 | } 55 | 56 | public function initCurl() 57 | { 58 | $this->ch = curl_init(); 59 | } 60 | 61 | public function closeCurl() 62 | { 63 | curl_close($this->ch); 64 | } 65 | 66 | public function __destruct() 67 | { 68 | $this->closeCurl(); 69 | } 70 | 71 | public function getApiUrl() 72 | { 73 | return trim($this->settings['base_url'], '/') . '/bot' . $this->settings['api_token'] . '/'; 74 | } 75 | 76 | private function closeRequest($data) 77 | { 78 | if(function_exists('fastcgi_finish_request')) 79 | { 80 | echo $data; 81 | fastcgi_finish_request(); 82 | }else{ 83 | ob_start(); 84 | header("Connection: close\r\n"); 85 | header("Content-Type: application/json; charset=utf-8"); 86 | echo $data; 87 | 88 | $size = ob_get_length(); 89 | header("Content-Length: ". $size . "\r\n"); 90 | ob_end_flush(); 91 | flush(); 92 | } 93 | } 94 | 95 | public function callMethod($method, $fields = [], $headers = [], $json = true) 96 | { 97 | if ($this->settings['run_type'] == 1 AND !$this->settings['debug_mode'] AND $this->settings['hook_reply'] AND !$this->webhookreply_used AND !in_array($method, $this->WH_BL)) { 98 | $this->webhookreply_used = true; 99 | $response['method'] = $method; 100 | $response = $response + $fields; 101 | $this->closeRequest(json_encode($response)); 102 | return true; 103 | 104 | } 105 | 106 | curl_setopt($this->ch, CURLOPT_URL, $this->getApiUrl() . $method); 107 | if (is_array($headers) AND count($headers) > 0) curl_setopt($this->ch, CURLOPT_HTTPHEADER, $headers); 108 | curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); 109 | curl_setopt($this->ch, CURLOPT_POST, true); 110 | curl_setopt($this->ch, CURLOPT_POSTFIELDS, $fields); 111 | curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, false); 112 | curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false); 113 | curl_setopt($this->ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); 114 | if ($this->settings['use_proxy']) { 115 | curl_setopt($this->ch, CURLOPT_TIMEOUT, 10); 116 | curl_setopt($this->ch, CURLOPT_PROXY, $this->settings['proxy']['server']); 117 | curl_setopt($this->ch, CURLOPT_HTTPPROXYTUNNEL, true); 118 | curl_setopt($this->ch, CURLOPT_PROXYTYPE, $this->settings['proxy']['proxy_type']); 119 | if (mb_strlen($this->settings['proxy']['authorization']) > 0) { 120 | curl_setopt($this->ch, CURLOPT_PROXYUSERPWD, $this->settings['proxy']['authorization']); 121 | } 122 | 123 | } 124 | if($this->settings['timing']) Functions::ctime('callMethod'); 125 | $response = curl_exec($this->ch); 126 | $this->processError($method, $response, $fields); 127 | if($this->settings['timing']) $this->trace('#[API] - Метод: \''.$method.'\' = '.Functions::ctime('callMethod')); 128 | if ($json) return json_decode($response); 129 | else return $response; 130 | } 131 | 132 | public function processError($method, $response, $fields = []) 133 | { 134 | $response = json_decode($response); 135 | if (!$response->ok) { 136 | $this->trace('#При выполнении метода: "' . $method . '" произошла ошибка!'); 137 | $this->trace('#Код ошибки: ' . $response->error_code); 138 | $this->trace('#Описание ошибки: ' . $response->description); 139 | $this->trace('#Время вызова: ' . $this->datetime()); 140 | $this->trace('#Данные: '.json_encode($fields)); 141 | } 142 | return $response; 143 | } 144 | 145 | public function datetime() 146 | { 147 | return date('H:i:s m.d.Y'); 148 | } 149 | 150 | public function trace($msg, $onlyDebug = false) 151 | { 152 | if ($this->settings['debug_mode']) { 153 | if (substr(PHP_OS, 0, 3) == 'WIN' and false == true) { 154 | if (!is_string($msg)) { 155 | $text = unserialize(iconv('UTF-8', 'CP866', serialize($msg))); 156 | } else $text = iconv('UTF-8', 'CP866', $msg); 157 | } else $text = $msg; 158 | print_r($text); 159 | print_r(PHP_EOL); 160 | 161 | } 162 | if (!$onlyDebug AND $this->settings['log_mode']) { 163 | file_put_contents($this->settings['log_path'], $msg . PHP_EOL, FILE_APPEND); 164 | } 165 | } 166 | 167 | // Методы API 168 | 169 | public function getUpdates($params = []) 170 | { 171 | return $this->callMethod('getUpdates', $params); 172 | } 173 | 174 | public function sendMessage($params) 175 | { 176 | return $this->callMethod('sendMessage', $params); 177 | } 178 | 179 | public function getMe() 180 | { 181 | return $this->callMethod('getMe'); 182 | } 183 | 184 | public function forwardMessage($params) 185 | { 186 | return $this->callMethod('forwardMessage', $params); 187 | } 188 | 189 | public function sendPhoto($params) 190 | { 191 | $headers = []; 192 | if (isset($params['photo']) AND $params['photo'] instanceof \CURLFile) { 193 | $this->webhookreply_used = true; 194 | $headers[] = 'Content-Type:multipart/form-data'; 195 | } 196 | return $this->callMethod('sendPhoto', $params, $headers); 197 | } 198 | 199 | public function sendAudio($params) 200 | { 201 | $headers = []; 202 | if (isset($params['audio']) AND $params['audio'] instanceof \CURLFile) { 203 | $this->webhookreply_used = true; 204 | $headers[] = 'Content-Type:multipart/form-data'; 205 | } 206 | return $this->callMethod('sendAudio', $params, $headers); 207 | } 208 | 209 | public function sendDocument($params) 210 | { 211 | $headers = []; 212 | if (isset($params['document']) AND $params['document'] instanceof \CURLFile) { 213 | $this->webhookreply_used = true; 214 | $headers[] = 'Content-Type:multipart/form-data'; 215 | } 216 | return $this->callMethod('sendDocument', $params, $headers); 217 | } 218 | 219 | public function sendSticker($params) 220 | { 221 | $headers = []; 222 | if (isset($params['sticker']) AND $params['sticker'] instanceof \CURLFile) { 223 | $this->webhookreply_used = true; 224 | $headers[] = 'Content-Type:multipart/form-data'; 225 | } 226 | return $this->callMethod('sendSticker', $params, $headers); 227 | } 228 | 229 | public function sendVideo($params) 230 | { 231 | $headers = []; 232 | if (isset($params['video']) AND $params['video'] instanceof \CURLFile) { 233 | $this->webhookreply_used = true; 234 | $headers[] = 'Content-Type:multipart/form-data'; 235 | } 236 | return $this->callMethod('sendVideo', $params, $headers); 237 | } 238 | 239 | public function sendAnimation($params) 240 | { 241 | $headers = []; 242 | if (isset($params['animation']) AND $params['animation'] instanceof \CURLFile) { 243 | $this->webhookreply_used = true; 244 | $headers[] = 'Content-Type:multipart/form-data'; 245 | } 246 | return $this->callMethod('sendAnimation', $params, $headers); 247 | } 248 | 249 | public function sendVoice($params) 250 | { 251 | $headers = []; 252 | if (isset($params['voice']) AND $params['voice'] instanceof \CURLFile) { 253 | $this->webhookreply_used = true; 254 | $headers[] = 'Content-Type:multipart/form-data'; 255 | } 256 | return $this->callMethod('sendVoice', $params, $headers); 257 | } 258 | 259 | public function sendVideoNote($params) 260 | { 261 | $headers = []; 262 | if (isset($params['video_note']) AND $params['video_note'] instanceof \CURLFile) { 263 | $this->webhookreply_used = true; 264 | $headers[] = 'Content-Type:multipart/form-data'; 265 | } 266 | return $this->callMethod('sendVideoNote', $params, $headers); 267 | } 268 | 269 | public function sendMediaGroup($params) 270 | { 271 | $headers[] = 'Content-Type:multipart/form-data'; 272 | $this->webhookreply_used = true; 273 | if (isset($params['media']) and $params['media'] instanceof MediaGroup) $params['media']->build($params); 274 | return $this->callMethod('sendMediaGroup', $params, $headers); 275 | } 276 | 277 | public function sendLocation($params) 278 | { 279 | return $this->callMethod('sendLocation', $params); 280 | } 281 | 282 | public function editMessageLiveLocation($params) 283 | { 284 | return $this->callMethod('editMessageLiveLocation', $params); 285 | } 286 | 287 | public function stopMessageLiveLocation($params = []) 288 | { 289 | return $this->callMethod('stopMessageLiveLocation', $params); 290 | } 291 | 292 | public function sendVenue($params) 293 | { 294 | return $this->callMethod('sendVenue', $params); 295 | } 296 | 297 | public function sendContact($params) 298 | { 299 | return $this->callMethod('sendContact', $params); 300 | } 301 | 302 | public function sendChatAction($params) 303 | { 304 | return $this->callMethod('sendChatAction', $params); 305 | } 306 | 307 | public function getUserProfilePhotos($params) 308 | { 309 | return $this->callMethod('getUserProfilePhotos', $params); 310 | } 311 | 312 | public function getFile($params) 313 | { 314 | return $this->callMethod('getFile', $params); 315 | } 316 | 317 | public function kickChatMember($params) 318 | { 319 | return $this->callMethod('kickChatMember', $params); 320 | } 321 | 322 | public function unbanChatMember($params) 323 | { 324 | return $this->callMethod('unbanChatMember', $params); 325 | } 326 | 327 | public function restrictChatMember($params) 328 | { 329 | return $this->callMethod('restrictChatMember', $params); 330 | } 331 | 332 | public function promoteChatMember($params) 333 | { 334 | return $this->callMethod('promoteChatMember', $params); 335 | } 336 | 337 | public function exportChatInviteLink($params) 338 | { 339 | return $this->callMethod('exportChatInviteLink', $params); 340 | } 341 | 342 | public function setChatPhoto($params) 343 | { 344 | $headers = []; 345 | if (isset($params['photo']) AND $params['photo'] instanceof \CURLFile) { 346 | $this->webhookreply_used = true; 347 | $headers[] = 'Content-Type:multipart/form-data'; 348 | } 349 | return $this->callMethod('setChatPhoto', $params, $headers); 350 | } 351 | 352 | public function deleteChatPhoto($params) 353 | { 354 | return $this->callMethod('deleteChatPhoto', $params); 355 | } 356 | 357 | public function setChatTitle($params) 358 | { 359 | return $this->callMethod('setChatTitle', $params); 360 | } 361 | 362 | public function setChatDescription($params) 363 | { 364 | return $this->callMethod('setChatDescription', $params); 365 | } 366 | 367 | public function pinChatMessage($params) 368 | { 369 | return $this->callMethod('pinChatMessage', $params); 370 | } 371 | 372 | public function unpinChatMessage($params) 373 | { 374 | return $this->callMethod('unpinChatMessage', $params); 375 | } 376 | 377 | public function leaveChat($params) 378 | { 379 | return $this->callMethod('leaveChat', $params); 380 | } 381 | 382 | public function getChat($params) 383 | { 384 | return $this->callMethod('getChat', $params); 385 | } 386 | 387 | public function getChatAdministrators($params) 388 | { 389 | return $this->callMethod('getChatAdministrators', $params); 390 | } 391 | 392 | public function getChatMembersCount($params) 393 | { 394 | return $this->callMethod('getChatMembersCount', $params); 395 | } 396 | 397 | public function getChatMember($params) 398 | { 399 | return $this->callMethod('getChatMember', $params); 400 | } 401 | 402 | public function setChatStickerSet($params) 403 | { 404 | return $this->callMethod('setChatStickerSet', $params); 405 | } 406 | 407 | public function deleteChatStickerSet($params) 408 | { 409 | return $this->callMethod('deleteChatStickerSet', $params); 410 | } 411 | 412 | public function answerCallbackQuery($params) 413 | { 414 | return $this->callMethod('answerCallbackQuery', $params); 415 | } 416 | 417 | public function editMessageText($params) 418 | { 419 | return $this->callMethod('editMessageText', $params); 420 | } 421 | 422 | public function editMessageCaption($params = []) 423 | { 424 | return $this->callMethod('editMessageCaption', $params); 425 | } 426 | 427 | public function editMessageMedia($params) 428 | { 429 | return $this->callMethod('editMessageMedia', $params); 430 | } 431 | 432 | public function editMessageReplyMarkup($params = []) 433 | { 434 | return $this->callMethod('editMessageReplyMarkup', $params); 435 | } 436 | 437 | public function deleteMessage($params) 438 | { 439 | return $this->callMethod('deleteMessage', $params); 440 | } 441 | 442 | public function answerInlineQuery($params) 443 | { 444 | return $this->callMethod('answerInlineQuery', $params); 445 | } 446 | 447 | public function sendInvoice($params) 448 | { 449 | return $this->callMethod('sendInvoice', $params); 450 | } 451 | 452 | public function answerShippingQuery($params) 453 | { 454 | return $this->callMethod('answerShippingQuery', $params); 455 | } 456 | 457 | public function answerPreCheckoutQuery($params) 458 | { 459 | return $this->callMethod('answerPreCheckoutQuery', $params); 460 | } 461 | 462 | public function setPassportDataErrors($params) 463 | { 464 | return $this->callMethod('setPassportDataErrors', $params); 465 | } 466 | 467 | public function sendGame($params) 468 | { 469 | return $this->callMethod('sendGame', $params); 470 | } 471 | 472 | public function setGameScore($params) 473 | { 474 | return $this->callMethod('setGameScore', $params); 475 | } 476 | 477 | public function getGameHighScores($params) 478 | { 479 | return $this->callMethod('getGameHighScores', $params); 480 | } 481 | } -------------------------------------------------------------------------------- /src/Core/Bot.php: -------------------------------------------------------------------------------- 1 | api = new API($settings); 34 | } 35 | 36 | public function ctx(): Context 37 | { 38 | return $this->ctx; 39 | } 40 | 41 | public function api(): API 42 | { 43 | return $this->api; 44 | } 45 | 46 | public function loop($loopHandler) 47 | { 48 | $this->loopHandler = $loopHandler; 49 | } 50 | 51 | public function run() 52 | { 53 | switch ($this->api->settings['run_type']) { 54 | case self::RUN_AS_POLL: 55 | $update_id = 0; 56 | while (true) { 57 | $updates = $this->api->getUpdates(['offset' => $update_id, 'timeout' => 600]); 58 | if ($updates->ok) { 59 | foreach ($updates->result as $update) { 60 | $update_id = $update->update_id + 1; 61 | $this->processUpdate($update); 62 | } 63 | } else { 64 | $this->api->trace('После критической ошибки, бот не был запущен в режиме Long Poll'); 65 | break; 66 | } 67 | } 68 | break; 69 | 70 | case self::RUN_AS_HOOK: 71 | if (isset($_REQUEST)) { 72 | $this->processUpdate(json_decode(file_get_contents('php://input'))); 73 | } 74 | break; 75 | } 76 | } 77 | 78 | public function processUpdate($update) 79 | { 80 | if(!isset($update->update_id)) return; 81 | $this->ctx = new Context(new Update($update), $this->api, $this->scenes); 82 | if(is_callable($this->loopHandler)) ($this->loopHandler)(new Update($update)); 83 | if($this->api->settings['timing']) { 84 | $this->api->trace('#'); 85 | $this->api->trace('#Update: ' . $update->update_id); 86 | Functions::ctime('update'); 87 | } 88 | if ($this->loadAddons()) { 89 | if($this->ctx->usedControl()) { 90 | $scene = (isset($this->scenes[$this->ctx()->getState()])) ? $this->scenes[$this->ctx()->getState()] : null; 91 | if(is_array($scene)) { 92 | $handlers = $scene['handlers']; 93 | foreach ($handlers as $handler) { 94 | if ($handler($this->ctx) === true) break; 95 | } 96 | return; 97 | } 98 | } 99 | if($this->api->settings['timing']) Functions::ctime('handlers'); 100 | foreach ($this->handlers as $id => $handler) { 101 | if($this->api->settings['timing']) Functions::ctime('handler'); 102 | if ($handler($this->ctx) === true) { 103 | if($this->api->settings['timing']) $this->api->trace('#[Handlers] - Событие ID:'.$id.' = '.Functions::ctime('handler')); 104 | break; 105 | } 106 | } 107 | } 108 | if($this->api->settings['timing']) { 109 | $this->api->trace('#Время затраченное на обработку событий: ' . Functions::ctime('handlers')); 110 | $this->api->trace('#Всего: ' . Functions::ctime('update')); 111 | $this->api->trace('#'); 112 | } 113 | } 114 | 115 | private function loadAddons() 116 | { 117 | $ctx = $this->ctx; 118 | foreach ($this->addons as $addon) { 119 | $ctx = $addon($ctx); 120 | if (!$ctx) { 121 | $this->api->trace('#[WARNING] Usage not returned the Context.'); 122 | return false; 123 | } 124 | } 125 | $this->ctx = $ctx; 126 | return true; 127 | } 128 | 129 | public function addScene(Scene $scene) 130 | { 131 | $this->scenes[$scene->name] = $scene->import(); 132 | } 133 | 134 | public function addScenes() 135 | { 136 | $scenes = func_get_args(); 137 | foreach ($scenes as $scene) { 138 | $this->addScene($scene); 139 | } 140 | } 141 | 142 | public function usage($func) 143 | { 144 | $this->addons[] = $func; 145 | } 146 | 147 | public function addUsages() 148 | { 149 | $usages = func_get_args(); 150 | foreach ($usages as $usage) { 151 | $this->usage($usage); 152 | } 153 | } 154 | 155 | } -------------------------------------------------------------------------------- /src/Core/Context.php: -------------------------------------------------------------------------------- 1 | update = $update; 74 | $this->api = $api; 75 | $this->scenes = $scenes; 76 | } 77 | 78 | public function setUserControl(UserInterface $control) 79 | { 80 | $this->__user = $control; 81 | } 82 | 83 | public function usedControl() 84 | { 85 | return ($this->__user instanceof UserInterface) ? true : false; 86 | } 87 | 88 | public function user(): UserInterface 89 | { 90 | return $this->__user; 91 | } 92 | 93 | public function getState() 94 | { 95 | return $this->user()->getState(); 96 | } 97 | 98 | public function setState($state) 99 | { 100 | $this->user()->setState($state); 101 | return $this; 102 | } 103 | 104 | public function enter($sceneName) 105 | { 106 | $this->setState($sceneName); 107 | if (is_callable($this->scenes[$sceneName]['enter'])) $this->scenes[$sceneName]['enter']($this); 108 | else { 109 | $this->api->trace('[WARNING] Scene "'.$sceneName.'" not found!'); 110 | } 111 | } 112 | 113 | public function leave() 114 | { 115 | if (is_callable($this->scenes[$this->getState()]['leave'])) $this->scenes[$this->getState()]['leave']($this); 116 | $this->setState(''); 117 | } 118 | 119 | public function getMessage() : ?Message 120 | { 121 | if($this->update->exists('message')) return $this->update->message(); 122 | elseif ($this->update->exists('edited_message')) return $this->update->editedMessage(); 123 | elseif ( 124 | $this->update->exists('callback_query') and 125 | $this->update->callbackQuery()->exists('message') 126 | ) return $this->update->callbackQuery()->message(); 127 | elseif ($this->update->exists('channel_post')) $this->update->channelPost(); 128 | elseif ($this->update->exists('edited_channel_post')) $this->update->editedChannelPost(); 129 | else return null; 130 | } 131 | 132 | public function getFrom() : ?User 133 | { 134 | if ($this->update->exists('message')) return $this->update->message()->from(); 135 | elseif ($this->update->exists('edited_message')) return $this->update->editedMessage()->from(); 136 | elseif ($this->update->exists('callback_query')) return $this->update->callbackQuery()->from(); 137 | elseif ($this->update->exists('inline_query')) return $this->update->inlineQuery()->from(); 138 | elseif ($this->update->exists('channel_post')) return $this->update->channelPost()->from(); 139 | elseif ($this->update->exists('edited_channel_post')) return $this->update->editedChannelPost()->from(); 140 | elseif ($this->update->exists('shipping_query')) return $this->update->shippingQuery()->from(); 141 | elseif ($this->update->exists('pre_checkout_query')) return $this->update->preCheckoutQuery()->from(); 142 | elseif ($this->update->exists('chosen_inline_result')) return $this->update->chosenInlineResult()->from(); 143 | else return null; 144 | } 145 | 146 | public function getChat() : ?Chat 147 | { 148 | return $this->getMessage()->chat() ?? null; 149 | } 150 | 151 | public function getText(): string 152 | { 153 | return $this->getMessage()->text() ?? ''; 154 | } 155 | 156 | public function getLowerCaseText(): string 157 | { 158 | return mb_strtolower($this->getText()); 159 | } 160 | 161 | public function getSticker(): ?Sticker 162 | { 163 | return !is_null($this->getMessage()) ? ($this->getMessage()->exists('sticker') ? $this->getMessage()->sticker() : null) : null; 164 | } 165 | 166 | public function getChatID(): int 167 | { 168 | return $this->getChat()->id(); 169 | } 170 | 171 | public function getMessageID(): int 172 | { 173 | return $this->getMessage()->messageId(); 174 | } 175 | 176 | public function getCallbackID(): int 177 | { 178 | return $this->callbackQuery()->id(); 179 | } 180 | 181 | public function getUserID(): int 182 | { 183 | return $this->getFrom()->id(); 184 | } 185 | 186 | public function getUsername(): string 187 | { 188 | return $this->getFrom()->username(); 189 | } 190 | 191 | public function getFromIsBot() : bool 192 | { 193 | return $this->getFrom()->isBot(); 194 | } 195 | 196 | public function getFirstName(): string 197 | { 198 | return $this->getFrom()->firstName(); 199 | } 200 | 201 | public function getLastName(): string 202 | { 203 | return $this->getFrom()->lastName(); 204 | } 205 | 206 | public function getFullName(): string 207 | { 208 | return $this->getFirstName() . ' ' . $this->getLastName(); 209 | } 210 | 211 | public function getLangCode(): string 212 | { 213 | return $this->getFrom()->languageCode(); 214 | } 215 | 216 | public function getInlineQueryID(): string 217 | { 218 | return $this->inlineQuery()->id(); 219 | } 220 | 221 | public function getInlineMessID() 222 | { 223 | return $this->chosenInlineResult()->inlineMessageId(); 224 | } 225 | 226 | public function editedMessage() : ?Message 227 | { 228 | return $this->update->editedMessage(); 229 | } 230 | 231 | public function inlineQuery() : ?InlineQuery 232 | { 233 | return $this->update->inlineQuery(); 234 | } 235 | 236 | public function shippingQuery() : ?ShippingQuery 237 | { 238 | return $this->update->shippingQuery(); 239 | } 240 | 241 | public function preCheckoutQuery() : ?PreCheckoutQuery 242 | { 243 | return $this->update->preCheckoutQuery(); 244 | } 245 | 246 | public function chosenInlineResult() : ?ChosenInlineResult 247 | { 248 | return $this->update->chosenInlineResult(); 249 | } 250 | 251 | public function channelPost() : ?Message 252 | { 253 | return $this->update->channelPost(); 254 | } 255 | 256 | public function editedChannelPost() : ?Message 257 | { 258 | return $this->update->editedChannelPost(); 259 | } 260 | 261 | public function callbackQuery() : ?CallbackQuery 262 | { 263 | return $this->update->callbackQuery(); 264 | } 265 | 266 | 267 | // Кастомные методы 268 | public function reply($text, $keyboard = null, $reply_mode = false, $options = []) 269 | { 270 | $fields = ['chat_id' => $this->getChatID(), 'text' => $text, 'reply_markup' => (string)$keyboard]; 271 | if ($reply_mode) $fields['reply_to_message_id'] = $this->getMessageID(); 272 | $fields = $fields + $options; 273 | return $this->api->sendMessage($fields); 274 | } 275 | 276 | public function replyHTML($text, $keyboard = null, $reply_mode = false, $options = []) 277 | { 278 | $options['parse_mode'] = 'HTML'; 279 | return $this->reply($text, $keyboard, $reply_mode, $options); 280 | } 281 | 282 | public function replyMarkdown($text, $keyboard = null, $reply_mode = false, $options = []) 283 | { 284 | $options['parse_mode'] = 'Markdown'; 285 | return $this->reply($text, $keyboard, $reply_mode, $options); 286 | } 287 | 288 | public function replyPhoto($photo, $caption = null, $keyboard = null, $reply_mode = false, $options = []) 289 | { 290 | $fields = ['chat_id' => $this->getChatID(), 'photo' => $photo, 'caption' => $caption, 'reply_markup' => (string)$keyboard]; 291 | if ($reply_mode) $fields['reply_to_message_id'] = $this->getMessageID(); 292 | $fields = $fields + $options; 293 | $this->api->sendPhoto($fields); 294 | } 295 | 296 | public function replyDocument($document, $caption = null, $keyboard = null, $reply_mode = false, $options = []) 297 | { 298 | $fields = ['chat_id' => $this->getChatID(), 'document' => $document, 'caption' => $caption, 'reply_markup' => (string)$keyboard]; 299 | if ($reply_mode) $fields['reply_to_message_id'] = $this->getMessageID(); 300 | $fields = $fields + $options; 301 | $this->api->sendDocument($fields); 302 | } 303 | 304 | public function replyAudio($audio, $caption = null, $keyboard = null, $reply_mode = false, $options = []) 305 | { 306 | $fields = ['chat_id' => $this->getChatID(), 'audio' => $audio, 'caption' => $caption, 'reply_markup' => (string)$keyboard]; 307 | if ($reply_mode) $fields['reply_to_message_id'] = $this->getMessageID(); 308 | $fields = $fields + $options; 309 | $this->api->sendAudio($fields); 310 | } 311 | 312 | public function replyVideo($video, $keyboard = null, $reply_mode = false, $options = []) 313 | { 314 | $fields = ['chat_id' => $this->getChatID(), 'video' => $video, 'reply_markup' => (string)$keyboard]; 315 | if ($reply_mode) $fields['reply_to_message_id'] = $this->getMessageID(); 316 | $fields = $fields + $options; 317 | $this->api->sendVideo($fields); 318 | } 319 | 320 | public function replyMediaGroup($media, $reply_mode = false, $disable_notification = false) 321 | { 322 | $fields = ['chat_id' => $this->getChatID(), 'media' => $media, 'disable_notification' => $disable_notification]; 323 | if ($reply_mode) $fields['reply_to_message_id'] = $this->getMessageID(); 324 | return $this->api->sendMediaGroup($fields); 325 | } 326 | 327 | public function editActTxt($text, $keyboard = null, $options = []) 328 | { 329 | $fields = ['chat_id' => $this->getChatID(), 'message_id' => $this->getMessageID(), 'text' => $text, 'reply_markup' => (string)$keyboard]; 330 | $fields = $fields + $options; 331 | $this->api->editMessageText($fields); 332 | 333 | } 334 | 335 | public function editActTxtHTML($text, $keyboard = null, $disable_web_page_preview = false) 336 | { 337 | $this->api->editMessageText(['chat_id' => $this->getChatID(), 'message_id' => $this->getMessageID(), 'text' => $text, 'reply_markup' => (string)$keyboard, 'parse_mode' => 'HTML', 'disable_web_page_preview' => $disable_web_page_preview]); 338 | } 339 | 340 | public function editActTxtMarkdown($text, $keyboard = null, $disable_web_page_preview = false) 341 | { 342 | $this->api->editMessageText(['chat_id' => $this->getChatID(), 'message_id' => $this->getMessageID(), 'text' => $text, 'reply_markup' => (string)$keyboard, 'parse_mode' => 'Markdown', 'disable_web_page_preview' => $disable_web_page_preview]); 343 | } 344 | 345 | public function ansCallback($text = null, $alert = false, $url = null, $cache = 0) 346 | { 347 | return $this->api->answerCallbackQuery(['callback_query_id' => $this->getCallbackID(), 'text' => $text, 'show_alert' => $alert, 'url' => $url, 'cache_time' => $cache]); 348 | } 349 | 350 | public function getFile($fileID) 351 | { 352 | return $this->api->getFile(['file_id' => $fileID]); 353 | } 354 | 355 | public function getFileLink($fileID) 356 | { 357 | $response = $this->getFile($fileID); 358 | return (isset($response->result->file_path)) ? 'https://api.telegram.org/file/bot' . $this->api->settings['api_token'] . '/' . $response->result->file_path : $response; 359 | } 360 | 361 | public function replyChatAction($act) 362 | { 363 | return $this->api->sendChatAction(['chat_id' => $this->getChatID(), 'action' => $act]); 364 | } 365 | 366 | // Устаревшие кастомные методы 367 | public function sMessage($chatID, $message, $keyboard = null, $parseMode = false, $disableWebPreview = false, $replyID = null) 368 | { 369 | $fields = ['chat_id' => $chatID, 'text' => $message, 'disable_web_page_preview' => $disableWebPreview, 'reply_markup' => (string)$keyboard]; 370 | if ($parseMode) $fields['parse_mode'] = $parseMode; 371 | if ($replyID) $fields['reply_to_message_id'] = $replyID; 372 | return $this->api->sendMessage($fields); 373 | } 374 | 375 | public function fMessage($chatID, $fromID, $messID, $keyboard = null, $disableNotification = false) 376 | { 377 | $fields = ['chat_id' => $chatID, 'from_chat_id' => $fromID, 'message_id' => $messID, 'disable_notification' => $disableNotification, 'reply_markup' => (string)$keyboard]; 378 | return $this->api->forwardMessage($fields); 379 | 380 | } 381 | 382 | public function sDocument($chatID, $document, $caption = null, $disableNotification = false, $keyboard = null, $replyID = null) 383 | { 384 | $fields = ['chat_id' => $chatID, 'document' => $document, 'disable_notification' => $disableNotification, 'caption' => $caption, 'reply_markup' => (string)$keyboard]; 385 | if ($replyID) $fields['reply_to_message_id'] = $replyID; 386 | return $this->api->sendDocument($fields); 387 | 388 | } 389 | 390 | public function sSticker($chatID, $sticker, $disableNotification = false, $keyboard = null, $replyID = null) 391 | { 392 | $fields = ['chat_id' => $chatID, 'sticker' => $sticker, 'disable_notification' => $disableNotification, 'reply_markup' => (string)$keyboard]; 393 | if ($replyID) $fields['reply_to_message_id'] = $replyID; 394 | return $this->api->sendSticker($fields); 395 | 396 | } 397 | 398 | public function sMediaGroup($chatID, $media, $disableNotification = false, $replyID = null) 399 | { 400 | $fields = ['chat_id' => $chatID, 'media' => $media, 'disable_notification' => $disableNotification]; 401 | if ($replyID) $fields['reply_to_message_id'] = $replyID; 402 | return $this->api->sendMediaGroup($fields); 403 | 404 | } 405 | 406 | public function sPhoto($chatID, $photo, $caption = null, $keyboard = null, $disableNotification = false, $replyID = null) 407 | { 408 | $fields = ['chat_id' => $chatID, 'photo' => $photo, 'caption' => $caption, 'disable_notification' => $disableNotification, 'reply_markup' => (string)$keyboard]; 409 | if ($replyID) $fields['reply_to_message_id'] = $replyID; 410 | return $this->api->sendPhoto($fields); 411 | } 412 | 413 | public function sAudio($chatID, $audio, $caption = null, $duration = null, $performer = null, $title = null, $disableNotification = false, $keyboard = null, $replyID = null) 414 | { 415 | $fields = ['chat_id' => $chatID, 'audio' => $audio, 'caption' => $caption, 'duration' => $duration, 'performer' => $performer, 'title' => $title, 'disable_notification' => $disableNotification, 'reply_markup' => (string)$keyboard]; 416 | if ($replyID) $fields['reply_to_message_id'] = $replyID; 417 | return $this->api->sendAudio($fields); 418 | } 419 | 420 | public function sVoice($chatID, $voice, $caption = null, $duration = null, $disableNotification = false, $keyboard = null, $replyID = null) 421 | { 422 | $fields = ['chat_id' => $chatID, 'voice' => $voice, 'caption' => $caption, 'duration' => $duration, 'disable_notification' => $disableNotification, 'reply_markup' => (string)$keyboard]; 423 | if ($replyID) $fields['reply_to_message_id'] = $replyID; 424 | return $this->api->sendVoice($fields); 425 | } 426 | 427 | public function sVideo($chatID, $video, $caption = null, $duration = null, $width = null, $height = null, $disableNotification = false, $keyboard = null, $replyID = null) 428 | { 429 | $fields = ['chat_id' => $chatID, 'video' => $video, 'caption' => $caption, 'duration' => $duration, 'width' => $width, 'height' => $height, 'disable_notification' => $disableNotification, 'reply_markup' => (string)$keyboard]; 430 | if ($replyID) $fields['reply_to_message_id'] = $replyID; 431 | return $this->api->sendVideo($fields); 432 | } 433 | 434 | public function sVideoNote($chatID, $video, $duration = null, $length = null, $disableNotification = false, $keyboard = null, $replyID = null) 435 | { 436 | $fields = ['chat_id' => $chatID, 'video_note' => $video, 'disable_notification' => $disableNotification, 'duration' => $duration, 'length' => $length, 'reply_markup' => (string)$keyboard]; 437 | if ($replyID) $fields['reply_to_message_id'] = $replyID; 438 | return $this->api->sendVideoNote($fields); 439 | } 440 | 441 | public function sContact($chatID, $phone, $first_name, $last_name = null, $disableNotification = false, $keyboard = null, $replyID = null) 442 | { 443 | $fields = ['chat_id' => $chatID, 'phone_number' => $phone, 'first_name' => $first_name, 'last_name' => $last_name, 'disable_notification' => $disableNotification, 'reply_markup' => (string)$keyboard]; 444 | if ($replyID) $fields['reply_to_message_id'] = $replyID; 445 | return $this->api->sendContact($fields); 446 | } 447 | 448 | public function sLocation($chatID, $latitude, $longitude, $livePeriod = null, $disableNotification = false, $keyboard = null, $replyID = null) 449 | { 450 | $fields = ['chat_id' => $chatID, 'latitude' => $latitude, 'longitude' => $longitude, 'live_period' => $livePeriod, 'disable_notification' => $disableNotification, 'reply_markup' => (string)$keyboard]; 451 | if ($replyID) $fields['reply_to_message_id'] = $replyID; 452 | return $this->api->sendLocation($fields); 453 | 454 | } 455 | 456 | public function editMessageLiveLocation($chatID, $messID, $latitude, $longitude, $keyboard = null) 457 | { 458 | $fields = ['chat_id' => $chatID, 'message_id' => $messID, 'latitude' => $latitude, 'longitude' => $longitude, 'reply_markup' => (string)$keyboard]; 459 | return $this->api->editMessageLiveLocation($fields); 460 | } 461 | 462 | public function editInlineLiveLocation($inlineMessID, $latitude, $longitude, $keyboard = null) 463 | { 464 | $fields = ['inline_message_id' => $inlineMessID, 'latitude' => $latitude, 'longitude' => $longitude, 'reply_markup' => (string)$keyboard]; 465 | return $this->api->editMessageLiveLocation($fields); 466 | } 467 | 468 | public function stopMessageLiveLocation($chatID, $messID, $keyboard = null) 469 | { 470 | $fields = ['chat_id' => $chatID, 'message_id' => $messID, 'reply_markup' => (string)$keyboard]; 471 | return $this->api->stopMessageLiveLocation($fields); 472 | } 473 | 474 | public function stopInlineLiveLocation($inlineMessID, $keyboard = null) 475 | { 476 | $fields = ['inline_message_id' => $inlineMessID, 'reply_markup' => (string)$keyboard]; 477 | return $this->api->stopMessageLiveLocation($fields); 478 | } 479 | 480 | public function sVenue($chatID, $latitude, $longitude, $title = null, $address = null, $foursquare = null, $disableNotification = false, $keyboard = null, $replyID = null) 481 | { 482 | $fields = ['chat_id' => $chatID, 'latitude' => $latitude, 'longitude' => $longitude, 'title' => $title, 'address' => $address, 'foursquare_id' => $foursquare, 'disable_notification' => $disableNotification, 'reply_markup' => (string)$keyboard]; 483 | if ($replyID) $fields['reply_to_message_id'] = $replyID; 484 | return $this->api->sendVenue($fields); 485 | 486 | } 487 | 488 | public function sChatAction($chatID, $act) 489 | { 490 | return $this->api->sendChatAction(['chat_id' => $chatID, 'action' => $act]); 491 | } 492 | 493 | public function getUserProfilePhotos($userID, $offset = null, $limit = 100) 494 | { 495 | return $this->api->getUserProfilePhotos(['user_id' => $userID, 'limit' => $limit, 'offset' => $offset]); 496 | } 497 | 498 | public function kickChatMember($chatID, $userID) 499 | { 500 | return $this->api->kickChatMember(['chat_id' => $chatID, 'user_id' => $userID]); 501 | } 502 | 503 | public function unbanChatMember($chatID, $userID) 504 | { 505 | return $this->api->unbanChatMember(['chat_id' => $chatID, 'user_id' => $userID]); 506 | } 507 | 508 | public function restrictChatMember($chatID, $userID, $date, $canSendMessage = false, $canSendMedia = false, $canSendOther = false, $canAddWebPrev = false) 509 | { 510 | return $this->api->restrictChatMember([ 511 | 'chat_id' => $chatID, 512 | 'user_id' => $userID, 513 | 'until_date' => $date, 514 | 'can_send_messages' => $canSendMessage, 515 | 'can_send_media_messages' => $canSendMedia, 516 | 'can_send_other_messages' => $canSendOther, 517 | 'can_add_web_page_previews' => $canAddWebPrev 518 | ]); 519 | } 520 | 521 | public function promoteChatMember( 522 | $chatID, 523 | $userID, 524 | $canChangeInfo = false, 525 | $canPostMessages = false, 526 | $canEditMessages = false, 527 | $canDeleteMessages = false, 528 | $canInviteUsers = false, 529 | $canRestrictMembers = false, 530 | $canPinMessages = false, 531 | $canPromoteMembers = false 532 | ) 533 | { 534 | return $this->api->promoteChatMember([ 535 | 'chat_id' => $chatID, 536 | 'user_id' => $userID, 537 | 'can_change_info' => $canChangeInfo, 538 | 'can_post_messages' => $canPostMessages, 539 | 'can_edit_messages' => $canEditMessages, 540 | 'can_delete_messages' => $canDeleteMessages, 541 | 'can_invite_users' => $canInviteUsers, 542 | 'can_restrict_members' => $canRestrictMembers, 543 | 'can_pin_messages' => $canPinMessages, 544 | 'can_promote_members' => $canPromoteMembers 545 | ]); 546 | 547 | } 548 | 549 | public function exportChatInviteLink($chatID) 550 | { 551 | return $this->api->exportChatInviteLink(['chat_id' => $chatID]); 552 | } 553 | 554 | public function setChatPhoto($chatID, $photo) 555 | { 556 | return $this->api->setChatPhoto(['chat_id' => $chatID, 'photo' => $photo]); 557 | } 558 | 559 | public function deleteChatPhoto($chatID) 560 | { 561 | return $this->api->deleteChatPhoto(['chat_id' => $chatID]); 562 | } 563 | 564 | public function setChatTitle($chatID, $title) 565 | { 566 | return $this->api->setChatTitle(['chat_id' => $chatID, 'title' => $title]); 567 | } 568 | 569 | public function setChatDescription($chatID, $description) 570 | { 571 | return $this->api->setChatDescription(['chat_id' => $chatID, 'description' => $description]); 572 | } 573 | 574 | public function pinChatMessage($chatID, $messID, $disableNotification = false) 575 | { 576 | return $this->api->pinChatMessage(['chat_id' => $chatID, 'message_id' => $messID, 'disable_notification' => $disableNotification]); 577 | } 578 | 579 | public function unpinChatMessage($chatID) 580 | { 581 | return $this->api->unpinChatMessage(['chat_id' => $chatID]); 582 | } 583 | 584 | public function leaveChat($chatID) 585 | { 586 | return $this->api->leaveChat(['chat_id' => $chatID]); 587 | } 588 | 589 | public function getChatMethod($chatID) 590 | { 591 | return $this->api->getChat(['chat_id' => $chatID]); 592 | } 593 | 594 | public function getChatAdministrators($chatID) 595 | { 596 | return $this->api->getChatAdministrators(['chat_id' => $chatID]); 597 | } 598 | 599 | public function getChatMembersCount($chatID) 600 | { 601 | return $this->api->getChatMembersCount(['chat_id' => $chatID]); 602 | } 603 | 604 | public function getChatMember($chatID, $userID) 605 | { 606 | return $this->api->getChatMember(['chat_id' => $chatID, 'user_id' => $userID]); 607 | } 608 | 609 | public function editMessageText($chatID, $messID, $text, $parseMode = false, $disableWebPreview = false, $keyboard = null) 610 | { 611 | $fields = [ 612 | 'chat_id' => $chatID, 613 | 'message_id' => $messID, 614 | 'text' => $text, 615 | 'parse_mode' => $parseMode, 616 | 'disable_web_page_preview' => $disableWebPreview, 617 | 'reply_markup' => (string)$keyboard 618 | ]; 619 | $this->api->editMessageText($fields); 620 | 621 | } 622 | 623 | public function editInlineText($inlineMessID, $text, $parseMode = false, $disableWebPreview = false, $keyboard = null) 624 | { 625 | $fields = [ 626 | 'inline_message_id' => $inlineMessID, 627 | 'text' => $text, 628 | 'parse_mode' => $parseMode, 629 | 'disable_web_page_preview' => $disableWebPreview, 630 | 'reply_markup' => (string)$keyboard 631 | ]; 632 | $this->api->editMessageText($fields); 633 | 634 | } 635 | 636 | public function editMessageCaption($chatID, $messID, $caption, $keyboard = null) 637 | { 638 | $fields = [ 639 | 'chat_id' => $chatID, 640 | 'message_id' => $messID, 641 | 'caption' => $caption, 642 | 'reply_markup' => (string)$keyboard 643 | ]; 644 | $this->api->editMessageCaption($fields); 645 | } 646 | 647 | public function editInlineCaption($inlineMessID, $caption, $keyboard = null) 648 | { 649 | $fields = [ 650 | 'inline_message_id' => $inlineMessID, 651 | 'caption' => $caption, 652 | 'reply_markup' => (string)$keyboard 653 | ]; 654 | $this->api->editMessageCaption($fields); 655 | } 656 | 657 | public function editKeyboard($chatID, $messID, $keyboard) 658 | { 659 | return $this->api->editMessageReplyMarkup(['chat_id' => $chatID, 'message_id' => $messID, 'reply_markup' => (string)$keyboard]); 660 | } 661 | 662 | public function delMessage($chatID, $messID) 663 | { 664 | return $this->api->deleteMessage(['chat_id' => $chatID, 'message_id' => $messID]); 665 | } 666 | 667 | public function sInvoice( 668 | $chatID, 669 | $title, 670 | $description, 671 | $payload, 672 | $token, 673 | $start_parameter, 674 | $currency, 675 | $prices, 676 | $photo = null, 677 | $phSize = null, 678 | $phWidth = null, 679 | $phHeight = null, 680 | $needName = false, 681 | $needNumber = false, 682 | $needEmail = false, 683 | $needAddress = false, 684 | $isFlexible = false, 685 | $disableNotification = false, 686 | $keyboard = false, 687 | $replyID = null 688 | ) 689 | { 690 | $fields = [ 691 | 'chat_id' => $chatID, 692 | 'title' => $title, 693 | 'description' => $description, 694 | 'payload' => $payload, 695 | 'provider_token' => $token, 696 | 'start_parameter' => $start_parameter, 697 | 'currency' => $currency, 698 | 'prices' => $prices, 699 | 'photo_size' => $phSize, 700 | 'photo_width' => $phWidth, 701 | 'photo_height' => $phHeight, 702 | 'need_name' => $needName, 703 | 'need_phone_number' => $needNumber, 704 | 'need_email' => $needEmail, 705 | 'need_shipping_address' => $needAddress, 706 | 'is_flexible' => $isFlexible, 707 | 'disable_notification' => $disableNotification, 708 | 'photo_url' => $photo, 709 | 'reply_markup' => (string)$keyboard 710 | ]; 711 | if ($replyID) $fields['reply_to_message_id'] = $replyID; 712 | return $this->api->sendInvoice($fields); 713 | } 714 | 715 | public function ansPreCheckoutQuery($id, $ok = false, $errorMessage = null) 716 | { 717 | return $this->api->answerPreCheckoutQuery([ 718 | 'pre_checkout_query_id' => $id, 719 | 'ok' => $ok, 720 | 'error_message' => $errorMessage 721 | ]); 722 | } 723 | 724 | public function answerShippingQuery($shippingID, $ok = false, $shippingOptions = null, $errorMessage = null) 725 | { 726 | return $this->api->answerShippingQuery([ 727 | 'shipping_query_id' => $shippingID, 728 | 'ok' => $ok, 729 | 'shipping_options' => $shippingOptions, 730 | 'error_message' => $errorMessage 731 | ]); 732 | } 733 | 734 | public function ansInlineQuery($id, $results, $options = []) 735 | { 736 | $fields = ['inline_query_id' => $id, 'results' => (string) $results]; 737 | $fields = $fields+$options; 738 | return $this->api->answerInlineQuery($fields); 739 | } 740 | } -------------------------------------------------------------------------------- /src/Core/Eventer.php: -------------------------------------------------------------------------------- 1 | '([\d]+)', 12 | '{NUM}' => '([\d])', 13 | '{STR}' => '([\w]+)', 14 | '{STR_S}' => '([\w\s]+)', 15 | '{ANY}' => '(.*?)', 16 | '{SYM}' => '([\w])', 17 | '{ENG}' => '([A-Za-z]+)', 18 | '{ENG_S}' => '([A-Za-z\s]+)', 19 | '{RUS}' => '([А-Яа-яёЁ]+)', 20 | '{RUS_S}' => '([А-Яа-яёЁ\s]+)', 21 | '{UKR}' => '([А-Яа-яЇїІіЄєҐґ]+)', 22 | '{UKR_S}' => '([А-Яа-яЇїІіЄєҐґ\s]+)', 23 | ]; 24 | 25 | protected $customTypes = [ 26 | 'int' => '[\d]+', 27 | 'num' => '[\d]', 28 | 'str' => '[\w]+', 29 | 'str_s' => '[\w\s]+', 30 | 'any' => '(.*?)', 31 | 'chr' => '[\w]', 32 | 'eng' => '[A-Za-z]+', 33 | 'eng_s' => '[A-Za-z\s]+', 34 | 'rus' => '[А-Яа-яёЁ]+', 35 | 'rus_s' => '[А-Яа-яёЁ\s]+', 36 | 'ukr' => '[А-Яа-яЇїІіЄєҐґ]+', 37 | 'ukr_s' => '[А-Яа-яЇїІіЄєҐґ\s]+' 38 | ]; 39 | 40 | protected $handlers; 41 | 42 | protected function addHandler($func) 43 | { 44 | $this->handlers[] = $func; 45 | } 46 | 47 | protected function initParams($param) 48 | { 49 | preg_match_all("{([A-Za-z_]+:[A-Za-z_]+)}", $param, $matches); 50 | $matches = $matches[0]; 51 | foreach ($matches as $preset) { 52 | list($key, $type) = explode(':', $preset); 53 | $param = str_replace('{' . $preset . '}', '(?<' . $key . '>' . $this->customTypes[$type] . ')', $param); 54 | } 55 | return str_replace(array_flip($this->customParams), $this->customParams, $param); 56 | } 57 | 58 | protected function parseCommands(Message $message) 59 | { 60 | $commands = []; 61 | if($message->exists('entities')) { 62 | foreach ($message->entities() as $entity) { 63 | if ($entity->type() == 'bot_command') { 64 | $commands[] = mb_substr($message->text(), $entity->offset(), $entity->length()); 65 | } 66 | } 67 | } 68 | return $commands; 69 | } 70 | 71 | protected function parseParams($matches) 72 | { 73 | $output = []; 74 | foreach ($matches as $k => $match) { 75 | if (is_string($k)) $output[$k] = $match; 76 | } 77 | return $output; 78 | } 79 | 80 | public function txt($text, $func, $regex = false, $anyCase = true) 81 | { 82 | $case = $anyCase ? 'i' : ''; 83 | $text = !$regex ? '#^' . $this->initParams($text) . '$#u' . $case : $text; 84 | $this->addHandler(function (Context $ctx) use ($text, $func) { 85 | if (!$ctx->update->exists('message') or !$ctx->update->message()->exists('text')) return false; 86 | if (preg_match($text, $ctx->getText(), $matches)) { 87 | $ctx->params = $this->parseParams($matches); 88 | $func($ctx, $matches); 89 | return true; 90 | } 91 | return false; 92 | }); 93 | } 94 | 95 | public function cmd($command, $func) 96 | { 97 | $this->addHandler(function (Context $ctx) use ($command, $func) { 98 | if (!$ctx->update->exists('message') or !$ctx->update->message()->exists('entities')) return false; 99 | $commands = $this->parseCommands($ctx->update->message()); 100 | if (count($commands) == 0) return false; 101 | foreach ($commands as $cmd) { 102 | if ('/' . $command == $cmd) { 103 | $func($ctx); 104 | return true; 105 | } 106 | } 107 | return false; 108 | }); 109 | } 110 | 111 | public function hears($text, $func) 112 | { 113 | if (is_array($text)) { 114 | foreach ($text as $string) { 115 | $this->txt("/$string/iu", $func, true); 116 | } 117 | } else $this->txt("/$text/iu", $func, true); 118 | } 119 | 120 | public function onMessage($field, $func) 121 | { 122 | $this->addHandler(function (Context $ctx) use ($field, $func) { 123 | if ($ctx->update->exists('message') and $ctx->update->message()->exists($field)) { 124 | $func($ctx); 125 | return true; 126 | } 127 | return false; 128 | }); 129 | } 130 | 131 | public function onUpdate($field, $func) 132 | { 133 | $this->addHandler(function (Context $ctx) use ($field, $func) { 134 | if ($ctx->update->exists($field)) { 135 | $func($ctx); 136 | return true; 137 | } 138 | return false; 139 | }); 140 | } 141 | 142 | public function act($act, $func, $regex = false, $anyCase = true) 143 | { 144 | $case = $anyCase ? 'i' : ''; 145 | $act = !$regex ? '#^' . $this->initParams($act) . '$#u' . $case : $act; 146 | $this->addHandler(function (Context $ctx) use ($act, $func) { 147 | if($ctx->callbackQuery()!=null) { 148 | if (preg_match($act, $ctx->callbackQuery()->data(), $matches)) { 149 | $ctx->params = $this->parseParams($matches); 150 | $func($ctx, $matches); 151 | return true; 152 | } 153 | } 154 | return false; 155 | }); 156 | } 157 | 158 | public function inlQuery($query, $func, $regex = false, $anyCase = true) 159 | { 160 | $case = $anyCase ? 'i' : ''; 161 | $query = !$regex ? '#^' . $this->initParams($query) . '$#u' . $case : $query; 162 | $this->addHandler(function(Context $ctx) use ($query, $func) { 163 | if($ctx->inlineQuery()!=null) { 164 | if (preg_match($query, $ctx->inlineQuery()->query(), $matches)) { 165 | $ctx->params = $this->parseParams($matches); 166 | $func($ctx, $matches); 167 | return true; 168 | } 169 | } 170 | return false; 171 | }); 172 | } 173 | } -------------------------------------------------------------------------------- /src/Interfaces/UserInterface.php: -------------------------------------------------------------------------------- 1 | __data->file_id; 13 | } 14 | 15 | public function width() : int 16 | { 17 | return $this->__data->width; 18 | } 19 | 20 | public function height() : int 21 | { 22 | return $this->__data->height; 23 | } 24 | 25 | public function duration() : int 26 | { 27 | return $this->__data->duration; 28 | } 29 | 30 | public function thumb() : ?PhotoSize 31 | { 32 | return isset($this->__data->thumb) ? new PhotoSize($this->__data->thumb) : null; 33 | } 34 | 35 | public function fileName() : ?string 36 | { 37 | return $this->__data->file_name ?? null; 38 | } 39 | 40 | public function mimeType() : ?string 41 | { 42 | return $this->__data->mime_type ?? null; 43 | } 44 | 45 | public function fileSize() : ?int 46 | { 47 | return $this->__data->file_size ?? null; 48 | } 49 | } -------------------------------------------------------------------------------- /src/Types/Audio.php: -------------------------------------------------------------------------------- 1 | __data->file_id; 14 | } 15 | 16 | public function duration() : int 17 | { 18 | return $this->__data->duration; 19 | } 20 | 21 | public function performer() : ?string 22 | { 23 | return $this->__data->performer ?? null; 24 | } 25 | 26 | public function title() : ?string 27 | { 28 | return $this->__data->title ?? null; 29 | } 30 | 31 | public function mimeType() : ?string 32 | { 33 | return $this->__data->mime_type ?? null; 34 | } 35 | 36 | public function fileSize() : ?int 37 | { 38 | return $this->__data->file_size ?? null; 39 | } 40 | 41 | public function thumb() : ?PhotoSize 42 | { 43 | return isset($this->__data->thumb) ? new PhotoSize($this->__data->thumb) : null; 44 | } 45 | } -------------------------------------------------------------------------------- /src/Types/Base/Base.php: -------------------------------------------------------------------------------- 1 | __data = $data; 12 | } 13 | 14 | public function exists($param) 15 | { 16 | return isset($this->__data->$param); 17 | } 18 | 19 | public function __get($param) 20 | { 21 | return $this->__data->$param; 22 | } 23 | } -------------------------------------------------------------------------------- /src/Types/CallbackQuery.php: -------------------------------------------------------------------------------- 1 | __data->id; 13 | } 14 | 15 | public function from() : User 16 | { 17 | return new User($this->__data->from); 18 | } 19 | 20 | public function message() : ?Message 21 | { 22 | return isset($this->__data->message) ? new Message($this->__data->message) : null; 23 | } 24 | 25 | public function inlineMessageId() : ?string 26 | { 27 | return $this->__data->inline_message_id ?? null; 28 | } 29 | 30 | public function chatInstance() : string 31 | { 32 | return $this->__data->chat_instance; 33 | } 34 | 35 | public function data() : ?string 36 | { 37 | return $this->__data->data ?? null; 38 | } 39 | 40 | public function gameShortName() : ?string 41 | { 42 | return $this->__data->game_short_name ?? null; 43 | } 44 | } -------------------------------------------------------------------------------- /src/Types/Chat.php: -------------------------------------------------------------------------------- 1 | __data->id; 14 | } 15 | 16 | public function type() : string 17 | { 18 | return $this->__data->type; 19 | } 20 | 21 | public function title() : ?string 22 | { 23 | return $this->__data->title ?? null; 24 | } 25 | 26 | public function username() : ?string 27 | { 28 | return $this->__data->username ?? null; 29 | } 30 | 31 | public function firstName() : ?string 32 | { 33 | return $this->__data->first_name ?? null; 34 | } 35 | 36 | public function lastName() : ?string 37 | { 38 | return $this->__data->last_name ?? null; 39 | } 40 | 41 | public function allMembersAreAdministrators() : ?bool 42 | { 43 | return $this->__data->all_members_are_administrators ?? null; 44 | } 45 | 46 | public function photo() : ChatPhoto 47 | { 48 | return new ChatPhoto($this->__data->photo); 49 | } 50 | 51 | public function description() : ?string 52 | { 53 | return $this->__data->description ?? null; 54 | } 55 | 56 | public function inviteLink() : ?string 57 | { 58 | return $this->__data->invite_link ?? null; 59 | } 60 | 61 | public function pinnedMessage() : ?Message 62 | { 63 | return isset($this->__data->pinned_message) ? new Message($this->__data->pinned_message) : null; 64 | } 65 | 66 | public function stickerSetName() : ?string 67 | { 68 | return $this->__data->sticker_set_name ?? null; 69 | } 70 | 71 | public function canSetStickerSet() : ?bool 72 | { 73 | return $this->__data->can_set_sticker_set ?? null; 74 | } 75 | } -------------------------------------------------------------------------------- /src/Types/ChatMember.php: -------------------------------------------------------------------------------- 1 | __data->user) ? new User($this->__data->user) : null; 13 | } 14 | 15 | public function status() : string 16 | { 17 | return $this->__data->status; 18 | } 19 | 20 | public function untilDate() : ?int 21 | { 22 | return $this->__data->until_date ?? null; 23 | } 24 | 25 | public function canBeEdited() : ?bool 26 | { 27 | return $this->__data->can_be_edited ?? null; 28 | } 29 | 30 | public function canChangeInfo() : ?bool 31 | { 32 | return $this->__data->can_change_info ?? null; 33 | } 34 | 35 | public function canPostMessages() : ?bool 36 | { 37 | return $this->__data->can_post_messages ?? null; 38 | } 39 | 40 | public function canEditMessages() : ?bool 41 | { 42 | return $this->__data->can_edit_messages ?? null; 43 | } 44 | 45 | public function canDeleteMessages() : ?bool 46 | { 47 | return $this->__data->can_delete_messages ?? null; 48 | } 49 | 50 | public function canInviteUsers() : ?bool 51 | { 52 | return $this->__data->can_invite_users ?? null; 53 | } 54 | 55 | public function canRestrictMembers() : ?bool 56 | { 57 | return $this->__data->can_restrict_members ?? null; 58 | } 59 | 60 | public function canPinMessages() : ?bool 61 | { 62 | return $this->__data->can_pin_messages ?? null; 63 | } 64 | 65 | public function canPromoteMembers() : ?bool 66 | { 67 | return $this->__data->can_promote_members ?? null; 68 | } 69 | 70 | public function canSendMessages() : ?bool 71 | { 72 | return $this->__data->can_send_messages ?? null; 73 | } 74 | 75 | public function canSendMediaMessages() : ?bool 76 | { 77 | return $this->__data->can_send_media_messages ?? null; 78 | } 79 | 80 | public function canSendOtherMessages() : ?bool 81 | { 82 | return $this->__data->can_send_other_messages ?? null; 83 | } 84 | 85 | public function canAddWebPagePreviews() : ?bool 86 | { 87 | return $this->__data->can_add_web_page_previews ?? null; 88 | } 89 | } -------------------------------------------------------------------------------- /src/Types/ChatPhoto.php: -------------------------------------------------------------------------------- 1 | __data->small_file_id; 14 | } 15 | 16 | public function bigFileId() : string 17 | { 18 | return $this->__data->big_file_id; 19 | } 20 | } -------------------------------------------------------------------------------- /src/Types/ChosenInlineResult.php: -------------------------------------------------------------------------------- 1 | __data->result_id; 13 | } 14 | 15 | public function from() : User 16 | { 17 | return new User($this->__data->from); 18 | } 19 | 20 | public function location() : ?Location 21 | { 22 | return isset($this->__data->location) ? new Location($this->__data->location) : null; 23 | } 24 | 25 | public function inlineMessageId() : ?string 26 | { 27 | return $this->__data->inline_message_id ?? null; 28 | } 29 | 30 | public function query() : string 31 | { 32 | return $this->__data->query; 33 | } 34 | } -------------------------------------------------------------------------------- /src/Types/Contact.php: -------------------------------------------------------------------------------- 1 | __data->phone_number ?? null; 13 | } 14 | 15 | public function firstName() : string 16 | { 17 | return $this->__data->first_name; 18 | } 19 | 20 | public function lastName() : ?string 21 | { 22 | return $this->__data->last_name ?? null; 23 | } 24 | 25 | public function userId() : ?int 26 | { 27 | return $this->__data->user_id ?? null; 28 | } 29 | 30 | public function vcard() : ?string 31 | { 32 | return $this->__data->vcard ?? null; 33 | } 34 | } -------------------------------------------------------------------------------- /src/Types/Document.php: -------------------------------------------------------------------------------- 1 | __data->file_id; 13 | } 14 | 15 | public function thumb() : ?PhotoSize 16 | { 17 | return isset($this->__data->thumb) ? new PhotoSize($this->__data->thumb) : null; 18 | } 19 | 20 | public function fileName() : ?string 21 | { 22 | return $this->__data->file_name ?? null; 23 | } 24 | 25 | public function mimeType() : ?string 26 | { 27 | return $this->__data->mime_type ?? null; 28 | } 29 | 30 | public function fileSize() : ?int 31 | { 32 | return $this->__data->file_size ?? null; 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /src/Types/EncryptedCredentials.php: -------------------------------------------------------------------------------- 1 | __data->data; 13 | } 14 | 15 | public function hash() : string 16 | { 17 | return $this->__data->hash; 18 | } 19 | 20 | public function secret() : string 21 | { 22 | return $this->__data->secret; 23 | } 24 | } -------------------------------------------------------------------------------- /src/Types/EncryptedPassportElement.php: -------------------------------------------------------------------------------- 1 | __data->type; 13 | } 14 | 15 | public function data() : ?string 16 | { 17 | return $this->__data->data ?? null; 18 | } 19 | 20 | public function phoneNumber() : ?string 21 | { 22 | return $this->__data->phone_number ?? null; 23 | } 24 | 25 | public function email() : ?string 26 | { 27 | return $this->__data->email ?? null; 28 | } 29 | 30 | /** 31 | * @return PassportFile[] 32 | */ 33 | public function files() : ?array 34 | { 35 | if(isset($this->__data->files)) { 36 | foreach ($this->__data->files as $key => $data) { 37 | $this->__data->files[$key] = new PassportFile($data); 38 | } 39 | return $this->__data->files; 40 | } else return null; 41 | } 42 | 43 | /** 44 | * @return PassportFile[] 45 | */ 46 | public function frontSide() : ?array 47 | { 48 | if(isset($this->__data->front_side)) { 49 | foreach ($this->__data->front_side as $key => $data) { 50 | $this->__data->front_side[$key] = new PassportFile($data); 51 | } 52 | return $this->__data->front_side; 53 | } else return null; 54 | } 55 | 56 | /** 57 | * @return PassportFile[] 58 | */ 59 | public function reverseSide() : ?array 60 | { 61 | if(isset($this->__data->reverse_side)) { 62 | foreach ($this->__data->reverse_side as $key => $data) { 63 | $this->__data->reverse_side[$key] = new PassportFile($data); 64 | } 65 | return $this->__data->reverse_side; 66 | } else return null; 67 | } 68 | 69 | /** 70 | * @return PassportFile[] 71 | */ 72 | public function selfie() : ?array 73 | { 74 | if(isset($this->__data->selfie)) { 75 | foreach ($this->__data->selfie as $key => $data) { 76 | $this->__data->selfie[$key] = new PassportFile($data); 77 | } 78 | return $this->__data->selfie; 79 | } else return null; 80 | } 81 | 82 | /** 83 | * @return PassportFile[] 84 | */ 85 | public function translation() : ?array 86 | { 87 | if(isset($this->__data->translation)) { 88 | foreach ($this->__data->translation as $key => $data) { 89 | $this->__data->translation[$key] = new PassportFile($data); 90 | } 91 | return $this->__data->translation; 92 | } else return null; 93 | } 94 | 95 | public function hash() : string 96 | { 97 | return $this->__data->hash; 98 | } 99 | } -------------------------------------------------------------------------------- /src/Types/File.php: -------------------------------------------------------------------------------- 1 | __data->file_id; 13 | } 14 | 15 | public function fileSize() : ?int 16 | { 17 | return $this->__data->file_size ?? null; 18 | } 19 | 20 | public function filePath() : ?string 21 | { 22 | return $this->__data->file_path ?? null; 23 | } 24 | } -------------------------------------------------------------------------------- /src/Types/Game.php: -------------------------------------------------------------------------------- 1 | __data->title; 13 | } 14 | 15 | public function description() : string 16 | { 17 | return $this->__data->description; 18 | } 19 | 20 | public function photo() : array 21 | { 22 | return $this->__data->photo; 23 | } 24 | 25 | public function text() : ?string 26 | { 27 | return $this->__data->text ?? null; 28 | } 29 | 30 | /** 31 | * @return MessageEntity[] 32 | */ 33 | public function text_entities() : ?array 34 | { 35 | if(isset($this->__data->text_entities)) { 36 | foreach ($this->__data->text_entities as $key => $entity) { 37 | $this->__data->text_entities[$key] = new MessageEntity($entity); 38 | } 39 | return $this->__data->text_entities; 40 | } else return null; 41 | } 42 | 43 | public function animation() : ?Animation 44 | { 45 | return isset($this->__data->animation) ? new Animation($this->__data->animation) : null; 46 | } 47 | } -------------------------------------------------------------------------------- /src/Types/InlineQuery.php: -------------------------------------------------------------------------------- 1 | __data->id; 13 | } 14 | 15 | public function from() : User 16 | { 17 | return new User($this->__data->from); 18 | } 19 | 20 | public function location() : ?Location 21 | { 22 | return isset($this->__data->location) ? new Location($this->__data->location) : null; 23 | } 24 | 25 | public function query() : string 26 | { 27 | return $this->__data->query; 28 | } 29 | 30 | public function offset() : string 31 | { 32 | return $this->__data->offset; 33 | } 34 | } -------------------------------------------------------------------------------- /src/Types/Invoice.php: -------------------------------------------------------------------------------- 1 | __data->title; 13 | } 14 | 15 | public function description() : string 16 | { 17 | return $this->__data->description; 18 | } 19 | 20 | public function startParameter() : string 21 | { 22 | return $this->__data->start_parameter; 23 | } 24 | 25 | public function currency() : string 26 | { 27 | return $this->__data->currency; 28 | } 29 | 30 | public function totalAmount() : int 31 | { 32 | return $this->__data->total_amount; 33 | } 34 | } -------------------------------------------------------------------------------- /src/Types/Location.php: -------------------------------------------------------------------------------- 1 | __data->longitude; 13 | } 14 | 15 | public function latitude() : float 16 | { 17 | return $this->__data->latitude; 18 | } 19 | } -------------------------------------------------------------------------------- /src/Types/MaskPosition.php: -------------------------------------------------------------------------------- 1 | __data->point; 13 | } 14 | 15 | public function xShift() : float 16 | { 17 | return $this->__data->x_shift; 18 | } 19 | 20 | public function yShift() : float 21 | { 22 | return $this->__data->y_shift; 23 | } 24 | 25 | public function scale() : float 26 | { 27 | return $this->__data->scale; 28 | } 29 | } -------------------------------------------------------------------------------- /src/Types/Message.php: -------------------------------------------------------------------------------- 1 | __data->message_id; 14 | } 15 | 16 | public function from() : ?User 17 | { 18 | return isset($this->__data->from) ? new User($this->__data->from) : null; 19 | } 20 | 21 | public function date() : int 22 | { 23 | return $this->__data->date; 24 | } 25 | 26 | public function chat() : Chat 27 | { 28 | return new Chat($this->__data->chat); 29 | } 30 | 31 | public function forwardFrom() : ?User 32 | { 33 | return isset($this->__data->forward_from) ? new User($this->__data->forward_from) : null; 34 | } 35 | 36 | public function forwardFromChat() : ?Chat 37 | { 38 | return isset($this->__data->forward_from_chat) ? new Chat($this->__data->forward_from_chat) : null; 39 | } 40 | 41 | public function forwardFromMessageId() : ?int 42 | { 43 | return $this->__data->forward_from_message_id ?? null; 44 | } 45 | 46 | public function forwardSignature() : ?string 47 | { 48 | return $this->__data->forward_signature ?? null; 49 | } 50 | 51 | public function forwardDate() : ?int 52 | { 53 | return $this->__data->forward_date ?? null; 54 | } 55 | 56 | public function replyToMessage() : ?Message 57 | { 58 | return isset($this->__data->reply_to_message) ? new Message($this->__data->reply_to_message) : null; 59 | } 60 | 61 | public function editDate() : ?int 62 | { 63 | return $this->__data->edit_date ?? null; 64 | } 65 | 66 | public function mediaGroupId() : ?string 67 | { 68 | return $this->__data->media_group_id ?? null; 69 | } 70 | 71 | public function authorSignature() : ?string 72 | { 73 | return $this->__data->author_signature ?? null; 74 | } 75 | 76 | public function text() : ?string 77 | { 78 | return $this->__data->text ?? null; 79 | } 80 | 81 | /** 82 | * @return MessageEntity[] 83 | */ 84 | public function entities() : ?array 85 | { 86 | if(isset($this->__data->entities)) { 87 | foreach ($this->__data->entities as $key => $entity) { 88 | $this->__data->entities[$key] = new MessageEntity($entity); 89 | } 90 | return $this->__data->entities; 91 | } else return null; 92 | } 93 | 94 | 95 | /** 96 | * @return MessageEntity[] 97 | */ 98 | public function caption_entities() : ?array 99 | { 100 | if(isset($this->__data->caption_entities)) { 101 | foreach ($this->__data->caption_entities as $key => $entity) { 102 | $this->__data->caption_entities[$key] = new MessageEntity($entity); 103 | } 104 | return $this->__data->caption_entities; 105 | } else return null; 106 | } 107 | 108 | public function audio() : ?Audio 109 | { 110 | return isset($this->__data->audio) ? new Audio($this->__data->audio) : null; 111 | } 112 | 113 | public function document() : ?Document 114 | { 115 | return isset($this->__data->document) ? new Document($this->__data->document) : null; 116 | } 117 | 118 | public function animation() : ?Animation 119 | { 120 | return isset($this->__data->animation) ? new Animation($this->__data->animation) : null; 121 | } 122 | 123 | public function game() : ?Game 124 | { 125 | return isset($this->__data->animation) ? new Game($this->__data->animation) : null; 126 | } 127 | 128 | /** 129 | * @return PhotoSize[] 130 | */ 131 | public function photo() : ?array 132 | { 133 | if(isset($this->__data->photo)) { 134 | foreach ($this->__data->photo as $key => $photo) { 135 | $this->__data->photo[$key] = new PhotoSize($photo); 136 | } 137 | return $this->__data->photo; 138 | } else return null; 139 | } 140 | 141 | public function sticker() : ?Sticker 142 | { 143 | return isset($this->__data->sticker) ? new Sticker($this->__data->sticker) : null; 144 | } 145 | 146 | public function video() : ?Video 147 | { 148 | return isset($this->__data->video) ? new Video($this->__data->video) : null; 149 | } 150 | 151 | public function voice() : ?Voice 152 | { 153 | return isset($this->__data->voice) ? new Voice($this->__data->voice) : null; 154 | } 155 | 156 | public function videoNote() : ?VideoNote 157 | { 158 | return isset($this->__data->video_note) ? new VideoNote($this->__data->video_note) : null; 159 | } 160 | 161 | public function caption() : ?string 162 | { 163 | return $this->__data->caption ?? null; 164 | } 165 | 166 | public function contact() : ?Contact 167 | { 168 | return isset($this->__data->contact) ? new Contact($this->__data->contact) : null; 169 | } 170 | 171 | public function location() : ?Location 172 | { 173 | return isset($this->__data->location) ? new Location($this->__data->location) : null; 174 | } 175 | 176 | public function venue() : ?Venue 177 | { 178 | return isset($this->__data->venue) ? new Venue($this->__data->venue) : null; 179 | } 180 | 181 | /** 182 | * @return User[] 183 | */ 184 | public function newChatMembers() : ?array 185 | { 186 | if(isset($this->__data->new_chat_members)) { 187 | foreach ($this->__data->new_chat_members as $key => $user) { 188 | $this->__data->new_chat_members[$key] = new User($user); 189 | } 190 | return $this->__data->new_chat_members; 191 | } else return null; 192 | } 193 | 194 | public function leftChatMember() : ?User 195 | { 196 | return isset($this->__data->left_chat_member) ? new User($this->__data->left_chat_member) : null; 197 | } 198 | 199 | public function newChatTitle() : ?string 200 | { 201 | return $this->__data->new_chat_title ?? null; 202 | } 203 | 204 | /** 205 | * @return PhotoSize[] 206 | */ 207 | public function newChatPhoto() : ?array 208 | { 209 | if(isset($this->__data->new_chat_photo)) { 210 | foreach ($this->__data->new_chat_photo as $key => $photo) { 211 | $this->__data->new_chat_photo[$key] = new PhotoSize($photo); 212 | } 213 | return $this->__data->new_chat_photo; 214 | } else return null; 215 | } 216 | 217 | public function deleteChatPhoto() : ?bool 218 | { 219 | return $this->__data->delete_chat_photo ?? null; 220 | } 221 | 222 | public function groupChatCreated() : ?bool 223 | { 224 | return $this->__data->group_chat_created ?? null; 225 | } 226 | 227 | public function supergroupChatCreated() : ?bool 228 | { 229 | return $this->__data->supergroup_chat_created ?? null; 230 | } 231 | 232 | public function channelChatCreated() : ?bool 233 | { 234 | return $this->__data->channel_chat_created ?? null; 235 | } 236 | 237 | public function migrateToChatId() : ?int 238 | { 239 | return $this->__data->migrate_to_chat_id ?? null; 240 | } 241 | 242 | public function migrateFromChatId() : ?int 243 | { 244 | return $this->__data->migrate_from_chat_id ?? null; 245 | } 246 | 247 | public function pinnedMessage() : ?Message 248 | { 249 | return isset($this->__data->pinned_message) ? new Message($this->__data->pinned_message) : null; 250 | } 251 | 252 | public function invoice() : ?Invoice 253 | { 254 | return isset($this->__data->invoice) ? new Invoice($this->__data->invoice) : null; 255 | } 256 | 257 | public function successfulPayment() : ?SuccessfulPayment 258 | { 259 | return isset($this->__data->successful_payment) ? new SuccessfulPayment($this->__data->successful_payment) : null; 260 | } 261 | 262 | public function connectedWebsite() : ?string 263 | { 264 | return $this->__data->connected_website ?? null; 265 | } 266 | 267 | public function passportData() : ?PassportData 268 | { 269 | return isset($this->__data->passport_data) ? new PassportData($this->__data->passport_data) : null; 270 | } 271 | 272 | } -------------------------------------------------------------------------------- /src/Types/MessageEntity.php: -------------------------------------------------------------------------------- 1 | __data->type; 14 | } 15 | 16 | public function offset() : int 17 | { 18 | return $this->__data->offset; 19 | } 20 | 21 | public function length() : int 22 | { 23 | return $this->__data->length; 24 | } 25 | 26 | public function url() : ?string 27 | { 28 | return $this->__data->url ?? null; 29 | } 30 | 31 | public function user() : ?User 32 | { 33 | return isset($this->__data->user) ? new User($this->__data->user) : null; 34 | } 35 | } -------------------------------------------------------------------------------- /src/Types/OrderInfo.php: -------------------------------------------------------------------------------- 1 | __data->name ?? null; 13 | } 14 | 15 | public function phoneNumber() : ?string 16 | { 17 | return $this->__data->phone_number ?? null; 18 | } 19 | 20 | public function email() : ?string 21 | { 22 | return $this->__data->email ?? null; 23 | } 24 | 25 | public function shippingAddress() : ?ShippingAddress 26 | { 27 | return isset($this->__data->shipping_address) ? new ShippingAddress($this->__data->shipping_address) : null; 28 | } 29 | } -------------------------------------------------------------------------------- /src/Types/PassportData.php: -------------------------------------------------------------------------------- 1 | __data->data)) { 16 | foreach ($this->__data->data as $key => $data) { 17 | $this->__data->data[$key] = new EncryptedPassportElement($data); 18 | } 19 | return $this->__data->data; 20 | } else return null; 21 | } 22 | 23 | public function credentials() : ?EncryptedCredentials 24 | { 25 | return isset($this->__data->credentials) ? new EncryptedCredentials($this->__data->credentials) : null; 26 | } 27 | } -------------------------------------------------------------------------------- /src/Types/PassportFile.php: -------------------------------------------------------------------------------- 1 | __data->file_id; 13 | } 14 | 15 | public function fileSize() : int 16 | { 17 | return $this->__data->file_size; 18 | } 19 | 20 | public function fileDate() : int 21 | { 22 | return $this->__data->file_date; 23 | } 24 | } -------------------------------------------------------------------------------- /src/Types/PhotoSize.php: -------------------------------------------------------------------------------- 1 | __data->file_id; 13 | } 14 | 15 | public function width() : int 16 | { 17 | return $this->__data->width; 18 | } 19 | 20 | public function height() : int 21 | { 22 | return $this->__data->height; 23 | } 24 | 25 | public function fileSize() : ?int 26 | { 27 | return $this->__data->file_size ?? null; 28 | } 29 | } -------------------------------------------------------------------------------- /src/Types/PreCheckoutQuery.php: -------------------------------------------------------------------------------- 1 | __data->id; 13 | } 14 | 15 | public function from() : User 16 | { 17 | return new User($this->__data->from); 18 | } 19 | 20 | public function currency() : string 21 | { 22 | return $this->__data->currency; 23 | } 24 | 25 | public function totalAmount() : int 26 | { 27 | return $this->__data->total_amount; 28 | } 29 | 30 | public function invoicePayload() : string 31 | { 32 | return $this->__data->invoice_payload; 33 | } 34 | 35 | public function shippingOptionId() : ?string 36 | { 37 | return $this->__data->shipping_option_id ?? null; 38 | } 39 | 40 | public function orderInfo() : ?OrderInfo 41 | { 42 | return isset($this->__data->order_info) ? new OrderInfo($this->__data->order_info) : null; 43 | } 44 | } -------------------------------------------------------------------------------- /src/Types/ShippingAddress.php: -------------------------------------------------------------------------------- 1 | __data->country_code; 13 | } 14 | 15 | public function state() : string 16 | { 17 | return $this->__data->state; 18 | } 19 | 20 | public function city() : string 21 | { 22 | return $this->__data->city; 23 | } 24 | 25 | public function streetLine1() : string 26 | { 27 | return $this->__data->street_line1; 28 | } 29 | 30 | public function streetLine2() : string 31 | { 32 | return $this->__data->street_line2; 33 | } 34 | 35 | public function postCode() : string 36 | { 37 | return $this->__data->post_code; 38 | } 39 | } -------------------------------------------------------------------------------- /src/Types/ShippingQuery.php: -------------------------------------------------------------------------------- 1 | __data->id; 13 | } 14 | 15 | public function from() : User 16 | { 17 | return new User($this->__data->from); 18 | } 19 | 20 | public function invoicePayload() : string 21 | { 22 | return $this->__data->invoice_payload; 23 | } 24 | 25 | public function shippingAddress() : ShippingAddress 26 | { 27 | return new ShippingAddress($this->__data->shipping_address); 28 | } 29 | } -------------------------------------------------------------------------------- /src/Types/Sticker.php: -------------------------------------------------------------------------------- 1 | __data->file_id; 13 | } 14 | 15 | public function width() : int 16 | { 17 | return $this->__data->width; 18 | } 19 | 20 | public function height() : int 21 | { 22 | return $this->__data->height; 23 | } 24 | 25 | public function thumb() : ?PhotoSize 26 | { 27 | return isset($this->__data->thumb) ? new PhotoSize($this->__data->thumb) : null; 28 | } 29 | 30 | public function emoji() : ?string 31 | { 32 | return $this->__data->emoji ?? null; 33 | } 34 | 35 | public function setName() : ?string 36 | { 37 | return $this->__data->set_name ?? null; 38 | } 39 | 40 | public function maskPosition() : ?MaskPosition 41 | { 42 | return isset($this->__data->mask_position) ? new MaskPosition($this->__data->mask_position) : null; 43 | } 44 | 45 | public function fileSize() : ?int 46 | { 47 | return $this->__data->file_size ?? null; 48 | } 49 | } -------------------------------------------------------------------------------- /src/Types/SuccessfulPayment.php: -------------------------------------------------------------------------------- 1 | __data->currency; 13 | } 14 | 15 | public function totalAmount() : int 16 | { 17 | return $this->__data->total_amount; 18 | } 19 | 20 | public function invoicePayload() : string 21 | { 22 | return $this->__data->invoice_payload; 23 | } 24 | 25 | public function shippingOptionId() : string 26 | { 27 | return $this->__data->shipping_option_id; 28 | } 29 | 30 | public function orderInfo() : ?OrderInfo 31 | { 32 | return isset($this->__data->order_info) ? new OrderInfo($this->__data->order_info) : null; 33 | } 34 | 35 | public function telegramPaymentChargeId() : string 36 | { 37 | return $this->__data->telegram_payment_charge_id; 38 | } 39 | 40 | public function providerPaymentChargeId() : string 41 | { 42 | return $this->__data->provider_payment_charge_id; 43 | } 44 | } -------------------------------------------------------------------------------- /src/Types/Update.php: -------------------------------------------------------------------------------- 1 | __data->update_id; 12 | } 13 | 14 | public function message() : ?Message 15 | { 16 | return isset($this->__data->message) ? new Message($this->__data->message) : null; 17 | } 18 | 19 | public function editedMessage() : ?Message 20 | { 21 | return isset($this->__data->edited_message) ? new Message($this->__data->edited_message) : null; 22 | } 23 | 24 | public function channelPost() : ?Message 25 | { 26 | return isset($this->__data->channel_post) ? new Message($this->__data->channel_post) : null; 27 | } 28 | 29 | public function editedChannelPost() : ?Message 30 | { 31 | return isset($this->__data->edited_channel_post) ? new Message($this->__data->edited_channel_post) : null; 32 | } 33 | 34 | public function inlineQuery() : ?InlineQuery 35 | { 36 | return isset($this->__data->inline_query) ? new InlineQuery($this->__data->inline_query) : null; 37 | } 38 | 39 | public function chosenInlineResult() : ?ChosenInlineResult 40 | { 41 | return isset($this->__data->chosen_inline_result) ? new ChosenInlineResult($this->__data->chosen_inline_result) : null; 42 | } 43 | 44 | public function callbackQuery() : ?CallbackQuery 45 | { 46 | return isset($this->__data->callback_query) ? new CallbackQuery($this->__data->callback_query) : null; 47 | } 48 | 49 | public function shippingQuery() : ?ShippingQuery 50 | { 51 | return isset($this->__data->shipping_query) ? new ShippingQuery($this->__data->shipping_query) : null; 52 | } 53 | 54 | public function preCheckoutQuery() : ?PreCheckoutQuery 55 | { 56 | return isset($this->__data->pre_checkout_query) ? new PreCheckoutQuery($this->__data->pre_checkout_query) : null; 57 | } 58 | 59 | } -------------------------------------------------------------------------------- /src/Types/User.php: -------------------------------------------------------------------------------- 1 | __data->id; 14 | } 15 | 16 | public function isBot() : bool 17 | { 18 | return $this->__data->is_bot; 19 | } 20 | 21 | public function firstName() : string 22 | { 23 | return $this->__data->first_name; 24 | } 25 | 26 | public function lastName() : ?string 27 | { 28 | return $this->__data->last_name ?? null; 29 | } 30 | 31 | public function username() : ?string 32 | { 33 | return $this->__data->username ?? null; 34 | } 35 | 36 | public function languageCode() : ?string 37 | { 38 | return $this->__data->language_code ?? null; 39 | } 40 | } -------------------------------------------------------------------------------- /src/Types/UserProfilePhotos.php: -------------------------------------------------------------------------------- 1 | __data->total_count; 13 | } 14 | 15 | /** 16 | * @return PhotoSize[][] 17 | */ 18 | public function photos() : array 19 | { 20 | foreach($this->__data->photos as $aopKey => $arrayOfPhotos ) { 21 | foreach ($arrayOfPhotos as $key => $photo) { 22 | $arrayOfPhotos[$key] = new PhotoSize($photo); 23 | } 24 | $this->__data->photos[$aopKey] = $arrayOfPhotos; 25 | } 26 | return $this->__data->photos; 27 | } 28 | } -------------------------------------------------------------------------------- /src/Types/Venue.php: -------------------------------------------------------------------------------- 1 | __data->location); 13 | } 14 | 15 | public function title() : string 16 | { 17 | return $this->__data->title; 18 | } 19 | 20 | public function address() : string 21 | { 22 | return $this->__data->address; 23 | } 24 | 25 | public function foursquareId() : ?string 26 | { 27 | return $this->__data->foursquare_id ?? null; 28 | } 29 | 30 | public function foursquareType() : ?string 31 | { 32 | return $this->__data->foursquare_type ?? null; 33 | } 34 | } -------------------------------------------------------------------------------- /src/Types/Video.php: -------------------------------------------------------------------------------- 1 | __data->file_id; 13 | } 14 | 15 | public function width() : int 16 | { 17 | return $this->__data->width; 18 | } 19 | 20 | public function height() : int 21 | { 22 | return $this->__data->height; 23 | } 24 | 25 | public function duration() : int 26 | { 27 | return $this->__data->duration; 28 | } 29 | 30 | public function thumb() : ?PhotoSize 31 | { 32 | return isset($this->__data->thumb) ? new PhotoSize($this->__data->thumb) : null; 33 | } 34 | 35 | public function mimeType() : ?string 36 | { 37 | return $this->__data->mime_type ?? null; 38 | } 39 | 40 | public function fileSize() : ?int 41 | { 42 | return $this->__data->file_size ?? null; 43 | } 44 | } -------------------------------------------------------------------------------- /src/Types/VideoNote.php: -------------------------------------------------------------------------------- 1 | __data->file_id; 13 | } 14 | 15 | public function length() : int 16 | { 17 | return $this->__data->length; 18 | } 19 | 20 | public function duration() : int 21 | { 22 | return $this->__data->duration; 23 | } 24 | 25 | public function thumb() : ?PhotoSize 26 | { 27 | return isset($this->__data->thumb) ? new PhotoSize($this->__data->thumb) : null; 28 | } 29 | 30 | public function fileSize() : ?int 31 | { 32 | return $this->__data->file_size ?? null; 33 | } 34 | } -------------------------------------------------------------------------------- /src/Types/Voice.php: -------------------------------------------------------------------------------- 1 | __data->file_id; 13 | } 14 | 15 | public function duration() : int 16 | { 17 | return $this->__data->duration; 18 | } 19 | 20 | public function mimeType() : ?string 21 | { 22 | return $this->__data->mime_type ?? null; 23 | } 24 | 25 | public function fileSize() : ?int 26 | { 27 | return $this->__data->file_size ?? null; 28 | } 29 | } --------------------------------------------------------------------------------