Skip to content
Open
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
6 changes: 5 additions & 1 deletion src/TelegramDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
23 changes: 23 additions & 0 deletions tests/Unit/TelegramDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down