This commit is contained in:
Ravi Gulhane 2026-11-04 15:56:57 +05:30
parent b75579f346
commit 5cdea3cbaa
1 changed files with 38 additions and 3 deletions

View File

@ -113,6 +113,7 @@ class TgicsHelper
/**
* Map contact_id => whether WhatsApp is validated for TGICS.
* Prefers TGICS API (same RAPPORT token that wrote the flag); falls back to contact/get_one.
*
* @param array<int, string> $contactIds
* @return array<string, bool>
@ -127,20 +128,54 @@ class TgicsHelper
return [];
}
$status = array_fill_keys($ids, false);
$base = rtrim((string) env('TGICS_API_BASE', ''), '/');
if ($base !== '') {
try {
$response = Http::timeout(10)->acceptJson()->get($base.'/api/whatsapp/status', [
'contact_ids' => implode(',', $ids),
]);
if ($response->successful()) {
$json = $response->json();
$validatedRaw = $json['data']['validated'] ?? [];
foreach ($ids as $id) {
$status[$id] = !empty($validatedRaw[$id]);
}
Log::info('[TGICS_WA_STATUS] via TGICS API', [
'ids' => $ids,
'status' => $status,
'http' => $response->status(),
]);
return $status;
}
Log::warning('TGICS WhatsApp status request failed', [
'status' => $response->status(),
'body' => $response->body(),
]);
} catch (\Throwable $e) {
Log::warning('[TGICS_WA_STATUS] TGICS API error: '.$e->getMessage());
}
} else {
Log::warning('TGICS_API_BASE is not configured; falling back to Rapport contact/get_one');
}
// Fallback: Rapport via a lifemankind user token from local users table
$accessToken = self::resolveContactAccessToken($domain);
if ($accessToken === '') {
Log::warning('TGICS WhatsApp validation: no contact access token for domain '.$domain);
return array_fill_keys($ids, false);
return $status;
}
$status = array_fill_keys($ids, false);
foreach ($ids as $id) {
try {
$resp = LambdaRequest::getrequest('contact', 'contact/get_one', ['id' => $id], $accessToken);
$item = $resp->data->item ?? null;
$validated = self::contactHasWhatsappValidated($item);
$status[$id] = $validated;
Log::info('[TGICS_WA_STATUS] contact lookup', [
Log::info('[TGICS_WA_STATUS] contact lookup fallback', [
'contact_id' => $id,
'validated' => $validated,
'flag' => $item->tgics_whatsapp_validated ?? ($item->attribute_tgics_whatsapp_validated ?? null),