diff --git a/src/TelegramDriver.php b/src/TelegramDriver.php index 91ba454..a314d7d 100644 --- a/src/TelegramDriver.php +++ b/src/TelegramDriver.php @@ -62,7 +62,11 @@ public function verifyRequest(): void */ public function getChat(): Chat { - $chat = $this->request->getParameter('message.chat'); + if ($this->request->hasParameters('callback_query')) { + $chat = $this->request->getParameter('callback_query.message.chat'); + } else { + $chat = $this->request->getParameter('message.chat'); + } return new Chat( (string) $chat['id'], diff --git a/tests/Unit/TelegramDriverTest.php b/tests/Unit/TelegramDriverTest.php index 7aad86c..5b824eb 100644 --- a/tests/Unit/TelegramDriverTest.php +++ b/tests/Unit/TelegramDriverTest.php @@ -7,6 +7,7 @@ use Tests\TestCase; use GuzzleHttp\Client; use FondBot\Helpers\Str; +use FondBot\Drivers\Chat; use FondBot\Drivers\User; use FondBot\Http\Request; use FondBot\Templates\Location; @@ -85,6 +86,28 @@ public function test_getSender(): void $this->assertSame($response['username'], $sender->getUsername()); } + public function test_getChat(): void + { + $this->driver->fill( + $this->parameters, + new Request([ + 'message' => [ + 'chat' => $response = [ + 'id' => Str::random(), + 'title' => $this->faker()->name, + 'type' => Chat::TYPE_PRIVATE, + ], + ], + ], []) + ); + + $chat = $this->driver->getChat(); + $this->assertInstanceOf(Chat::class, $chat); + $this->assertSame($response['id'], $chat->getId()); + $this->assertSame($response['title'], $chat->getTitle()); + $this->assertSame($response['type'], $chat->getType()); + } + public function test_getMessage(): void { $this->driver->fill(