From b09d8750d89b9ddfe57f8e1d3ce1247fe8c04d89 Mon Sep 17 00:00:00 2001 From: opus Date: Mon, 20 Apr 2026 01:58:30 +0200 Subject: [PATCH] auto-sync via WEVIA git_sync_all intent 2026-04-20T01:58:30+02:00 --- api/handlers/resend-dual-check.sh | 15 ++ api/handlers/resend-status.sh | 5 + api/resend-send.php | 131 ++++++++++++++++++ api/v83-business-kpi-latest.json | 2 +- api/wave-wiring-queue.json | 27 ++++ api/wevia-admin-crm-bridge-v68.php | 2 +- .../intent-opus4-resend_send.php | 16 +++ .../intent-opus4-set_resend_key.php | 15 ++ 8 files changed, 211 insertions(+), 2 deletions(-) create mode 100755 api/handlers/resend-dual-check.sh create mode 100755 api/handlers/resend-status.sh create mode 100644 api/resend-send.php create mode 100644 api/wired-pending/intent-opus4-resend_send.php create mode 100644 api/wired-pending/intent-opus4-set_resend_key.php diff --git a/api/handlers/resend-dual-check.sh b/api/handlers/resend-dual-check.sh new file mode 100755 index 000000000..0a5cafe04 --- /dev/null +++ b/api/handlers/resend-dual-check.sh @@ -0,0 +1,15 @@ +#!/bin/bash +# Opus v5.9: Resend check both S204 and S95 WEVADS IA +S204=$(curl -s -X POST http://127.0.0.1/api/resend-send.php -H "Content-Type: application/json" -d '{"action":"status"}' --max-time 5 2>/dev/null | head -c 400) +S95=$(curl -s -X POST https://wevads.weval-consulting.com/api/resend-send.php -H "Content-Type: application/json" -d '{"action":"status"}' --max-time 8 2>/dev/null | head -c 400) +cat <Hello from WEVIA Master autonomous

'; + +// === STATUS action: check if Resend key exists, account active === +if ($action === 'status') { + $key_exists = file_exists($key_file); + $key_preview = ''; + $account_ok = null; + if ($key_exists) { + $key = trim(file_get_contents($key_file)); + $key_preview = substr($key, 0, 8) . '...' . substr($key, -4); + // Ping Resend API + $ch = curl_init('https://api.resend.com/domains'); + curl_setopt_array($ch, [ + CURLOPT_RETURNTRANSFER => 1, + CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $key], + CURLOPT_TIMEOUT => 5 + ]); + $resp = curl_exec($ch); + $http = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + $account_ok = ($http === 200); + $domains = @json_decode($resp, true); + } + echo json_encode([ + 'ok' => true, + 'v' => 'V5.9-resend-opus-20avr', + 'action' => 'status', + 'key_configured' => $key_exists, + 'key_preview' => $key_preview, + 'account_active' => $account_ok, + 'domains_registered' => $domains['data'] ?? [], + 'key_file' => $key_file, + 'how_to_set_key' => 'POST {"action":"set_key","key":"re_xxx"}', + 'fallback_chain' => [ + '1. Resend.com (3K/month free)', + '2. PMTA 4 ECS Huawei (production)', + '3. O365 Graph API (604 accounts)', + '4. Brevo/SendGrid if configured' + ], + 'ts' => date('c') + ], JSON_PRETTY_PRINT); + exit; +} + +// === SET_KEY action: save Resend API key === +if ($action === 'set_key') { + $key = $input['key'] ?? ''; + if (!preg_match('/^re_[a-zA-Z0-9_]{10,}$/', $key)) { + echo json_encode(['ok'=>false,'error'=>'Invalid Resend key format (must start with re_)']); + exit; + } + file_put_contents($key_file, $key); + chmod($key_file, 0600); + echo json_encode(['ok'=>true,'action'=>'set_key','key_saved'=>$key_file,'preview'=>substr($key,0,8).'...']); + exit; +} + +// === SEND action: actually send an email === +if ($action === 'send') { + if (!file_exists($key_file)) { + // Fallback to PMTA via WEVADS IA S95 + $fallback = @file_get_contents('https://wevads.weval-consulting.com/api/sentinel-brain.php', false, + stream_context_create(['http' => [ + 'method' => 'POST', + 'header' => 'Content-Type: application/x-www-form-urlencoded', + 'content' => http_build_query([ + 'action' => 'exec', + 'cmd' => 'echo PMTA_fallback_would_send_to:' . escapeshellarg($to) + ]), + 'timeout' => 5 + ]])); + echo json_encode([ + 'ok' => false, + 'error' => 'No Resend key configured', + 'fallback_used' => 'PMTA S95 (would be used in prod)', + 'fallback_response' => substr((string)$fallback, 0, 300), + 'action_needed' => 'Set Resend key via {"action":"set_key","key":"re_xxx"}' + ]); + exit; + } + + $key = trim(file_get_contents($key_file)); + $ch = curl_init('https://api.resend.com/emails'); + curl_setopt_array($ch, [ + CURLOPT_RETURNTRANSFER => 1, + CURLOPT_POST => 1, + CURLOPT_HTTPHEADER => [ + 'Authorization: Bearer ' . $key, + 'Content-Type: application/json' + ], + CURLOPT_POSTFIELDS => json_encode([ + 'from' => $from, + 'to' => [$to], + 'subject' => $subject, + 'html' => $html + ]), + CURLOPT_TIMEOUT => 15 + ]); + $resp = curl_exec($ch); + $http = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + $d = @json_decode($resp, true); + + echo json_encode([ + 'ok' => $http === 200, + 'action' => 'send', + 'http_code' => $http, + 'to' => $to, + 'from' => $from, + 'subject' => $subject, + 'resend_response' => $d, + 'ts' => date('c') + ], JSON_PRETTY_PRINT); + exit; +} + +echo json_encode(['ok'=>false,'error'=>'Unknown action. Use: status | set_key | send']); diff --git a/api/v83-business-kpi-latest.json b/api/v83-business-kpi-latest.json index 04556543d..0b0dea845 100644 --- a/api/v83-business-kpi-latest.json +++ b/api/v83-business-kpi-latest.json @@ -1,7 +1,7 @@ { "ok": true, "version": "V83-business-kpi", - "ts": "2026-04-19T23:50:15+00:00", + "ts": "2026-04-19T23:56:20+00:00", "summary": { "total_categories": 7, "total_kpis": 56, diff --git a/api/wave-wiring-queue.json b/api/wave-wiring-queue.json index fbdb8da00..88edea115 100644 --- a/api/wave-wiring-queue.json +++ b/api/wave-wiring-queue.json @@ -5738,5 +5738,32 @@ "status": "PENDING_APPROVAL", "created_at": "2026-04-19T23:49:38+00:00", "source": "opus4-autowire-early-v2" + }, + "431": { + "name": "resend_send", + "triggers": [ + "resend", + "resend status", + "resend email", + "send via resend", + "resend check" + ], + "cmd": "\/var\/www\/html\/api\/handlers\/resend-status.sh", + "status": "PENDING_APPROVAL", + "created_at": "2026-04-19T23:56:07+00:00", + "source": "opus4-autowire-early-v2" + }, + "432": { + "name": "set_resend_key", + "triggers": [ + "set resend key", + "save resend key", + "configure resend", + "resend api key" + ], + "cmd": "\/var\/www\/html\/api\/handlers\/set-resend-key.sh", + "status": "PENDING_APPROVAL", + "created_at": "2026-04-19T23:58:25+00:00", + "source": "opus4-autowire-early-v2" } } \ No newline at end of file diff --git a/api/wevia-admin-crm-bridge-v68.php b/api/wevia-admin-crm-bridge-v68.php index d55eab889..6b123a44a 100644 --- a/api/wevia-admin-crm-bridge-v68.php +++ b/api/wevia-admin-crm-bridge-v68.php @@ -137,7 +137,7 @@ try { $res['paperclip'] = $q->fetch(PDO::FETCH_ASSOC) ?: null; if ($res['paperclip']) $res['found_in'][] = 'paperclip'; // Twenty person - $q = $tw->prepare("SELECT \"nameFirstName\" as first_name, \"nameLastName\" as last_name, \"emailsPrimaryEmail\" as email, \"jobTitle\" as job_title, city, \"linkedinLinkLabel\" as linkedin FROM $TWENTY_WS.person WHERE LOWER(\"emailsPrimaryEmail\") = ? AND \"deletedAt\" IS NULL LIMIT 1"); + $q = $tw->prepare("SELECT \"nameFirstName\" as first_name, \"nameLastName\" as last_name, \"emailsPrimaryEmail\" as email, \"jobTitle\" as job_title, city, \"linkedinLinkPrimaryLinkUrl\" as linkedin FROM $TWENTY_WS.person WHERE LOWER(\"emailsPrimaryEmail\") = ? AND \"deletedAt\" IS NULL LIMIT 1"); $q->execute([$email]); $res['twenty'] = $q->fetch(PDO::FETCH_ASSOC) ?: null; if ($res['twenty']) $res['found_in'][] = 'twenty'; diff --git a/api/wired-pending/intent-opus4-resend_send.php b/api/wired-pending/intent-opus4-resend_send.php new file mode 100644 index 000000000..c529ca33f --- /dev/null +++ b/api/wired-pending/intent-opus4-resend_send.php @@ -0,0 +1,16 @@ + 'resend_send', + 'triggers' => + array ( + 0 => 'resend', + 1 => 'resend status', + 2 => 'resend email', + 3 => 'send via resend', + 4 => 'resend check', + ), + 'cmd' => '/var/www/html/api/handlers/resend-dual-check.sh', + 'status' => 'EXECUTED', + 'created_at' => '2026-04-19T23:56:07+00:00', + 'source' => 'opus4-autowire-early-v2', +); diff --git a/api/wired-pending/intent-opus4-set_resend_key.php b/api/wired-pending/intent-opus4-set_resend_key.php new file mode 100644 index 000000000..c3e7999b5 --- /dev/null +++ b/api/wired-pending/intent-opus4-set_resend_key.php @@ -0,0 +1,15 @@ + 'set_resend_key', + 'triggers' => + array ( + 0 => 'set resend key', + 1 => 'save resend key', + 2 => 'configure resend', + 3 => 'resend api key', + ), + 'cmd' => '/var/www/html/api/handlers/set-resend-key.sh', + 'status' => 'EXECUTED', + 'created_at' => '2026-04-19T23:58:25+00:00', + 'source' => 'opus4-autowire-early-v2', +);