Skip to content

Commit

Permalink
unknown callback query support
Browse files Browse the repository at this point in the history
  • Loading branch information
BeyCoder committed Feb 23, 2024
1 parent 6013466 commit d328684
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
11 changes: 10 additions & 1 deletion src/Concerns/HasBotsAndChats.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
use DefStudio\Telegraph\Models\TelegraphChat;
use DefStudio\Telegraph\ScopedPayloads\SetChatMenuButtonPayload;
use DefStudio\Telegraph\Telegraph;
use File;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\File;

/**
* @mixin Telegraph
Expand All @@ -30,6 +30,15 @@ trait HasBotsAndChats

protected TelegraphChat|string|null $chat;

public function toEndpoint(string $endpoint): Telegraph
{
$telegraph = clone $this;

$telegraph->endpoint = $endpoint;

return $telegraph;
}

public function bot(TelegraphBot|string $bot): Telegraph
{
$telegraph = clone $this;
Expand Down
9 changes: 5 additions & 4 deletions src/Handlers/WebhookHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,19 @@ private function handleCallbackQuery(): void
$action = $this->callbackQuery?->data()->get('action') ?? '';

if (!$this->canHandle($action)) {
$this->handleUnknownCallbackQuery($action);
$this->handleUnknownCallbackQuery(new Stringable($action));

return;
}

$this->$action();
}

protected function handleUnknownCallbackQuery(string $action): void
protected function handleUnknownCallbackQuery(Stringable $text): void
{
report(TelegramWebhookException::invalidAction($action));
$this->reply(__('telegraph::errors.invalid_action'));
if ($this->message?->chat()?->type() === Chat::TYPE_PRIVATE) {
$this->chat->html(__('telegraph::errors.invalid_action'))->send();
}
}

private function handleCommand(Stringable $text): void
Expand Down

0 comments on commit d328684

Please sign in to comment.