Deploy: 2026-06-24 13:42:28
This commit is contained in:
@@ -251,15 +251,32 @@ class OTPController extends BaseController
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send voice note
|
// 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') {
|
} else if ($type === 'image') {
|
||||||
// Generate OTP Image as Base64
|
// Generate OTP Image as Base64
|
||||||
$imageBase64 = $this->generateOtpImage($code);
|
$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 {
|
} else {
|
||||||
// Send text
|
// Send text
|
||||||
|
$customText = $body['message'] ?? null;
|
||||||
|
if ($customText) {
|
||||||
|
$textMsg = str_replace('{code}', $code, $customText);
|
||||||
|
} else {
|
||||||
$textMsg = "رمز التحقق الخاص بك لمتجر نابه هو: *{$code}* \n الرجاء عدم مشاركته مع أي شخص.";
|
$textMsg = "رمز التحقق الخاص بك لمتجر نابه هو: *{$code}* \n الرجاء عدم مشاركته مع أي شخص.";
|
||||||
ConversationFlowEngine::sendReply($session, $phone, $textMsg);
|
}
|
||||||
|
$success = ConversationFlowEngine::sendReply($session, $phone, $textMsg);
|
||||||
|
if (!$success) {
|
||||||
|
$response->status(500)->json(['error' => 'Failed to send text OTP via gateway.']);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Increment usage stats
|
// Increment usage stats
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ class ConversationFlowEngine
|
|||||||
?string $audioBase64 = null,
|
?string $audioBase64 = null,
|
||||||
?string $mimetype = null,
|
?string $mimetype = null,
|
||||||
?string $imageBase64 = null
|
?string $imageBase64 = null
|
||||||
): void {
|
): bool {
|
||||||
$gatewayUrl = rtrim(getenv('WHATSAPP_GATEWAY_URL') ?: 'http://localhost:3722', '/');
|
$gatewayUrl = rtrim(getenv('WHATSAPP_GATEWAY_URL') ?: 'http://localhost:3722', '/');
|
||||||
if (substr($gatewayUrl, -4) === '/api') {
|
if (substr($gatewayUrl, -4) === '/api') {
|
||||||
$sendUrl = $gatewayUrl . '/messages/send';
|
$sendUrl = $gatewayUrl . '/messages/send';
|
||||||
@@ -315,5 +315,7 @@ class ConversationFlowEngine
|
|||||||
'status' => $status,
|
'status' => $status,
|
||||||
'error_message' => $errorMsg
|
'error_message' => $errorMsg
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
return $status === 'sent';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user