Add AnswerInlineQuery method

This commit is contained in:
netkas 2024-11-15 15:22:31 -05:00
parent ee5f8fb06f
commit c4b08b5ab9
2 changed files with 80 additions and 0 deletions

View file

@ -7,6 +7,7 @@
use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Methods\AddStickerToSet; use TgBotLib\Methods\AddStickerToSet;
use TgBotLib\Methods\AnswerCallbackQuery; use TgBotLib\Methods\AnswerCallbackQuery;
use TgBotLib\Methods\AnswerInlineQuery;
use TgBotLib\Methods\ApproveChatJoinRequest; use TgBotLib\Methods\ApproveChatJoinRequest;
use TgBotLib\Methods\BanChatMember; use TgBotLib\Methods\BanChatMember;
use TgBotLib\Methods\BanChatSenderChat; use TgBotLib\Methods\BanChatSenderChat;
@ -233,6 +234,7 @@
case SET_STICKER_SET_THUMBNAIL = 'setStickerSetThumbnail'; case SET_STICKER_SET_THUMBNAIL = 'setStickerSetThumbnail';
case SET_CUSTOM_EMOJI_STICKER_SET_THUMBNAIL = 'setCustomEmojiStickerSetThumbnail'; case SET_CUSTOM_EMOJI_STICKER_SET_THUMBNAIL = 'setCustomEmojiStickerSetThumbnail';
case DELETE_STICKER_SET = 'deleteStickerSet'; case DELETE_STICKER_SET = 'deleteStickerSet';
case ANSWER_INLINE_QUERY = 'answerInlineQuery';
/** /**
* Executes a command on the provided bot with the given parameters. * 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_STICKER_SET_THUMBNAIL => SetStickerSetThumbnail::execute($bot, $parameters),
self::SET_CUSTOM_EMOJI_STICKER_SET_THUMBNAIL => SetCustomEmojiStickerSetThumbnail::execute($bot, $parameters), self::SET_CUSTOM_EMOJI_STICKER_SET_THUMBNAIL => SetCustomEmojiStickerSetThumbnail::execute($bot, $parameters),
self::DELETE_STICKER_SET => DeleteStickerFromSet::execute($bot, $parameters), self::DELETE_STICKER_SET => DeleteStickerFromSet::execute($bot, $parameters),
self::ANSWER_INLINE_QUERY => AnswerInlineQuery::execute($bot, $parameters)
}; };
} }
} }

View file

@ -0,0 +1,77 @@
<?php
namespace TgBotLib\Methods;
use TgBotLib\Abstracts\Method;
use TgBotLib\Bot;
use TgBotLib\Enums\Methods;
use TgBotLib\Interfaces\ObjectTypeInterface;
class AnswerInlineQuery extends Method
{
/**
* @inheritDoc
*/
public static function execute(Bot $bot, array $parameters = []): true
{
if(isset($parameters['results']))
{
$results = [];
foreach($parameters['results'] as $result)
{
if($result instanceof ObjectTypeInterface)
{
$result[] = $result->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'
];
}
}