Commit 78af7d20 authored by Mahmoud Aglan's avatar Mahmoud Aglan

Fix WhatsApp webhook: fallback verify token from config when no DB record exists

Solves chicken-and-egg: Meta verifies webhook before credentials are saved.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 02ebb8ac
......@@ -18,7 +18,8 @@ public function verify(Request $request): Response
$challenge = $request->query('hub_challenge');
$channel = MessagingChannel::where('name', 'whatsapp')->where('is_active', true)->first();
$expectedToken = $channel?->credentials['webhook_verify_token'] ?? '';
$expectedToken = $channel?->credentials['webhook_verify_token']
?? config('services.whatsapp.webhook_verify_token', '');
if ($mode === 'subscribe' && !empty($expectedToken) && $token === $expectedToken) {
return response($challenge, 200)->header('Content-Type', 'text/plain');
......
......@@ -35,4 +35,8 @@
],
],
'whatsapp' => [
'webhook_verify_token' => env('WHATSAPP_WEBHOOK_VERIFY_TOKEN', 'elcaptain_whatsapp_verify_2024'),
],
];
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment