diff --git a/CHANGELOG.md b/CHANGELOG.md index 98c076c..695d4c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ input objects for methods that require input objects. * Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultDocument`, see [InlineQueryResultDocument](https://core.telegram.org/bots/api#inlinequeryresultdocument) for more information. * Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultLocation`, see [InlineQueryResultLocation](https://core.telegram.org/bots/api#inlinequeryresultlocation) for more information. * Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultVenue`, see [InlineQueryResultVenue](https://core.telegram.org/bots/api#inlinequeryresultvenue) for more information. + * Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultContact`, see [InlineQueryResultContact](https://core.telegram.org/bots/api#inlinequeryresultcontact) for more information. ### Changed * Refactored InputMessageContent types to its own namespace so InputMessageContent can always return the correct InputMessageContent object type when calling `fromArray()` diff --git a/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultContact.php b/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultContact.php new file mode 100644 index 0000000..51f066a --- /dev/null +++ b/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultContact.php @@ -0,0 +1,236 @@ +type = 'contact'; + } + + /** + * Type of the result, must be contact + * + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * Unique identifier for this result, 1-64 Bytes + * + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * Contact's phone number + * + * @return string + */ + public function getPhoneNumber(): string + { + return $this->phone_number; + } + + /** + * Contact's first name + * + * @return string + */ + public function getFirstName(): string + { + return $this->first_name; + } + + /** + * Optional. Contact's last name + * + * @return string|null + */ + public function getLastName(): ?string + { + return $this->last_name; + } + + /** + * Optional. Additional data about the contact in the form of a vCard, 0-2048 bytes + * + * @return string|null + */ + public function getVcard(): ?string + { + return $this->vcard; + } + + /** + * Optional. Inline keyboard attached to the message + * + * @return InlineKeyboardMarkup|null + */ + public function getReplyMarkup(): ?InlineKeyboardMarkup + { + return $this->reply_markup; + } + + /** + * Optional. Content of the message to be sent instead of the contact + * + * @return InputContactMessageContent|InputInvoiceMessageContent|InputLocationMessageContent|InputTextMessageContent|InputVenueMessageContent|null + */ + public function getInputMessageContent(): InputVenueMessageContent|InputTextMessageContent|InputContactMessageContent|InputLocationMessageContent|InputInvoiceMessageContent|null + { + return $this->input_message_content; + } + + /** + * Optional. Url of the thumbnail for the result + * + * @return string|null + */ + public function getThumbnailUrl(): ?string + { + return $this->thumbnail_url; + } + + /** + * Optional. Thumbnail width + * + * @return int|null + */ + public function getThumbnailWidth(): ?int + { + return $this->thumbnail_width; + } + + /** + * Optional. Thumbnail height + * + * @return int|null + */ + public function getThumbnailHeight(): ?int + { + return $this->thumbnail_height; + } + + /** + * Returns an array representation of the object + * + * @return array + */ + public function toArray(): array + { + return [ + 'type' => $this->type, + 'id' => $this->id, + 'phone_number' => $this->phone_number, + 'first_name' => $this->first_name, + 'last_name' => $this->last_name, + 'vcard' => $this->vcard, + 'reply_markup' => ($this->reply_markup instanceof InlineKeyboardMarkup) ? $this->reply_markup->toArray() : null, + 'input_message_content' => ($this->input_message_content instanceof ObjectTypeInterface) ? $this->input_message_content->toArray() : null, + 'thumbnail_url' => $this->thumbnail_url, + 'thumbnail_width' => $this->thumbnail_width, + 'thumbnail_height' => $this->thumbnail_height + ]; + } + + /** + * Constructs object from an array representation + * + * @param array $data + * @return ObjectTypeInterface + */ + public static function fromArray(array $data): ObjectTypeInterface + { + $object = new self(); + + $object->id = $data['id'] ?? null; + $object->phone_number = $data['phone_number'] ?? null; + $object->first_name = $data['first_name'] ?? null; + $object->last_name = $data['last_name'] ?? null; + $object->vcard = $data['vcard'] ?? null; + $object->reply_markup = isset($data['reply_markup']) ? InlineKeyboardMarkup::fromArray($data['reply_markup']) : null; + $object->input_message_content = isset($data['input_message_content']) ? InputMessageContent::fromArray($data['input_message_content']) : null; + $object->thumbnail_url = $data['thumbnail_url'] ?? null; + $object->thumbnail_width = $data['thumbnail_width'] ?? null; + $object->thumbnail_height = $data['thumbnail_height'] ?? null; + + return $object; + } + } \ No newline at end of file