Skip to content

Commit

Permalink
Merge pull request #354 from defstudio/fix-353
Browse files Browse the repository at this point in the history
[fix] reply to commands in webhook handler
  • Loading branch information
fabio-ivona authored Mar 7, 2023
2 parents 0ff9036 + 2bc8294 commit b834e74
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Handlers/WebhookHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,13 @@ protected function deleteKeyboard(): void

protected function reply(string $message, bool $showAlert = false): void
{
$this->bot->replyWebhook($this->callbackQueryId, $message, $showAlert)->send();
if (isset($this->callbackQueryId)) {
$this->bot->replyWebhook($this->callbackQueryId, $message, $showAlert)->send();

return;
}

$this->chat->message($message)->send();
}

public function chatid(): void
Expand Down
14 changes: 14 additions & 0 deletions tests/Regression/issue-353-ReplyToCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php


use DefStudio\Telegraph\Facades\Telegraph as Facade;
use DefStudio\Telegraph\Tests\Support\TestWebhookHandler;

it('can reply to a command', function () {
$bot = bot();
Facade::fake();

app(TestWebhookHandler::class)->handle(webhook_command('/reply_to_command'), $bot);

Facade::assertSent("foo");
});
5 changes: 5 additions & 0 deletions tests/Support/TestWebhookHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public function hello($parameter = null): void
$this->chat->html("Hello!!")->send();
}

public function reply_to_command(): void
{
$this->reply('foo');
}

private function private_action(): void
{
}
Expand Down

0 comments on commit b834e74

Please sign in to comment.