Add PreparedInlineMessage and SavePreparedInlineMessage

This commit is contained in:
netkas 2024-11-22 15:07:44 -05:00
parent 4ace03c02d
commit cef24db929
4 changed files with 231 additions and 0 deletions

View file

@ -72,6 +72,7 @@
use TgBotLib\Methods\ReplaceStickerInSet;
use TgBotLib\Methods\RestrictChatMember;
use TgBotLib\Methods\RevokeChatInviteLink;
use TgBotLib\Methods\SavePreparedInlineMessage;
use TgBotLib\Methods\SendAnimation;
use TgBotLib\Methods\SendAudio;
use TgBotLib\Methods\SendChatAction;
@ -237,6 +238,7 @@
case DELETE_STICKER_SET = 'deleteStickerSet';
case ANSWER_INLINE_QUERY = 'answerInlineQuery';
case ANSWER_WEB_APP_QUERY = 'answerWebAppQuery';
case SAVE_PREPARED_INLINE_MESSAGE = 'savePreparedInlineMessage';
/**
* Executes a command on the provided bot with the given parameters.
@ -365,6 +367,7 @@
self::DELETE_STICKER_SET => DeleteStickerFromSet::execute($bot, $parameters),
self::ANSWER_INLINE_QUERY => AnswerInlineQuery::execute($bot, $parameters),
self::ANSWER_WEB_APP_QUERY => AnswerWebAppQuery::execute($bot, $parameters),
self::SAVE_PREPARED_INLINE_MESSAGE => SavePreparedInlineMessage::execute($bot, $parameters),
};
}
}

View file

@ -0,0 +1,58 @@
<?php
namespace TgBotLib\Methods;
use TgBotLib\Abstracts\Method;
use TgBotLib\Bot;
use TgBotLib\Enums\Methods;
use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\PreparedInlineMessage;
class SavePreparedInlineMessage extends Method
{
/**
* @inheritDoc
*/
public static function execute(Bot $bot, array $parameters = []): PreparedInlineMessage
{
if(isset($parameters['result']))
{
if($parameters['result'] instanceof ObjectTypeInterface)
{
$parameters['result'] = json_encode($parameters['result']->toArray());
}
if(is_array($parameters['result']))
{
$parameters['result'] = json_encode($parameters['result']);
}
}
return PreparedInlineMessage::fromArray(self::executeCurl(self::buildPost($bot, Methods::SAVE_PREPARED_INLINE_MESSAGE->value, $parameters)));
}
/**
* @inheritDoc
*/
public static function getRequiredParameters(): ?array
{
return [
'user_id',
'result'
];
}
/**
* @inheritDoc
*/
public static function getOptionalParameters(): ?array
{
return [
'allow_user_chats',
'allow_bot_chats',
'allow_group_chats',
'allow_channel_chats'
];
}
}

View file

@ -0,0 +1,77 @@
<?php
namespace TgBotLib\Methods;
use TgBotLib\Abstracts\Method;
use TgBotLib\Bot;
use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\Message;
class SendInvoice extends Method
{
/**
* @inheritDoc
*/
public static function execute(Bot $bot, array $parameters = []): Message
{
if(isset($parameters['prices']))
{
$prices = [];
foreach($parameters['prices'] as $price)
{
if($price instanceof ObjectTypeInterface)
{
}
}
}
}
/**
* @inheritDoc
*/
public static function getRequiredParameters(): ?array
{
return [
'chat_id',
'title',
'description',
'payload',
'currency',
'prices'
];
}
/**
* @inheritDoc
*/
public static function getOptionalParameters(): ?array
{
return [
'message_thread_id',
'provider_token',
'max_tip_amount',
'suggested_tip_amounts',
'start_parameter',
'provider_data',
'photo_url',
'photo_size',
'photo_width',
'photo_height',
'need_name',
'need_phone_number',
'need_email',
'need_shipping_address',
'send_phone_number_to_provider',
'send_email_to_provider',
'is_flexible',
'disable_notification',
'protect_content',
'allow_paid_broadcast',
'message_effect_id',
'reply_parameters',
'reply_markup'
];
}
}

View file

@ -0,0 +1,93 @@
<?php
namespace TgBotLib\Objects;
use TgBotLib\Interfaces\ObjectTypeInterface;
class PreparedInlineMessage implements ObjectTypeInterface
{
private ?string $id;
private ?int $expirationDate;
/**
* Describes an inline message to be sent by a user of a Mini App.
*
* @param array $data
*/
public function __construct(?array $data)
{
if($data === null)
{
$this->id = null;
$this->expirationDate = null;
return;
}
$this->id = $data['id'];
$this->expirationDate = (int)$data['expiration_date'];
}
/**
* Unique identifier of the prepared message
*
* @return string
*/
public function getId(): string
{
return $this->id;
}
/**
* Sets the ID for the prepared inline message.
*
* @param string $id The ID to set.
* @return PreparedInlineMessage The current instance.
*/
public function setId(string $id): PreparedInlineMessage
{
$this->id = $id;
return $this;
}
/**
* Expiration date of the prepared message, in Unix time. Expired prepared messages can no longer be used
*
* @return int
*/
public function getExpirationDate(): int
{
return $this->expirationDate;
}
/**
* Sets the expiration date for the prepared inline message.
*
* @param int $expirationDate The expiration date timestamp.
* @return PreparedInlineMessage Returns the
*/
public function setExpirationDate(int $expirationDate): PreparedInlineMessage
{
$this->expirationDate = $expirationDate;
return $this;
}
/**
* @inheritDoc
*/
public function toArray(): ?array
{
return [
'id' => $this->id,
'expiration_date' => $this->expirationDate
];
}
/**
* @inheritDoc
*/
public static function fromArray(?array $data): PreparedInlineMessage
{
return new self($data);
}
}