diff --git a/src/TgBotLib/Objects/CallbackQuery.php b/src/TgBotLib/Objects/CallbackQuery.php new file mode 100644 index 0000000..d3b9490 --- /dev/null +++ b/src/TgBotLib/Objects/CallbackQuery.php @@ -0,0 +1,159 @@ +id; + } + + /** + * Sender + * + * @return User + */ + public function getFrom(): User + { + return $this->from; + } + + /** + * Optional. Message with the callback button that originated the query. Note that message content and message + * date will not be available if the message is too old + * + * @return Message|null + */ + public function getMessage(): ?Message + { + return $this->message; + } + + /** + * Optional. Identifier of the message sent via the bot in inline mode, that originated the query. + * + * @return string|null + */ + public function getInlineMessageId(): ?string + { + return $this->inline_message_id; + } + + /** + * Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent. + * Useful for high scores in games. + * + * @see https://core.telegram.org/bots/api#games + * @return string + */ + public function getChatInstance(): string + { + return $this->chat_instance; + } + + /** + * Optional. Data associated with the callback button. Be aware that the message originated the query + * can contain no callback buttons with this data. + * + * @return string|null + */ + public function getData(): ?string + { + return $this->data; + } + + /** + * Optional. Short name of a Game to be returned, serves as the unique identifier for the game + * + * @see https://core.telegram.org/bots/api#games + * @return string|null + */ + public function getGameShortName(): ?string + { + return $this->game_short_name; + } + + /** + * Returns an array representation of the object + * + * @return array + */ + public function toArray(): array + { + return [ + 'id' => $this->id, + 'from' => ($this->from instanceof User) ? $this->from->toArray() : null, + 'message' => ($this->message instanceof Message) ? $this->message->toArray() : null, + 'inline_message_id' => $this->inline_message_id, + 'chat_instance' => $this->chat_instance, + 'data' => $this->data, + 'game_short_name' => $this->game_short_name, + ]; + } + + /** + * Constructs CallbackQuery object from an array representation + * + * @param array $data + * @return ObjectTypeInterface + */ + public static function fromArray(array $data): ObjectTypeInterface + { + $object = new self(); + + $object->id = $data['id']; + $object->from = isset($data['from']) ? User::fromArray($data['from']) : null; + $object->message = isset($data['message']) ? Message::fromArray($data['message']) : null; + $object->inline_message_id = $data['inline_message_id'] ?? null; + $object->chat_instance = $data['chat_instance']; + $object->data = $data['data'] ?? null; + $object->game_short_name = $data['game_short_name'] ?? null; + + return $object; + } + } \ No newline at end of file