Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Telegram Bot API 7.8 support #115

Merged
merged 3 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Telegram Bot API for PHP Change Log

## 0.4.1 under development

- New #115: Add `hasMainWebApp` field to `User` type.
- New #115: Add `businessConnectionId` parameter to `PinChatMessage` and `UnpinChatMessage` methods.

## 0.4.0 July 10, 2024

- New #103: Add `Update::getRaw()` method that returns raw data if type created by `Update::fromJson()` or
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

The package provides a simple and convenient way to interact with the Telegram Bot API.

✔️ Telegram Bot API 7.7 (July 7, 2024) is **full supported**.
✔️ Telegram Bot API 7.8 (July 31, 2024) is **full supported**.

## Requirements

Expand Down
2 changes: 2 additions & 0 deletions src/Method/PinChatMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function __construct(
private int|string $chatId,
private int $messageId,
private ?bool $disableNotification = null,
private ?string $businessConnectionId = null,
) {}

public function getHttpMethod(): HttpMethod
Expand All @@ -33,6 +34,7 @@ public function getData(): array
{
return array_filter(
[
'business_connection_id' => $this->businessConnectionId,
'chat_id' => $this->chatId,
'message_id' => $this->messageId,
'disable_notification' => $this->disableNotification,
Expand Down
2 changes: 2 additions & 0 deletions src/Method/UnpinChatMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
public function __construct(
private int|string $chatId,
private ?int $messageId = null,
private ?string $businessConnectionId = null,
) {}

public function getHttpMethod(): HttpMethod
Expand All @@ -32,6 +33,7 @@ public function getData(): array
{
return array_filter(
[
'business_connection_id' => $this->businessConnectionId,
'chat_id' => $this->chatId,
'message_id' => $this->messageId,
],
Expand Down
2 changes: 2 additions & 0 deletions src/Type/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function __construct(
public ?bool $canReadAllGroupMessages = null,
public ?bool $supportsInlineQueries = null,
public ?bool $canConnectToBusiness = null,
public ?bool $hasMainWebApp = null,
) {}

public function toRequestArray(): array
Expand All @@ -40,6 +41,7 @@ public function toRequestArray(): array
'can_read_all_group_messages' => $this->canReadAllGroupMessages,
'supports_inline_queries' => $this->supportsInlineQueries,
'can_connect_to_business' => $this->canConnectToBusiness,
'has_main_web_app' => $this->hasMainWebApp,
],
static fn(mixed $value): bool => $value !== null,
);
Expand Down
3 changes: 2 additions & 1 deletion tests/Method/PinChatMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ public function testBase(): void

public function testFull(): void
{
$method = new PinChatMessage(1, 2, true);
$method = new PinChatMessage(1, 2, true, 'bid');

$this->assertSame(HttpMethod::POST, $method->getHttpMethod());
$this->assertSame('pinChatMessage', $method->getApiMethod());
$this->assertSame(
[
'business_connection_id' => 'bid',
'chat_id' => 1,
'message_id' => 2,
'disable_notification' => true,
Expand Down
3 changes: 2 additions & 1 deletion tests/Method/UnpinChatMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ public function testBase(): void

public function testFull(): void
{
$method = new UnpinChatMessage(1, 2);
$method = new UnpinChatMessage(1, 2, 'bid');

$this->assertSame(HttpMethod::POST, $method->getHttpMethod());
$this->assertSame('unpinChatMessage', $method->getApiMethod());
$this->assertSame(
[
'business_connection_id' => 'bid',
'chat_id' => 1,
'message_id' => 2,
],
Expand Down
5 changes: 5 additions & 0 deletions tests/Type/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function testBase(): void
$this->assertNull($user->canReadAllGroupMessages);
$this->assertNull($user->supportsInlineQueries);
$this->assertNull($user->canConnectToBusiness);
$this->assertNull($user->hasMainWebApp);
}

public function testToRequestArray(): void
Expand All @@ -43,6 +44,7 @@ public function testToRequestArray(): void
true,
true,
true,
false,
);

$this->assertSame(
Expand All @@ -59,6 +61,7 @@ public function testToRequestArray(): void
'can_read_all_group_messages' => true,
'supports_inline_queries' => true,
'can_connect_to_business' => true,
'has_main_web_app' => false,
],
$user->toRequestArray(),
);
Expand All @@ -79,6 +82,7 @@ public function testFromTelegramResult(): void
'can_read_all_group_messages' => true,
'supports_inline_queries' => true,
'can_connect_to_business' => true,
'has_main_web_app' => false,
], null, User::class);

$this->assertInstanceOf(User::class, $user);
Expand All @@ -94,5 +98,6 @@ public function testFromTelegramResult(): void
$this->assertSame(true, $user->canReadAllGroupMessages);
$this->assertSame(true, $user->supportsInlineQueries);
$this->assertSame(true, $user->canConnectToBusiness);
$this->assertSame(false, $user->hasMainWebApp);
}
}
Loading