Merge pull request #24 from imperiumbee/master

Added payload param to openAppButton
This commit is contained in:
Alex
2026-03-07 09:25:53 +03:00
committed by GitHub
2 changed files with 8 additions and 2 deletions
@@ -13,17 +13,20 @@ final readonly class OpenAppButton extends AbstractInlineButton
{
public ?string $webApp;
public ?int $contactId;
public ?string $payload;
/**
* @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.
* @param string|null $payload Init param which would be passed in mini-application initData (1 to 512 characters, allowed A-Z, a-z, 0-9, _(underscore) , - (minus) ).
*/
public function __construct(string $text, ?string $webApp = null, ?int $contactId = null)
public function __construct(string $text, ?string $webApp = null, ?int $contactId = null, ?string $payload = null)
{
parent::__construct(InlineButtonType::OpenApp, $text);
$this->webApp = $webApp;
$this->contactId = $contactId;
$this->payload = $payload;
}
}
@@ -16,11 +16,12 @@ final class OpenAppButtonTest extends TestCase
#[Test]
public function toArraySerializesCorrectly(): void
{
$button = new OpenAppButton('Test Button', 'MyWebApp', 123);
$button = new OpenAppButton('Test Button', 'MyWebApp', 123, 'somePayload');
$expectedArray = [
'web_app' => 'MyWebApp',
'contact_id' => 123,
'payload' => 'somePayload',
'type' => InlineButtonType::OpenApp->value,
'text' => 'Test Button',
];
@@ -38,6 +39,7 @@ final class OpenAppButtonTest extends TestCase
'text' => 'Launch',
'web_app' => 'SomeApp',
'contact_id' => 456,
'payload' => 'somePayload'
];
$button = OpenAppButton::fromArray($data);
@@ -47,5 +49,6 @@ final class OpenAppButtonTest extends TestCase
$this->assertSame('Launch', $button->text);
$this->assertSame('SomeApp', $button->webApp);
$this->assertSame(456, $button->contactId);
$this->assertSame('somePayload', $button->payload);
}
}