Add support for custom transcription prompts in voicemail processing (#7908)

This commit is contained in:
Antonio Fernandez
2026-05-25 10:45:02 -04:00
committed by GitHub
parent 695b7d7410
commit 1b225840c4
7 changed files with 245 additions and 1 deletions
+8
View File
@@ -474,6 +474,14 @@
$apps[$x]['db'][$y]['fields'][$z]['type'] = "boolean";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "If voicemail transcription is enabled for this user";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = "voicemail_transcription_prompt_enabled";
$apps[$x]['db'][$y]['fields'][$z]['type'] = "boolean";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "If custom prompt post-processing of transcriptions is enabled";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = "voicemail_transcription_prompt";
$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Custom prompt template; use \${transcription} as placeholder for the raw STT text";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = "voicemail_attach_file";
$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Choose whether to attach the file to the email.";
+9
View File
@@ -1701,6 +1701,15 @@ $text['description-voicemail_transcription_enabled']['zh-cn'] = "选择是否为
$text['description-voicemail_transcription_enabled']['ja-jp'] = "この内線番号に対してボイスメールの文字起こしを有効にするかどうかを選択します。";
$text['description-voicemail_transcription_enabled']['ko-kr'] = "이 확장 프로그램에 음성 메일 전사가 활성화되어 있는지 선택하십시오.";
$text['label-voicemail_transcription_prompt_enabled']['en-us'] = "Custom Prompt Processing";
$text['label-voicemail_transcription_prompt_enabled']['en-gb'] = "Custom Prompt Processing";
$text['description-voicemail_transcription_prompt_enabled']['en-us'] = "When enabled, the transcription is sent to the configured AI provider with a custom prompt before being included in the voicemail email.";
$text['description-voicemail_transcription_prompt_enabled']['en-gb'] = "When enabled, the transcription is sent to the configured AI provider with a custom prompt before being included in the voicemail email.";
$text['label-voicemail_transcription_prompt']['en-us'] = "Transcription Prompt";
$text['label-voicemail_transcription_prompt']['en-gb'] = "Transcription Prompt";
$text['description-voicemail_transcription_prompt']['en-us'] = "Enter the prompt template. Use \${transcription} as a placeholder for the raw transcription text. If omitted, the transcription is appended after the prompt.";
$text['description-voicemail_transcription_prompt']['en-gb'] = "Enter the prompt template. Use \${transcription} as a placeholder for the raw transcription text. If omitted, the transcription is appended after the prompt.";
$text['description-voicemail_message']['en-us'] = "A list of recorded voice messages which shows when the message was created, caller ID information, length, file size and download or delete the message.";
$text['description-voicemail_message']['en-gb'] = "A list of recorded voice messages which shows when the message was created, caller ID information, length, file size and download or delete the message.";
$text['description-voicemail_message']['ar-eg'] = "قائمة بالرسائل الصوتية المسجلة التي تظهر وقت إنشاء الرسالة ومعلومات هوية المتصل وطولها وحجم الملف وتنزيل الرسالة أو حذفها.";
@@ -1183,6 +1183,23 @@ class voicemail {
$transcribe->audio_filename = basename($voicemail_message_file);
$message_transcription = $transcribe->transcribe('text');
if (!empty($message_transcription) && class_exists('transcribe_prompt')) {
$sql = "select voicemail_transcription_prompt_enabled, voicemail_transcription_prompt "
. "from v_voicemails where voicemail_uuid = :voicemail_uuid ";
$parameters['voicemail_uuid'] = $this->voicemail_uuid;
$vm_row = $this->database->select($sql, $parameters, 'row');
unset($sql, $parameters);
if (in_array($vm_row['voicemail_transcription_prompt_enabled'] ?? null, [true, 'true', 't'], true)
&& !empty($vm_row['voicemail_transcription_prompt'])
) {
$prompt_processor = new transcribe_prompt($settings);
$prompt_result = $prompt_processor->process($message_transcription, $vm_row['voicemail_transcription_prompt']);
if (!empty($prompt_result)) {
$message_transcription = $prompt_result;
}
}
}
//build voicemail message data array
if (!empty($message_transcription)) {
$array['voicemail_messages'][0]['voicemail_message_uuid'] = $this->voicemail_message_uuid;
+40
View File
@@ -127,6 +127,8 @@
$voicemail_mail_to = $_POST["voicemail_mail_to"];
$voicemail_sms_to = $_POST["voicemail_sms_to"] ?? null;
$voicemail_transcription_enabled = $_POST["voicemail_transcription_enabled"];
$voicemail_transcription_prompt_enabled = $_POST["voicemail_transcription_prompt_enabled"] ?? 'false';
$voicemail_transcription_prompt = $_POST["voicemail_transcription_prompt"] ?? '';
$voicemail_file = $_POST["voicemail_file"];
$voicemail_local_after_email = $_POST["voicemail_local_after_email"];
$voicemail_destination = $_POST["voicemail_destination"];
@@ -204,6 +206,10 @@
$array['voicemails'][0]['voicemail_mail_to'] = $voicemail_mail_to;
$array['voicemails'][0]['voicemail_sms_to'] = $voicemail_sms_to;
$array['voicemails'][0]['voicemail_transcription_enabled'] = $voicemail_transcription_enabled;
if ($transcribe_enabled && permission_exists('voicemail_transcription_enabled')) {
$array['voicemails'][0]['voicemail_transcription_prompt_enabled'] = $voicemail_transcription_prompt_enabled;
$array['voicemails'][0]['voicemail_transcription_prompt'] = $voicemail_transcription_prompt;
}
$array['voicemails'][0]['voicemail_tutorial'] = $voicemail_tutorial;
if (permission_exists('voicemail_recording_instructions')) {
$array['voicemails'][0]['voicemail_recording_instructions'] = $voicemail_recording_instructions;
@@ -370,6 +376,10 @@
$sql .= "voicemail_mail_to, ";
$sql .= "voicemail_sms_to, ";
$sql .= "voicemail_transcription_enabled, ";
if ($transcribe_enabled && permission_exists('voicemail_transcription_enabled')) {
$sql .= "voicemail_transcription_prompt_enabled, ";
$sql .= "voicemail_transcription_prompt, ";
}
$sql .= "voicemail_tutorial, ";
$sql .= "voicemail_recording_instructions, ";
$sql .= "voicemail_recording_options, ";
@@ -393,6 +403,8 @@
$voicemail_mail_to = $row["voicemail_mail_to"];
$voicemail_sms_to = $row["voicemail_sms_to"];
$voicemail_transcription_enabled = $row["voicemail_transcription_enabled"];
$voicemail_transcription_prompt_enabled = $row["voicemail_transcription_prompt_enabled"] ?? false;
$voicemail_transcription_prompt = $row["voicemail_transcription_prompt"] ?? '';
$voicemail_tutorial = $row["voicemail_tutorial"];
$voicemail_recording_instructions = $row["voicemail_recording_instructions"];
$voicemail_recording_options = $row["voicemail_recording_options"];
@@ -419,6 +431,8 @@
$voicemail_local_after_email = $voicemail_local_after_email ?? true;
$voicemail_enabled = $voicemail_enabled ?? $settings->get('voicemail', 'enabled_default', true);
$voicemail_transcription_enabled = $voicemail_transcription_enabled ?? $settings->get('voicemail', 'transcription_enabled_default', false);
$voicemail_transcription_prompt_enabled = $voicemail_transcription_prompt_enabled ?? false;
$voicemail_transcription_prompt = $voicemail_transcription_prompt ?? '';
$voicemail_tutorial = $voicemail_tutorial ?? false;
$voicemail_recording_instructions = $voicemail_recording_instructions ?? true;
$voicemail_recording_options = $voicemail_recording_options ?? true;
@@ -923,6 +937,32 @@
echo $text['description-voicemail_transcription_enabled']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-voicemail_transcription_prompt_enabled']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <select class='formfld' name='voicemail_transcription_prompt_enabled' id='voicemail_transcription_prompt_enabled' onchange=\"document.getElementById('voicemail_transcription_prompt_row').style.display = (this.value === 'true') ? '' : 'none';\">\n";
echo " <option value='false' ".(!in_array($voicemail_transcription_prompt_enabled, [true, 'true', 't'], true) ? "selected='selected'" : null).">".$text['option-false']."</option>\n";
echo " <option value='true' ".(in_array($voicemail_transcription_prompt_enabled, [true, 'true', 't'], true) ? "selected='selected'" : null).">".$text['option-true']."</option>\n";
echo " </select>\n";
echo "<br />\n";
echo $text['description-voicemail_transcription_prompt_enabled']."\n";
echo "</td>\n";
echo "</tr>\n";
$prompt_row_style = in_array($voicemail_transcription_prompt_enabled, [true, 'true', 't'], true) ? '' : 'display:none;';
echo "<tr id='voicemail_transcription_prompt_row' style='".$prompt_row_style."'>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-voicemail_transcription_prompt']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <textarea class='formfld' name='voicemail_transcription_prompt' rows='4' style='width:100%;'>".escape($voicemail_transcription_prompt)."</textarea>\n";
echo "<br />\n";
echo $text['description-voicemail_transcription_prompt']."\n";
echo "</td>\n";
echo "</tr>\n";
}
if (permission_exists('voicemail_file')) {