mirror of
https://github.com/BushlanovDev/max-bot-api-client-php.git
synced 2026-08-23 22:36:49 +00:00
Added OpenAppButton factory method
This commit is contained in:
+2
-2
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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')),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user