public function method(string $method, array $arguments = []) : result\Result { $Client = $this->Client; $Response = $Client->request("POST", $method, ['multipart' => self::mkGuzzleMultipart($arguments)]); $Result = Parser::parseRaw($Response->getBody(), $method); if ($Result instanceof result\Error) { $this->lastException = $Result->mkException(); if ($this->throw) { throw $this->lastException; } } return $Result; }
public function __construct(array $json) { $this->JSON = $json; $this->msgID = $json['message_id']; $this->msgTime = $json['date']; $this->msgChat = new Chat($json['chat']); if (isset($json['from'])) { $this->msgFrom = new User($json['from']); } // Forwards. if (isset($json['forward_from'])) { $this->fwd = true; $this->fwdFrom = new User($json['forward_from']); $this->fwdDate = $json['forward_date']; if (isset($json['forward_from_chat'])) { $this->fwdChat = new Chat($json['forward_from_chat']); } } // Replies. if (isset($json['reply_to_message'])) { $this->msgReplyTo = new Message($json['reply_to_message']); } // Text messages. if (isset($json['text'])) { $this->type = 'text'; $this->msgText = $json['text']; $this->msgWords = explode(' ', $this->msgText); if (strpos($this->msgText, '/') === 0) { $this->msgIsCommand = true; $this->msgCommand = preg_replace('/^\\//', '', $this->msgWords[0]); } } // Audio. if (isset($json['audio'])) { $this->type = 'audio'; $this->msgAudio = new Audio($json['audio']); } // Files. (internally called documents for whatever reason ┐('~'; )┌) if (isset($json['document'])) { $this->type = 'document'; $this->msgFile = new Document($json['document']); } elseif (isset($json['photo'])) { $this->type = 'photo'; $this->msgPhoto = Parser::getPhotoSizeArray($json['photo']); if (isset($json['caption'])) { $this->msgCaption = $json['caption']; } } elseif (isset($json['sticker'])) { $this->type = 'sticker'; $this->msgSticker = new Sticker($json['sticker']); } elseif (isset($json['video'])) { $this->type = 'video'; $this->msgVideo = new Video($json['video']); if (isset($json['caption'])) { $this->msgCaption = $json['caption']; } } elseif (isset($json['voice'])) { $this->type = 'voice'; $this->msgVoice = new Voice($json['voice']); } elseif (isset($json['contact'])) { $this->type = 'contact'; $this->msgContact = new Contact($json['contact']); } elseif (isset($json['location'])) { $this->type = 'location'; $this->msgLocation = new Location($json['location']); } elseif (isset($json['new_chat_participant'])) { $this->type = 'chat_join'; $this->chatJoin = new User($json['new_chat_participant']); } elseif (isset($json['left_chat_participant'])) { $this->type = 'chat_left'; $this->chatLeft = new User($json['left_chat_participant']); } elseif (isset($json['new_chat_title'])) { $this->type = 'newChatTitle'; $this->chatTitle = $json['new_chat_title']; } elseif (isset($json['new_chat_photo'])) { $this->type = 'newChatPhoto'; $this->chatPhoto = Parser::getPhotoSizeArray($json['new_chat_photo']); } elseif (isset($json['delete_chat_photo'])) { $this->type = 'deleteChatPhoto'; $this->chatPhotoDel = true; } elseif (isset($json['group_chat_created'])) { $this->type = 'groupCreated'; } elseif (isset($json['channel_chat_created'])) { $this->type = 'chanCreated'; } elseif (isset($json['supergroup_chat_created'])) { $this->type = 'supergroup'; $this->oldGroup = $json['migrate_to_chat_id']; $this->newSupergroup = $json['migrate_from_chat_id']; } }