Added method \TgBotLib\Bot::answerWebAppQuery
to answer a callback query sent from a web app, which returns the newly added \TgBotLib\Objects\Telegram\SentWebAppMessage
object on success.
https://git.n64.cc/nosial/libs/tgbot/-/issues/3
This commit is contained in:
parent
581fa42715
commit
3d6cc15894
3 changed files with 90 additions and 0 deletions
|
@ -32,6 +32,7 @@ input objects for methods that require input objects.
|
||||||
* Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultContact`, see [InlineQueryResultContact](https://core.telegram.org/bots/api#inlinequeryresultcontact) for more information.
|
* Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultContact`, see [InlineQueryResultContact](https://core.telegram.org/bots/api#inlinequeryresultcontact) for more information.
|
||||||
* Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultGame`, see [InlineQueryResultGame](https://core.telegram.org/bots/api#inlinequeryresultgame) for more information.
|
* Added object `\TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultGame`, see [InlineQueryResultGame](https://core.telegram.org/bots/api#inlinequeryresultgame) for more information.
|
||||||
* Added class `\TgBotLib\Objects\Telegram\InlineQueryResult` which is the base class for all inline query results, additionally added `\TgBotLib\Abstracts\InlineQueryResultType` to represent the type of inline query result object.
|
* Added class `\TgBotLib\Objects\Telegram\InlineQueryResult` which is the base class for all inline query results, additionally added `\TgBotLib\Abstracts\InlineQueryResultType` to represent the type of inline query result object.
|
||||||
|
* Added method `\TgBotLib\Bot::answerWebAppQuery` to answer a callback query sent from a web app, which returns the newly added `\TgBotLib\Objects\Telegram\SentWebAppMessage` object on success.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
* Refactored InputMessageContent types to its own namespace so InputMessageContent can always return the correct InputMessageContent object type when calling `fromArray()`
|
* Refactored InputMessageContent types to its own namespace so InputMessageContent can always return the correct InputMessageContent object type when calling `fromArray()`
|
||||||
|
|
|
@ -24,9 +24,22 @@
|
||||||
use TgBotLib\Objects\Telegram\ChatMember;
|
use TgBotLib\Objects\Telegram\ChatMember;
|
||||||
use TgBotLib\Objects\Telegram\File;
|
use TgBotLib\Objects\Telegram\File;
|
||||||
use TgBotLib\Objects\Telegram\ForumTopic;
|
use TgBotLib\Objects\Telegram\ForumTopic;
|
||||||
|
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultArticle;
|
||||||
|
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultAudio;
|
||||||
|
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultContact;
|
||||||
|
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultDocument;
|
||||||
|
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultGame;
|
||||||
|
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultGif;
|
||||||
|
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultLocation;
|
||||||
|
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultMpeg4Gif;
|
||||||
|
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultPhoto;
|
||||||
|
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultVenue;
|
||||||
|
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultVideo;
|
||||||
|
use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultVoice;
|
||||||
use TgBotLib\Objects\Telegram\MenuButton;
|
use TgBotLib\Objects\Telegram\MenuButton;
|
||||||
use TgBotLib\Objects\Telegram\Message;
|
use TgBotLib\Objects\Telegram\Message;
|
||||||
use TgBotLib\Objects\Telegram\Poll;
|
use TgBotLib\Objects\Telegram\Poll;
|
||||||
|
use TgBotLib\Objects\Telegram\SentWebAppMessage;
|
||||||
use TgBotLib\Objects\Telegram\Sticker;
|
use TgBotLib\Objects\Telegram\Sticker;
|
||||||
use TgBotLib\Objects\Telegram\Update;
|
use TgBotLib\Objects\Telegram\Update;
|
||||||
use TgBotLib\Objects\Telegram\User;
|
use TgBotLib\Objects\Telegram\User;
|
||||||
|
@ -2735,4 +2748,29 @@
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use this method to set the result of an interaction with a Web App and send a corresponding message on behalf
|
||||||
|
* of the user to the chat from which the query originated. On success, a SentWebAppMessage object is returned.
|
||||||
|
*
|
||||||
|
* @param string $web_app_query_id Unique identifier for the query to be answered
|
||||||
|
* @param InlineQueryResultArticle|InlineQueryResultAudio|InlineQueryResultContact|InlineQueryResultDocument|InlineQueryResultGame|InlineQueryResultGif|InlineQueryResultLocation|InlineQueryResultMpeg4Gif|InlineQueryResultPhoto|InlineQueryResultVenue|InlineQueryResultVideo|InlineQueryResultVoice $result This object represents one result of an inline query.
|
||||||
|
* @return SentWebAppMessage
|
||||||
|
* @throws TelegramException
|
||||||
|
* @link https://core.telegram.org/bots/api#answerwebappquery
|
||||||
|
* @noinspection PhpUnused
|
||||||
|
* @see https://core.telegram.org/bots/webapps
|
||||||
|
*/
|
||||||
|
public function answerWebAppQuery(
|
||||||
|
string $web_app_query_id,
|
||||||
|
InlineQueryResultArticle|InlineQueryResultAudio|InlineQueryResultContact|InlineQueryResultDocument|
|
||||||
|
InlineQueryResultGame|InlineQueryResultGif|InlineQueryResultLocation|InlineQueryResultMpeg4Gif|
|
||||||
|
InlineQueryResultPhoto|InlineQueryResultVenue|InlineQueryResultVideo|InlineQueryResultVoice $result
|
||||||
|
): SentWebAppMessage
|
||||||
|
{
|
||||||
|
return SentWebAppMessage::fromArray($this->sendRequest('answerWebAppQuery', [
|
||||||
|
'web_app_query_id' => $web_app_query_id,
|
||||||
|
'result' => $result->toArray()
|
||||||
|
]));
|
||||||
|
}
|
||||||
}
|
}
|
51
src/TgBotLib/Objects/Telegram/SentWebAppMessage.php
Normal file
51
src/TgBotLib/Objects/Telegram/SentWebAppMessage.php
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/** @noinspection PhpUnused */
|
||||||
|
/** @noinspection PhpMissingFieldTypeInspection */
|
||||||
|
|
||||||
|
namespace TgBotLib\Objects\Telegram;
|
||||||
|
|
||||||
|
use TgBotLib\Interfaces\ObjectTypeInterface;
|
||||||
|
|
||||||
|
class SentWebAppMessage implements ObjectTypeInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
private $inline_message_id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
public function getInlineMessageId(): ?string
|
||||||
|
{
|
||||||
|
return $this->inline_message_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array representation of the object
|
||||||
|
*
|
||||||
|
* @return null[]|string[]
|
||||||
|
*/
|
||||||
|
public function toArray(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'inline_message_id' => $this->inline_message_id,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs object from an array representation
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
* @return SentWebAppMessage
|
||||||
|
*/
|
||||||
|
public static function fromArray(array $data): SentWebAppMessage
|
||||||
|
{
|
||||||
|
$object = new self();
|
||||||
|
|
||||||
|
$object->inline_message_id = $data['inline_message_id'] ?? null;
|
||||||
|
|
||||||
|
return $object;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue