From c4b08b5ab9f644fc3414d58e012888147aa96c6e Mon Sep 17 00:00:00 2001 From: netkas Date: Fri, 15 Nov 2024 15:22:31 -0500 Subject: [PATCH] Add AnswerInlineQuery method --- src/TgBotLib/Enums/Methods.php | 3 + src/TgBotLib/Methods/AnswerInlineQuery.php | 77 ++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 src/TgBotLib/Methods/AnswerInlineQuery.php diff --git a/src/TgBotLib/Enums/Methods.php b/src/TgBotLib/Enums/Methods.php index a4f69fa..69d7691 100644 --- a/src/TgBotLib/Enums/Methods.php +++ b/src/TgBotLib/Enums/Methods.php @@ -7,6 +7,7 @@ use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Methods\AddStickerToSet; use TgBotLib\Methods\AnswerCallbackQuery; + use TgBotLib\Methods\AnswerInlineQuery; use TgBotLib\Methods\ApproveChatJoinRequest; use TgBotLib\Methods\BanChatMember; use TgBotLib\Methods\BanChatSenderChat; @@ -233,6 +234,7 @@ case SET_STICKER_SET_THUMBNAIL = 'setStickerSetThumbnail'; case SET_CUSTOM_EMOJI_STICKER_SET_THUMBNAIL = 'setCustomEmojiStickerSetThumbnail'; case DELETE_STICKER_SET = 'deleteStickerSet'; + case ANSWER_INLINE_QUERY = 'answerInlineQuery'; /** * Executes a command on the provided bot with the given parameters. @@ -359,6 +361,7 @@ self::SET_STICKER_SET_THUMBNAIL => SetStickerSetThumbnail::execute($bot, $parameters), self::SET_CUSTOM_EMOJI_STICKER_SET_THUMBNAIL => SetCustomEmojiStickerSetThumbnail::execute($bot, $parameters), self::DELETE_STICKER_SET => DeleteStickerFromSet::execute($bot, $parameters), + self::ANSWER_INLINE_QUERY => AnswerInlineQuery::execute($bot, $parameters) }; } } diff --git a/src/TgBotLib/Methods/AnswerInlineQuery.php b/src/TgBotLib/Methods/AnswerInlineQuery.php new file mode 100644 index 0000000..eb5f3c1 --- /dev/null +++ b/src/TgBotLib/Methods/AnswerInlineQuery.php @@ -0,0 +1,77 @@ +toArray(); + continue; + } + + if(is_array($result)) + { + $result[] = $result; + } + } + + $parameters['results'] = json_encode($results); + } + + if(isset($parameters['button'])) + { + if($parameters['button'] instanceof ObjectTypeInterface) + { + $parameters['button'] = json_encode($parameters['button']->toArray()); + } + + if(is_array($parameters['button'])) + { + $parameters['button'] = json_encode($parameters['button']); + } + } + + return (bool)self::executeCurl(self::buildPost($bot, Methods::ANSWER_INLINE_QUERY->value, $parameters)); + } + + /** + * @inheritDoc + */ + public static function getRequiredParameters(): ?array + { + return [ + 'inline_query_id', + 'results' + ]; + } + + /** + * @inheritDoc + */ + public static function getOptionalParameters(): ?array + { + return [ + 'cache_time', + 'is_personal', + 'next_offset', + 'button' + ]; + } + } \ No newline at end of file