From 2fe807b7f9397bd95fb0da33fe63e773433bfbef Mon Sep 17 00:00:00 2001 From: Chaim Date: Sun, 5 Apr 2026 06:46:13 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20SmartAssistant=20v2.2.0=20=E2=80=94=20E?= =?UTF-8?q?spoCRM=20sends=20its=20own=20credentials=20to=20AI=20Gateway?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - EspoCRM sends url + apiKey in every request to the gateway - New Integration field: espocrmApiKey - Gateway no longer needs ESPOCRM_URL/ESPOCRM_API_KEY env vars Co-Authored-By: Claude Opus 4.6 (1M context) --- .../Resources/i18n/en_US/Integration.json | 1 + .../Resources/i18n/fa_IR/Integration.json | 1 + .../metadata/integrations/SmartAssistant.json | 4 ++++ .../Services/SmartAssistantService.php | 18 ++++++++++++++++++ manifest.json | 2 +- 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/files/custom/Espo/Modules/SmartAssistant/Resources/i18n/en_US/Integration.json b/files/custom/Espo/Modules/SmartAssistant/Resources/i18n/en_US/Integration.json index 82814f0..b8812d6 100644 --- a/files/custom/Espo/Modules/SmartAssistant/Resources/i18n/en_US/Integration.json +++ b/files/custom/Espo/Modules/SmartAssistant/Resources/i18n/en_US/Integration.json @@ -3,6 +3,7 @@ "fields": { "webhookUrl": "Webhook URL", "apiKey": "API Key", + "espocrmApiKey": "EspoCRM API Key", "maxMessagesPerHour": "Max Messages Per Hour", "inactivityWarningDays": "Inactivity Warning Days", "inactivityCriticalDays": "Inactivity Critical Days", diff --git a/files/custom/Espo/Modules/SmartAssistant/Resources/i18n/fa_IR/Integration.json b/files/custom/Espo/Modules/SmartAssistant/Resources/i18n/fa_IR/Integration.json index 5dc7191..ae405de 100644 --- a/files/custom/Espo/Modules/SmartAssistant/Resources/i18n/fa_IR/Integration.json +++ b/files/custom/Espo/Modules/SmartAssistant/Resources/i18n/fa_IR/Integration.json @@ -3,6 +3,7 @@ "fields": { "webhookUrl": "כתובת Webhook", "apiKey": "מפתח API", + "espocrmApiKey": "מפתח API של EspoCRM", "maxMessagesPerHour": "מקסימום הודעות לשעה", "inactivityWarningDays": "ימים לאזהרת חוסר פעילות", "inactivityCriticalDays": "ימים לאזהרה קריטית", diff --git a/files/custom/Espo/Modules/SmartAssistant/Resources/metadata/integrations/SmartAssistant.json b/files/custom/Espo/Modules/SmartAssistant/Resources/metadata/integrations/SmartAssistant.json index 2905a27..516b9e2 100644 --- a/files/custom/Espo/Modules/SmartAssistant/Resources/metadata/integrations/SmartAssistant.json +++ b/files/custom/Espo/Modules/SmartAssistant/Resources/metadata/integrations/SmartAssistant.json @@ -8,6 +8,10 @@ "type": "varchar", "maxLength": 255 }, + "espocrmApiKey": { + "type": "varchar", + "maxLength": 255 + }, "maxMessagesPerHour": { "type": "int", "default": 30 diff --git a/files/custom/Espo/Modules/SmartAssistant/Services/SmartAssistantService.php b/files/custom/Espo/Modules/SmartAssistant/Services/SmartAssistantService.php index 4348423..151d379 100644 --- a/files/custom/Espo/Modules/SmartAssistant/Services/SmartAssistantService.php +++ b/files/custom/Espo/Modules/SmartAssistant/Services/SmartAssistantService.php @@ -374,12 +374,18 @@ class SmartAssistantService throw new Error('SmartAssistant webhook URL is not configured. Go to Admin > Integrations > Smart Assistant.'); } + $siteUrl = $this->config->get('siteUrl') ?? ''; + $payload = json_encode([ 'message' => $message, 'context' => $context, 'conversationId' => $conversationId, 'conversationHistory' => $history, 'mode' => $mode, + 'espocrm' => [ + 'url' => rtrim($siteUrl, '/'), + 'apiKey' => $this->getEspocrmApiKey(), + ], ]); $headers = ['Content-Type: application/json', 'Accept: application/json']; @@ -459,6 +465,18 @@ class SmartAssistantService return null; } + private function getEspocrmApiKey(): ?string + { + $integration = $this->entityManager->getEntityById('Integration', 'SmartAssistant'); + if ($integration && $integration->get('enabled')) { + $data = $integration->get('data') ?? (object) []; + if (!empty($data->espocrmApiKey)) { + return $data->espocrmApiKey; + } + } + return null; + } + private function getThresholds(): array { $integration = $this->entityManager->getEntityById('Integration', 'SmartAssistant'); diff --git a/manifest.json b/manifest.json index 1f02f11..aa6485c 100644 --- a/manifest.json +++ b/manifest.json @@ -3,7 +3,7 @@ "module": "SmartAssistant", "description": "Unified AI Assistant for Legal CRM — floating chat with case memory, office alerts, and AI Gateway integration", "author": "klear", - "version": "2.1.3", + "version": "2.2.0", "acceptableVersions": [ ">=8.0.0" ],