Changes
Specific Folder FTP Upload / ftp-deploy (push) Successful in 29s
Details
Specific Folder FTP Upload / ftp-deploy (push) Successful in 29s
Details
This commit is contained in:
parent
d7e11dfacc
commit
b75579f346
|
|
@ -95,6 +95,22 @@ class TgicsHelper
|
||||||
return strtolower(trim((string) $value)) === 'yes';
|
return strtolower(trim((string) $value)) === 'yes';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read validation flag from a contact object (supports attribute_ prefix).
|
||||||
|
*/
|
||||||
|
public static function contactHasWhatsappValidated($item): bool
|
||||||
|
{
|
||||||
|
if (!$item) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$direct = $item->tgics_whatsapp_validated ?? null;
|
||||||
|
if (self::isWhatsappValidatedFlag($direct)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
$prefixed = $item->attribute_tgics_whatsapp_validated ?? null;
|
||||||
|
return self::isWhatsappValidatedFlag($prefixed);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map contact_id => whether WhatsApp is validated for TGICS.
|
* Map contact_id => whether WhatsApp is validated for TGICS.
|
||||||
*
|
*
|
||||||
|
|
@ -122,11 +138,16 @@ class TgicsHelper
|
||||||
try {
|
try {
|
||||||
$resp = LambdaRequest::getrequest('contact', 'contact/get_one', ['id' => $id], $accessToken);
|
$resp = LambdaRequest::getrequest('contact', 'contact/get_one', ['id' => $id], $accessToken);
|
||||||
$item = $resp->data->item ?? null;
|
$item = $resp->data->item ?? null;
|
||||||
if ($item && self::isWhatsappValidatedFlag($item->tgics_whatsapp_validated ?? '')) {
|
$validated = self::contactHasWhatsappValidated($item);
|
||||||
$status[$id] = true;
|
$status[$id] = $validated;
|
||||||
}
|
Log::info('[TGICS_WA_STATUS] contact lookup', [
|
||||||
|
'contact_id' => $id,
|
||||||
|
'validated' => $validated,
|
||||||
|
'flag' => $item->tgics_whatsapp_validated ?? ($item->attribute_tgics_whatsapp_validated ?? null),
|
||||||
|
'api_status' => $resp->status ?? null,
|
||||||
|
]);
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
Log::warning('TGICS WhatsApp validation lookup failed for '.$id.': '.$e->getMessage());
|
Log::warning('[TGICS_WA_STATUS] lookup failed for '.$id.': '.$e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1705,6 +1705,43 @@ class FormController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Team3 doctor tagging (single submit): mark attribute = Yes on selected doctor(s)
|
||||||
|
$team3DrTagAttributes = [
|
||||||
|
'1793772514-e8e67206-8dba-471e-b08f-deece5d36d11' => 'levoswitch_drs',
|
||||||
|
'1793767249-069bf040-1469-4117-b364-e4851e1f4bdf' => 'toba_titans_drs',
|
||||||
|
];
|
||||||
|
if (isset($team3DrTagAttributes[$formdata->form_id])) {
|
||||||
|
$tagAttribute = $team3DrTagAttributes[$formdata->form_id];
|
||||||
|
$rawContactIds = $post['contact_id'] ?? [];
|
||||||
|
if (!is_array($rawContactIds)) {
|
||||||
|
$rawContactIds = [$rawContactIds];
|
||||||
|
}
|
||||||
|
$contactIds = [];
|
||||||
|
foreach ($rawContactIds as $contactId) {
|
||||||
|
$contactId = trim((string) $contactId);
|
||||||
|
if ($contactId !== '' && strcasecmp($contactId, 'others') !== 0) {
|
||||||
|
$contactIds[] = $contactId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$contactIds = array_values(array_unique($contactIds));
|
||||||
|
if ($contactIds !== [] && !empty($formdata->partition)) {
|
||||||
|
list($application, $domain) = explode('-', $formdata->partition);
|
||||||
|
$token = DB::table('users')->select('access_token')->where('domain', $domain)->where('permissions', 'like', '%contact_create%')->orderBy('updated_at', 'desc')->skip(0)->take(1)->get();
|
||||||
|
$userId = trim((string) ($post['user_id'] ?? ($formdata->user_id ?? '')));
|
||||||
|
if ($token->isNotEmpty() && $userId !== '') {
|
||||||
|
foreach ($contactIds as $contactId) {
|
||||||
|
LambdaRequest::postrequest('contact', 'contact/update', [
|
||||||
|
'domain' => $domain,
|
||||||
|
'application' => $application,
|
||||||
|
'user_id' => $userId,
|
||||||
|
'id' => $contactId,
|
||||||
|
$tagAttribute => 'Yes',
|
||||||
|
], $token[0]->access_token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if($formdata->form_id == '1757055046-ba0eff4e-0d4a-4e90-b190-c59f12ef6edd') {
|
if($formdata->form_id == '1757055046-ba0eff4e-0d4a-4e90-b190-c59f12ef6edd') {
|
||||||
// if(isset($post['cresar_bs_launched']) && $post['cresar_bs_launched'] == 'Yes' ) {
|
// if(isset($post['cresar_bs_launched']) && $post['cresar_bs_launched'] == 'Yes' ) {
|
||||||
list($application, $domain) = explode("-", $formdata->partition);
|
list($application, $domain) = explode("-", $formdata->partition);
|
||||||
|
|
@ -8104,6 +8141,40 @@ class FormController extends Controller
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Team3 doctor tagging: mark attribute = Yes on each selected doctor
|
||||||
|
$team3DrTagAttributes = [
|
||||||
|
'1793772514-e8e67206-8dba-471e-b08f-deece5d36d11' => 'levoswitch_drs',
|
||||||
|
'1793767249-069bf040-1469-4117-b364-e4851e1f4bdf' => 'toba_titans_drs',
|
||||||
|
];
|
||||||
|
if (isset($team3DrTagAttributes[$formdata->form_id])) {
|
||||||
|
$tagAttribute = $team3DrTagAttributes[$formdata->form_id];
|
||||||
|
$contactIds = [];
|
||||||
|
if (!empty($post['contact_id']) && is_array($post['contact_id'])) {
|
||||||
|
foreach ($post['contact_id'] as $contactId) {
|
||||||
|
$contactId = trim((string) $contactId);
|
||||||
|
if ($contactId !== '' && strcasecmp($contactId, 'others') !== 0) {
|
||||||
|
$contactIds[] = $contactId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$contactIds = array_values(array_unique($contactIds));
|
||||||
|
if ($contactIds !== [] && !empty($formdata->partition)) {
|
||||||
|
list($application, $domain) = explode('-', $formdata->partition);
|
||||||
|
$token = DB::table('users')->select('access_token')->where('domain', $domain)->where('permissions', 'like', '%contact_create%')->orderBy('updated_at', 'desc')->skip(0)->take(1)->get();
|
||||||
|
$userId = trim((string) ($post['user_id'] ?? ($formdata->user_id ?? '')));
|
||||||
|
if ($token->isNotEmpty() && $userId !== '') {
|
||||||
|
foreach ($contactIds as $contactId) {
|
||||||
|
LambdaRequest::postrequest('contact', 'contact/update', [
|
||||||
|
'domain' => $domain,
|
||||||
|
'application' => $application,
|
||||||
|
'user_id' => $userId,
|
||||||
|
'id' => $contactId,
|
||||||
|
$tagAttribute => 'Yes',
|
||||||
|
], $token[0]->access_token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(isset($formdata) && !empty($formdata) && $formdata->user_id != '') {
|
if(isset($formdata) && !empty($formdata) && $formdata->user_id != '') {
|
||||||
$post = $this->applyPobAmounts($post);
|
$post = $this->applyPobAmounts($post);
|
||||||
|
|
@ -13550,6 +13621,11 @@ class FormController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
$validated = \App\Helpers\TgicsHelper::isContactWhatsappValidated($contactId, $domain);
|
$validated = \App\Helpers\TgicsHelper::isContactWhatsappValidated($contactId, $domain);
|
||||||
|
\Log::info('[TGICS_WA_STATUS] poll', [
|
||||||
|
'contact_id' => $contactId,
|
||||||
|
'domain' => $domain,
|
||||||
|
'validated' => $validated,
|
||||||
|
]);
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'status' => 'success',
|
'status' => 'success',
|
||||||
|
|
|
||||||
|
|
@ -866,41 +866,50 @@
|
||||||
$('body').addClass('modal-open');
|
$('body').addClass('modal-open');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkTgicsWaStatus(contactId) {
|
||||||
|
return $.ajax({
|
||||||
|
type: 'GET',
|
||||||
|
url: '/form/tgicswhatsappstatus',
|
||||||
|
data: {
|
||||||
|
contact_id: contactId,
|
||||||
|
partition: 'rapport-lifemankind'
|
||||||
|
}
|
||||||
|
}).then(function(res) {
|
||||||
|
if (res && res.status === 'success' && res.data && res.data.validated) {
|
||||||
|
stopTgicsWaPoll();
|
||||||
|
$('#tgics-validate-wa-status').text('Validated!');
|
||||||
|
Swal.fire({
|
||||||
|
icon: 'success',
|
||||||
|
title: 'WhatsApp validated',
|
||||||
|
text: 'You can now send the survey link to this doctor.',
|
||||||
|
timer: 1800,
|
||||||
|
showConfirmButton: false
|
||||||
|
}).then(function() {
|
||||||
|
window.location.reload();
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}, function(err) {
|
||||||
|
console.warn('[TGICS_WA_STATUS] poll failed', err);
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function startTgicsWaPoll(contactId) {
|
function startTgicsWaPoll(contactId) {
|
||||||
stopTgicsWaPoll();
|
stopTgicsWaPoll();
|
||||||
tgicsWaPollStartedAt = Date.now();
|
tgicsWaPollStartedAt = Date.now();
|
||||||
$('#tgics-validate-wa-status').text('Waiting for validation…');
|
$('#tgics-validate-wa-status').text('Waiting for validation…');
|
||||||
|
// Immediate check, then every 2s
|
||||||
|
checkTgicsWaStatus(contactId);
|
||||||
tgicsWaPollTimer = setInterval(function() {
|
tgicsWaPollTimer = setInterval(function() {
|
||||||
if (Date.now() - tgicsWaPollStartedAt > 120000) {
|
if (Date.now() - tgicsWaPollStartedAt > 120000) {
|
||||||
stopTgicsWaPoll();
|
stopTgicsWaPoll();
|
||||||
$('#tgics-validate-wa-status').text('Still waiting. Close and try Validate again after the doctor sends the message.');
|
$('#tgics-validate-wa-status').text('Still waiting. Close and try Validate again after the doctor sends the message.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$.ajax({
|
checkTgicsWaStatus(contactId);
|
||||||
type: 'GET',
|
}, 2000);
|
||||||
url: '/form/tgicswhatsappstatus',
|
|
||||||
data: {
|
|
||||||
contact_id: contactId,
|
|
||||||
partition: 'rapport-lifemankind'
|
|
||||||
},
|
|
||||||
success: function(res) {
|
|
||||||
if (res && res.status === 'success' && res.data && res.data.validated) {
|
|
||||||
stopTgicsWaPoll();
|
|
||||||
$('#tgics-validate-wa-status').text('Validated!');
|
|
||||||
Swal.fire({
|
|
||||||
icon: 'success',
|
|
||||||
title: 'WhatsApp validated',
|
|
||||||
text: 'You can now send the survey link to this doctor.',
|
|
||||||
timer: 1800,
|
|
||||||
showConfirmButton: false
|
|
||||||
}).then(function() {
|
|
||||||
window.location.reload();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, 3000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$(document).on('click', '.tgics-validate-wa-btn', function(e) {
|
$(document).on('click', '.tgics-validate-wa-btn', function(e) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue