mirror of
https://github.com/BushlanovDev/max-bot-api-client-php.git
synced 2026-08-17 12:33:17 +00:00
Added MessageLink & OpenAppButton
This commit is contained in:
+5
-1
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -289,6 +289,7 @@ final class ApiTest extends TestCase
|
||||
$text,
|
||||
null,
|
||||
$format,
|
||||
null,
|
||||
$notify,
|
||||
$disableLinkPreview,
|
||||
);
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models\Attachments\Buttons;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\ButtonType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\OpenAppButton;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(OpenAppButton::class)]
|
||||
class OpenAppButtonTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function toArraySerializesCorrectly(): void
|
||||
{
|
||||
$button = new OpenAppButton('Test Button', 'MyWebApp', 123);
|
||||
|
||||
$expectedArray = [
|
||||
'web_app' => 'MyWebApp',
|
||||
'contact_id' => 123,
|
||||
'type' => ButtonType::OpenApp->value,
|
||||
'text' => 'Test Button',
|
||||
];
|
||||
|
||||
$resultArray = $button->toArray();
|
||||
|
||||
$this->assertSame($expectedArray, $resultArray);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BushlanovDev\MaxMessengerBot\Tests\Models;
|
||||
|
||||
use BushlanovDev\MaxMessengerBot\Enums\MessageLinkType;
|
||||
use BushlanovDev\MaxMessengerBot\Models\MessageLink;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(MessageLink::class)]
|
||||
final class MessageLinkTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function toArraySerializesCorrectly(): void
|
||||
{
|
||||
$messageLink = new MessageLink(MessageLinkType::Forward, '123');
|
||||
|
||||
$expectedArray = [
|
||||
'type' => MessageLinkType::Forward->value,
|
||||
'mid' => '123',
|
||||
];
|
||||
|
||||
$resultArray = $messageLink->toArray();
|
||||
|
||||
$this->assertSame($expectedArray, $resultArray);
|
||||
$this->assertSame(MessageLinkType::Forward, $messageLink->type);
|
||||
$this->assertSame('123', $messageLink->mid);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user