From cd2d070a1a20b7a496e930bd6cbb93b58d417f07 Mon Sep 17 00:00:00 2001 From: netkas Date: Mon, 7 Oct 2024 12:21:16 -0400 Subject: [PATCH] Added ReplyParameters --- src/TgBotLib/Objects/ReplyParameters.php | 138 +++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 src/TgBotLib/Objects/ReplyParameters.php diff --git a/src/TgBotLib/Objects/ReplyParameters.php b/src/TgBotLib/Objects/ReplyParameters.php new file mode 100644 index 0000000..14ddd79 --- /dev/null +++ b/src/TgBotLib/Objects/ReplyParameters.php @@ -0,0 +1,138 @@ +message_id; + } + + /** + * Optional. If the message to be replied to is from a different chat, unique identifier for the chat or + * username of the channel (in the format @channelusername). Not supported for messages sent on behalf + * of a business account. + * + * @return int|string|null + */ + public function getChatId(): int|string|null + { + return $this->chat_id; + } + + /** + * Optional. Pass True if the message should be sent even if the specified message to be replied to is + * not found. Always False for replies in another chat or forum topic. Always True for messages sent on + * behalf of a business account. + * + * @return bool + */ + public function isAllowSendingWithoutReply(): bool + { + return $this->allow_sending_without_reply; + } + + /** + * Optional. Quoted part of the message to be replied to; 0-1024 characters after entities parsing. + * The quote must be an exact substring of the message to be replied to, including bold, italic, underline, + * strikethrough, spoiler, and custom_emoji entities. The message will fail to send if the quote isn't found + * in the original message. + * + * @return string|null + */ + public function getQuote(): ?string + { + return $this->quote; + } + + /** + * Optional. Mode for parsing entities in the quote. See formatting options for more details. + * + * @return ParseMode|null + */ + public function getQuoteParseMode(): ?ParseMode + { + return $this->quote_parse_mode; + } + + /** + * Optional. A list of special entities that appear in the quote. It can be specified + * instead of quote_parse_mode. + * + * @return MessageEntity[]|null + */ + public function getQuoteEntities(): ?array + { + return $this->quote_entities; + } + + /** + * Optional. Position of the quote in the original message in UTF-16 code units + * + * @return int|null + */ + public function getQuotePosition(): ?int + { + return $this->quote_position; + } + + /** + * @inheritDoc + */ + public function toArray(): ?array + { + return [ + 'message_id' => $this->message_id, + 'chat_id' => $this->chat_id, + 'allow_sending_without_reply' => $this->allow_sending_without_reply, + 'quote' => $this->quote, + 'quote_parse_mode' => $this->quote_parse_mode?->value, + 'quote_entities' => array_map(fn(MessageEntity $item) => $item->toArray(), $this->quote_entities), + 'quote_position' => $this->quote_position, + ]; + } + + /** + * @inheritDoc + */ + public static function fromArray(?array $data): ?ReplyParameters + { + if($data === null) + { + return null; + } + + $object = new self; + + $object->message_id = $data['message_id']; + $object->chat_id = $data['chat_id']; + $object->allow_sending_without_reply = $data['allow_sending_without_reply']; + $object->quote = $data['quote']; + $object->quote_parse_mode = isset($data['quote_parse_mode']) ? ParseMode::tryFrom($data['quote_parse_mode']) : null; + $object->quote_entities = array_map(fn(array $item) => MessageEntity::fromArray($item), $data['quote_entities']); + $object->quote_position = $data['quote_position']; + + return $object; + } + } \ No newline at end of file