From 7085065fbe211a620c5ed5ae83da7b6ea3e8b76c Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Wed, 24 Jun 2026 13:42:28 +0300 Subject: [PATCH] Deploy: 2026-06-24 13:42:28 --- backend/app/Controllers/OTPController.php | 25 ++++++++++++++++--- .../app/Core/Flows/ConversationFlowEngine.php | 4 ++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/backend/app/Controllers/OTPController.php b/backend/app/Controllers/OTPController.php index 0d2e938..43a8015 100644 --- a/backend/app/Controllers/OTPController.php +++ b/backend/app/Controllers/OTPController.php @@ -251,15 +251,32 @@ class OTPController extends BaseController } // Send voice note - ConversationFlowEngine::sendReply($session, $phone, '', null, $audioBase64, $mimeType); + $success = ConversationFlowEngine::sendReply($session, $phone, '', null, $audioBase64, $mimeType); + if (!$success) { + $response->status(500)->json(['error' => 'Failed to send voice OTP via gateway.']); + return; + } } else if ($type === 'image') { // Generate OTP Image as Base64 $imageBase64 = $this->generateOtpImage($code); - ConversationFlowEngine::sendReply($session, $phone, '', null, null, null, $imageBase64); + $success = ConversationFlowEngine::sendReply($session, $phone, '', null, null, null, $imageBase64); + if (!$success) { + $response->status(500)->json(['error' => 'Failed to send image OTP via gateway.']); + return; + } } else { // Send text - $textMsg = "رمز التحقق الخاص بك لمتجر نابه هو: *{$code}* \n الرجاء عدم مشاركته مع أي شخص."; - ConversationFlowEngine::sendReply($session, $phone, $textMsg); + $customText = $body['message'] ?? null; + if ($customText) { + $textMsg = str_replace('{code}', $code, $customText); + } else { + $textMsg = "رمز التحقق الخاص بك لمتجر نابه هو: *{$code}* \n الرجاء عدم مشاركته مع أي شخص."; + } + $success = ConversationFlowEngine::sendReply($session, $phone, $textMsg); + if (!$success) { + $response->status(500)->json(['error' => 'Failed to send text OTP via gateway.']); + return; + } } // Increment usage stats diff --git a/backend/app/Core/Flows/ConversationFlowEngine.php b/backend/app/Core/Flows/ConversationFlowEngine.php index 4e40108..32f7948 100644 --- a/backend/app/Core/Flows/ConversationFlowEngine.php +++ b/backend/app/Core/Flows/ConversationFlowEngine.php @@ -241,7 +241,7 @@ class ConversationFlowEngine ?string $audioBase64 = null, ?string $mimetype = null, ?string $imageBase64 = null - ): void { + ): bool { $gatewayUrl = rtrim(getenv('WHATSAPP_GATEWAY_URL') ?: 'http://localhost:3722', '/'); if (substr($gatewayUrl, -4) === '/api') { $sendUrl = $gatewayUrl . '/messages/send'; @@ -315,5 +315,7 @@ class ConversationFlowEngine 'status' => $status, 'error_message' => $errorMsg ]); + + return $status === 'sent'; } }