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

Fix get chat parameters on callback query #1

Open
wants to merge 3 commits into
base: 1.0
Choose a base branch
from
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