64 lines
2.0 KiB
PHP
64 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace Modules\Crm\Services;
|
|
|
|
use Illuminate\Http\UploadedFile;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Modules\Crm\Entities\CrmCallSession;
|
|
use Modules\Crm\Utils\CrmUtil;
|
|
use Modules\Crm\Utils\TelemarketingUtil;
|
|
|
|
class CallSentimentService
|
|
{
|
|
public function isEnabled(int $business_id): bool
|
|
{
|
|
$crmUtil = new CrmUtil();
|
|
$settings = TelemarketingUtil::mergeSettings($crmUtil->getCrmSettings($business_id));
|
|
|
|
return ! empty($settings['enable_ai_sentiment']) && ! empty($settings['enable_call_recording']);
|
|
}
|
|
|
|
public function storeRecording(CrmCallSession $session, UploadedFile $file): string
|
|
{
|
|
$path = $file->store('crm/call_recordings/'.$session->business_id, 'local');
|
|
$session->update(['recording_path' => $path]);
|
|
|
|
return $path;
|
|
}
|
|
|
|
/**
|
|
* Analyze recording and return suggested assessment fields.
|
|
* Integrates with Communication agent when available; falls back to neutral.
|
|
*/
|
|
public function analyze(CrmCallSession $session): array
|
|
{
|
|
if (empty($session->recording_path) || ! $this->isEnabled($session->business_id)) {
|
|
return [
|
|
'sentiment' => 'neutral',
|
|
'objections' => [],
|
|
'suggested_notes' => '',
|
|
];
|
|
}
|
|
|
|
$fullPath = Storage::disk('local')->path($session->recording_path);
|
|
|
|
if (! file_exists($fullPath)) {
|
|
return ['sentiment' => 'neutral', 'objections' => [], 'suggested_notes' => ''];
|
|
}
|
|
|
|
// Hook for Communication/Gemini agent — placeholder heuristic until agent wired
|
|
$suggested = [
|
|
'sentiment' => 'neutral',
|
|
'objections' => [],
|
|
'suggested_notes' => __('crm::lang.ai_analysis_pending'),
|
|
];
|
|
|
|
$session->update([
|
|
'ai_suggested_sentiment' => $suggested['sentiment'],
|
|
'ai_suggested_objections' => json_encode($suggested['objections']),
|
|
]);
|
|
|
|
return $suggested;
|
|
}
|
|
}
|