Added OpenAppButton factory method

This commit is contained in:
Alex
2025-08-06 20:52:37 +03:00
parent 62fbb6cf3b
commit 68da594f89
4 changed files with 27 additions and 7 deletions
+2 -2
View File
@@ -251,10 +251,10 @@ class Api
try {
$this->processUpdatesBatch($handlers, $timeout, $marker);
} catch (NetworkException $e) {
error_log("Network error: " . $e->getMessage());
error_log('Network error: ' . $e->getMessage());
sleep(5);
} catch (\Exception $e) {
error_log("An error occurred: " . $e->getMessage());
error_log('An error occurred: ' . $e->getMessage());
sleep(1);
}
}
+4 -2
View File
@@ -15,6 +15,7 @@ use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\AbstractInlin
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\CallbackButton;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\ChatButton;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\LinkButton;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\OpenAppButton;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\RequestContactButton;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\RequestGeoLocationButton;
use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\AbstractReplyButton;
@@ -224,7 +225,7 @@ class ModelFactory
AttachmentType::InlineKeyboard => InlineKeyboardAttachment::fromArray($data),
AttachmentType::ReplyKeyboard => ReplyKeyboardAttachment::fromArray($data),
AttachmentType::Location => LocationAttachment::fromArray($data),
default => throw new LogicException("Unknown or unsupported attachment type: " . ($data['type'] ?? 'none')),
default => throw new LogicException('Unknown or unsupported attachment type: ' . ($data['type'] ?? 'none')),
};
}
@@ -265,7 +266,8 @@ class ModelFactory
InlineButtonType::RequestContact => RequestContactButton::fromArray($data),
InlineButtonType::RequestGeoLocation => RequestGeoLocationButton::fromArray($data),
InlineButtonType::Chat => ChatButton::fromArray($data),
default => throw new LogicException("Unknown or unsupported inline button type: " . ($data['type'] ?? 'none')),
InlineButtonType::OpenApp => OpenAppButton::fromArray($data),
default => throw new LogicException('Unknown or unsupported inline button type: ' . ($data['type'] ?? 'none')),
};
}
+2 -3
View File
@@ -9,8 +9,7 @@ final readonly class Image extends AbstractModel
/**
* @param string $url URL of image.
*/
public function __construct(
public string $url,
) {
public function __construct(public string $url)
{
}
}
@@ -29,4 +29,23 @@ final class OpenAppButtonTest extends TestCase
$this->assertSame($expectedArray, $resultArray);
}
#[Test]
public function fromArrayHydratesCorrectly(): void
{
$data = [
'type' => 'open_app',
'text' => 'Launch',
'web_app' => 'SomeApp',
'contact_id' => 456,
];
$button = OpenAppButton::fromArray($data);
$this->assertInstanceOf(OpenAppButton::class, $button);
$this->assertSame(InlineButtonType::OpenApp, $button->type);
$this->assertSame('Launch', $button->text);
$this->assertSame('SomeApp', $button->webApp);
$this->assertSame(456, $button->contactId);
}
}