diff --git a/app/call_recordings/resources/classes/call_recordings.php b/app/call_recordings/resources/classes/call_recordings.php index 16635a1e69..6db7166614 100644 --- a/app/call_recordings/resources/classes/call_recordings.php +++ b/app/call_recordings/resources/classes/call_recordings.php @@ -199,7 +199,40 @@ class call_recordings { } /** - * Transcribes multiple call recordings. + * Add transcript to the xml_cdr_transcripts queue + * + * @param array $params contain domain_uuid, xml_cdr_uuid and call_direction, transcript_json, transcribe_summary + * + * @return void + */ + public function transcribe_queue($params) { + //set the global variables + global $database; + + //define the array + $array = []; + + //prepare the array with the transcript details + $array['xml_cdr_transcripts'][0]['xml_cdr_transcript_uuid'] = uuid(); + $array['xml_cdr_transcripts'][0]['domain_uuid'] = $params['domain_uuid']; + $array['xml_cdr_transcripts'][0]['xml_cdr_uuid'] = $params['xml_cdr_uuid']; + $array['xml_cdr_transcripts'][0]['transcript_json'] = $params['transcribe_message']; + + //add temporary permissions + $p = permissions::new(); + $p->add('xml_cdr_transcript_add', 'temp'); + + //save the call recording transcript + $result = $this->database->save($array, false); + $result = $this->database->message; + unset($array); + + //remove the temporary permissions + $p->delete('xml_cdr_transcript_add', 'temp'); + } + + /** + * Add one or more calls recordings to the transcribe queue. * * @param array $records An array of records to transcribe. * @@ -233,7 +266,7 @@ class call_recordings { if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) { //get the call recording file name and path - $sql = "select call_recording_name, call_recording_path "; + $sql = "select call_recording_name, call_recording_path, call_direction "; $sql .= "from view_call_recordings "; $sql .= "where call_recording_uuid = :call_recording_uuid "; $sql .= "and call_recording_transcription is null "; @@ -244,19 +277,21 @@ class call_recordings { @sizeof($field) != 0 && file_exists($field['call_recording_path'] . '/' . $field['call_recording_name']) ) { + //prepare the paramaters + $params['domain_uuid'] = $_SESSION['domain_uuid']; + $params['xml_cdr_uuid'] = $record['uuid']; + $params['call_direction'] = $field['call_direction']; + //add the recording to the transcribe queue - $array['transcribe_queue'][$x]['transcribe_queue_uuid'] = uuid(); + $array['transcribe_queue'][$x]['transcribe_queue_uuid'] = $record['uuid']; $array['transcribe_queue'][$x]['domain_uuid'] = $_SESSION['domain_uuid']; $array['transcribe_queue'][$x]['hostname'] = gethostname(); $array['transcribe_queue'][$x]['transcribe_status'] = 'pending'; - $array['transcribe_queue'][$x]['transcribe_application_name'] = 'call_recordings'; - $array['transcribe_queue'][$x]['transcribe_application_uuid'] = '56165644-598d-4ed8-be01-d960bcb8ffed'; + $array['transcribe_queue'][$x]['transcribe_app_class'] = 'call_recordings'; + $array['transcribe_queue'][$x]['transcribe_app_method'] = 'transcribe_queue'; + $array['transcribe_queue'][$x]['transcribe_app_params'] = json_encode($params); $array['transcribe_queue'][$x]['transcribe_audio_path'] = $field['call_recording_path']; $array['transcribe_queue'][$x]['transcribe_audio_name'] = $field['call_recording_name']; - $array['transcribe_queue'][$x]['transcribe_target_table'] = 'xml_cdr'; - $array['transcribe_queue'][$x]['transcribe_target_key_name'] = 'xml_cdr_uuid'; - $array['transcribe_queue'][$x]['transcribe_target_key_uuid'] = $record['uuid']; - $array['transcribe_queue'][$x]['transcribe_target_column_name'] = 'record_transcription'; //increment the id $x++; diff --git a/app/call_recordings/resources/database/views/call_recordings.php b/app/call_recordings/resources/database/views/call_recordings.php index 4f25f9df88..1ab236d2ab 100644 --- a/app/call_recordings/resources/database/views/call_recordings.php +++ b/app/call_recordings/resources/database/views/call_recordings.php @@ -1,14 +1,16 @@ diff --git a/app/xml_cdr/xml_cdr_details.php b/app/xml_cdr/xml_cdr_details.php index 122a0d7831..eb03ca624c 100644 --- a/app/xml_cdr/xml_cdr_details.php +++ b/app/xml_cdr/xml_cdr_details.php @@ -89,19 +89,21 @@ !empty($record_path) && !empty($record_name) && file_exists($record_path.'/'.$record_name)) { + //prepare the params + $params['domain_uuid'] = $_SESSION['domain_uuid']; + $params['xml_cdr_uuid'] = $uuid; + $params['call_direction'] = $call_direction; + //add the recording to the transcribe queue $array['transcribe_queue'][$x]['transcribe_queue_uuid'] = uuid(); $array['transcribe_queue'][$x]['domain_uuid'] = $_SESSION['domain_uuid']; $array['transcribe_queue'][$x]['hostname'] = gethostname(); $array['transcribe_queue'][$x]['transcribe_status'] = 'pending'; - $array['transcribe_queue'][$x]['transcribe_application_name'] = 'call_recordings'; - $array['transcribe_queue'][$x]['transcribe_application_uuid'] = '56165644-598d-4ed8-be01-d960bcb8ffed'; + $array['transcribe_queue'][$x]['transcribe_app_class'] = 'call_recordings'; + $array['transcribe_queue'][$x]['transcribe_app_method'] = 'transcribe'; + $array['transcribe_queue'][$x]['transcribe_app_params'] = json_encode($params); $array['transcribe_queue'][$x]['transcribe_audio_path'] = $record_path; $array['transcribe_queue'][$x]['transcribe_audio_name'] = $record_name; - $array['transcribe_queue'][$x]['transcribe_target_table'] = 'xml_cdr'; - $array['transcribe_queue'][$x]['transcribe_target_key_name'] = 'xml_cdr_uuid'; - $array['transcribe_queue'][$x]['transcribe_target_key_uuid'] = $uuid; - $array['transcribe_queue'][$x]['transcribe_target_column_name'] = 'record_transcription'; //add the checked rows if (is_array($array) && @sizeof($array) != 0) { @@ -183,6 +185,25 @@ unset($sql, $parameters, $row); } +//get the cdr transcript from the database + //if (permission_exists('xml_cdr_call_log') && $call_log_enabled) { + $sql = "select * from v_xml_cdr_transcripts "; + if (permission_exists('xml_cdr_all')) { + $sql .= "where xml_cdr_uuid = :xml_cdr_uuid "; + } + else { + $sql .= "where xml_cdr_uuid = :xml_cdr_uuid "; + $sql .= "and domain_uuid = :domain_uuid "; + $parameters['domain_uuid'] = $domain_uuid; + } + $parameters['xml_cdr_uuid'] = $uuid; + $row = $database->select($sql, $parameters, 'row'); + if (!empty($row) && is_array($row) && @sizeof($row) != 0) { + $transcript_json = trim($row["transcript_json"] ?? ''); + } + unset($sql, $parameters, $row); + //} + //get the format if (!empty($xml_string)) { $format = "xml"; @@ -372,7 +393,7 @@ foreach ($transcription as $segment) { if ($previous_speaker != $segment['speaker']) { if ($i > 0) { $html .= "\n"; } - $speaker_class = $segment['speaker'] === 'A' ? 'message-bubble-em' : 'message-bubble-me'; + $speaker_class = $segment['speaker'] === '0' ? 'message-bubble-em' : 'message-bubble-me'; $html .= "
"; } //$html .= " [{$segment['start']} - {$segment['end']}]"; @@ -634,7 +655,7 @@ echo "\n"; //transcription, if enabled - $transcription_array = json_decode($record_transcription, true); + $transcription_array = json_decode($transcript_json, true); $record_transcription = $transcription_array['segments']; $record_transcription_html = conversational_html($record_transcription); if ($transcribe_enabled == 'true' && !empty($transcribe_engine) && !empty($record_transcription)) {