fix: tolerate malformed telegram callbacks, constrain channel id
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BCrwHHnGCB5XH968Nxokqw
This commit is contained in:
@@ -67,21 +67,31 @@ class TelegramWebhookController extends Controller
|
||||
$this->telegram->touch($chatId);
|
||||
}
|
||||
|
||||
$callbackId = (string) ($callback['id'] ?? '');
|
||||
[$action, $token] = array_pad(explode(':', (string) ($callback['data'] ?? ''), 2), 2, '');
|
||||
$delivery = Delivery::where('action_token', $token)->with('event.user')->first();
|
||||
|
||||
if ($delivery === null || $delivery->event->isTerminal() || ! in_array($action, ['ack', 'done'], true)) {
|
||||
$this->telegram->answerCallback((string) $callback['id'], 'Уже неактуально');
|
||||
$this->answerCallback($callbackId, 'Уже неактуально');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($action === 'done') {
|
||||
$this->actions->done($delivery->event);
|
||||
$this->telegram->answerCallback((string) $callback['id'], 'Закрыто');
|
||||
$this->answerCallback($callbackId, 'Закрыто');
|
||||
} else {
|
||||
$this->actions->ack($delivery->event);
|
||||
$this->telegram->answerCallback((string) $callback['id'], 'Ок, напомню позже');
|
||||
$this->answerCallback($callbackId, 'Ок, напомню позже');
|
||||
}
|
||||
}
|
||||
|
||||
private function answerCallback(string $callbackId, string $text): void
|
||||
{
|
||||
if ($callbackId === '') {
|
||||
// Нет id — отвечать нечему (malformed payload), но не считаем это ошибкой.
|
||||
return;
|
||||
}
|
||||
$this->telegram->answerCallback($callbackId, $text);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user