Added MessageLink & OpenAppButton

This commit is contained in:
Alex
2025-07-18 08:39:17 +03:00
parent 028d2591f8
commit b9c04bed33
7 changed files with 133 additions and 1 deletions
+5 -1
View File
@@ -13,6 +13,7 @@ use BushlanovDev\MaxMessengerBot\Models\AbstractModel;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Requests\AbstractAttachmentRequest;
use BushlanovDev\MaxMessengerBot\Models\BotInfo;
use BushlanovDev\MaxMessengerBot\Models\Message;
use BushlanovDev\MaxMessengerBot\Models\MessageLink;
use BushlanovDev\MaxMessengerBot\Models\Result;
use BushlanovDev\MaxMessengerBot\Models\Subscription;
use InvalidArgumentException;
@@ -159,7 +160,8 @@ class Api
* @param int|null $chatId Fill this if you send message to chat.
* @param string|null $text Message text.
* @param AbstractAttachmentRequest[]|null $attachments Message attachments.
* @param MessageFormat|null $format
* @param MessageFormat|null $format Message format.
* @param MessageLink|null $link Link to message.
* @param bool $notify If false, chat participants would not be notified.
* @param bool $disableLinkPreview If false, server will not generate media preview for links in text.
*
@@ -172,6 +174,7 @@ class Api
?string $text = null,
?array $attachments = null,
?MessageFormat $format = null,
?MessageLink $link = null,
bool $notify = true,
bool $disableLinkPreview = false,
): Message {
@@ -185,6 +188,7 @@ class Api
'text' => $text,
'format' => $format?->value,
'notify' => $notify,
'link' => $link,
'attachments' => $attachments !== null ? array_map(
fn(AbstractModel $attachment) => $attachment->toArray(),
$attachments,
+11
View File
@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Enums;
enum MessageLinkType: string
{
case Forward = 'forward';
case Reply = 'reply';
}
@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons;
use BushlanovDev\MaxMessengerBot\Enums\ButtonType;
/**
* Opens the bot's mini-application.
*/
final readonly class OpenAppButton extends AbstractButton
{
public ?string $webApp;
public ?int $contactId;
/**
* @param string $text Visible button text (1 to 128 characters).
* @param string|null $webApp The public name (username) of the bot or a link to it, whose mini-application should be launched.
* @param int|null $contactId The ID of the bot whose mini-app should be launched.
*/
public function __construct(string $text, ?string $webApp = null, ?int $contactId = null)
{
parent::__construct(ButtonType::OpenApp, $text);
$this->webApp = $webApp;
$this->contactId = $contactId;
}
}
+23
View File
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace BushlanovDev\MaxMessengerBot\Models;
use BushlanovDev\MaxMessengerBot\Enums\MessageLinkType;
/**
* Message link.
*/
final readonly class MessageLink extends AbstractModel
{
/**
* @param MessageLinkType $type Type of message link.
* @param string $mid Message identifier of original message.
*/
public function __construct(
public MessageLinkType $type,
public string $mid,
) {
}
}