Add InlineQueryResultsButton class and integration

This commit is contained in:
netkas 2024-11-28 21:57:58 -05:00
parent 8aac6544a6
commit b8e5b59241
2 changed files with 139 additions and 0 deletions

View file

@ -37,7 +37,9 @@
use TgBotLib\Objects\ForceReply;
use TgBotLib\Objects\ForumTopic;
use TgBotLib\Objects\Gifts;
use TgBotLib\Objects\Inline\InlineQueryResult;
use TgBotLib\Objects\InlineKeyboardMarkup;
use TgBotLib\Objects\InlineQueryResultsButton;
use TgBotLib\Objects\InputMedia;
use TgBotLib\Objects\InputPollOption;
use TgBotLib\Objects\LinkPreviewOptions;
@ -172,6 +174,7 @@
* @method true deleteStickerSet(string $name) Use this method to delete a sticker set that was created by the bot. Returns True on success.
* @method Gifts getAvailableGifts() Returns the list of gifts that can be sent by the bot to users. Requires no parameters. Returns a Gifts object.
* @method true sendGift(int $user_id, string $gift_id, ?string $text=null, ?ParseMode $text_parse_mode=null, MessageEntity[]|null $text_entities=null) Sends a gift to the given user. The gift can't be converted to Telegram Stars by the user. Returns True on success.
* @method true answerInlineQuery(string $inline_query_id, InlineQueryResult[] $results, ?int $cache_time=null, ?bool $is_personal=null, ?string $next_offset=null, ?InlineQueryResultsButton $button=null) Use this method to send answers to an inline query. On success, True is returned.
* @throws TelegramException if the method execution fails.
*/
class Bot

View file

@ -0,0 +1,136 @@
<?php
namespace TgBotLib\Objects;
use TgBotLib\Interfaces\ObjectTypeInterface;
class InlineQueryResultsButton implements ObjectTypeInterface
{
private ?string $text;
private ?WebAppInfo $webApp;
private ?string $startParameter;
/**
* This object represents a button to be shown above inline query results. You must use exactly one of the optional fields.
*
* @param array|null $data
*/
public function __construct(?array $data=null)
{
if($data == null)
{
$this->text = null;
$this->webApp = null;
$this->startParameter = null;
return;
}
$this->text = $data['text'];
$this->webApp = WebAppInfo::fromArray($data['web_app']);
$this->startParameter = $data['start_parameter'];
}
/**
* Label text on the button
*
* @return string|null
*/
public function getText(): ?string
{
return $this->text;
}
/**
* Label text on the button
*
* @param string|null $text
* @return $this
*/
public function setText(?string $text): InlineQueryResultsButton
{
$this->text = $text;
return $this;
}
/**
* Optional. Description of the Web App that will be launched when the user presses the button.
* The Web App will be able to switch back to the inline mode using the method switchInlineQuery inside the Web App.
*
* @return WebAppInfo|null
*/
public function getWebApp(): ?WebAppInfo
{
return $this->webApp;
}
/**
* Optional. Description of the Web App that will be launched when the user presses the button.
* The Web App will be able to switch back to the inline mode using the method switchInlineQuery inside the Web App.
*
* @param WebAppInfo|null $webApp
* @return $this
*/
public function setWebApp(?WebAppInfo $webApp): InlineQueryResultsButton
{
$this->webApp = $webApp;
return $this;
}
/**
* Optional. Deep-linking parameter for the /start message sent to the bot when a user presses the button.
* 1-64 characters, only A-Z, a-z, 0-9, _ and - are allowed.
*
* Example: An inline bot that sends YouTube videos can ask the user to connect the bot to their YouTube account
* to adapt search results accordingly. To do this, it displays a 'Connect your YouTube account' button above
* the results, or even before showing any. The user presses the button, switches to a private chat with the bot
* and, in doing so, passes a start parameter that instructs the bot to return an OAuth link. Once done, the bot
* can offer a switch_inline button so that the user can easily return to the chat where they wanted to use the
* bot's inline capabilities.
*
* @return string|null
*/
public function getStartParameter(): ?string
{
return $this->startParameter;
}
/**
* Optional. Deep-linking parameter for the /start message sent to the bot when a user presses the button.
* 1-64 characters, only A-Z, a-z, 0-9, _ and - are allowed.
*
* Example: An inline bot that sends YouTube videos can ask the user to connect the bot to their YouTube account
* to adapt search results accordingly. To do this, it displays a 'Connect your YouTube account' button above
* the results, or even before showing any. The user presses the button, switches to a private chat with the bot
* and, in doing so, passes a start parameter that instructs the bot to return an OAuth link. Once done, the bot
* can offer a switch_inline button so that the user can easily return to the chat where they wanted to use the
* bot's inline capabilities.
*
* @param string|null $startParameter
* @return $this
*/
public function setStartParameter(?string $startParameter): InlineQueryResultsButton
{
$this->startParameter = $startParameter;
return $this;
}
/**
* @inheritDoc
*/
public function toArray(): ?array
{
return [
'text' => $this->text,
'web_app' => $this->webApp->toArray(),
'start_parameter' => $this->startParameter
];
}
/**
* @inheritDoc
*/
public static function fromArray(?array $data): ?InlineQueryResultsButton
{
return new self($data);
}
}