From fcedd54255d3ea002b63dbdd993cd7fefe89e333 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 13 May 2025 12:11:24 -0400 Subject: [PATCH] MT#62544 support transcription via task-agent Change-Id: I07e646f7c3387b7c96a04391bb9958c1fae9de46 --- Makefile | 1 + debian/control | 1 + recnotify | 26 ++++++++++++++++++++++++++ vmnotify | 20 +++++++++++++++++++- vmnotify.conf | 1 + 5 files changed, 48 insertions(+), 1 deletion(-) create mode 100755 recnotify diff --git a/Makefile b/Makefile index b1d61fe..c64317f 100644 --- a/Makefile +++ b/Makefile @@ -12,3 +12,4 @@ install: $(INSTALL_DIR) $(DESTDIR)/usr/bin $(INSTALL_PROGRAM) vmnotify $(DESTDIR)/usr/bin/ngcp-vmnotify $(INSTALL_PROGRAM) vmsmsnotify $(DESTDIR)/usr/bin/ngcp-vmsmsnotify + $(INSTALL_PROGRAM) recnotify $(DESTDIR)/usr/bin/ngcp-recnotify diff --git a/debian/control b/debian/control index 7fa977e..0e251aa 100644 --- a/debian/control +++ b/debian/control @@ -11,6 +11,7 @@ Homepage: https://www.sipwise.com/ Package: ngcp-vmnotify Architecture: all Depends: + jq, libconfig-any-perl, libdbd-mysql-perl, libdbi-perl, diff --git a/recnotify b/recnotify new file mode 100755 index 0000000..eea04c4 --- /dev/null +++ b/recnotify @@ -0,0 +1,26 @@ +#!/bin/bash +# Wrapper script to trigger transcription from an rtpengine recording +################################################################################ + +set -e +set -u +set -o pipefail + +if [ "$#" -lt 2 ]; then + echo "Usage: $0 " + exit 1 +fi + +FILENAME="$1" +DB_ID="$2" + +ENC_DB_ID="$(echo "$DB_ID" | jq -R)" + +if [ -n "$FILENAME" ] && [ -f "$FILENAME" ]; then + ENC_FILENAME="$(echo "$FILENAME" | jq -R)" + exec ngcp-invoke-task --task transcribe_rtpengine_file_recording --dst localhost --data \ + "{\"filename\":$ENC_FILENAME, \"db_id\":$ENC_DB_ID}" +fi + +exec ngcp-invoke-task --task transcribe_rtpengine_db_recording --dst localhost --data \ + "{\"db_id\":$ENC_DB_ID}" diff --git a/vmnotify b/vmnotify index e0878cd..5b25c0c 100755 --- a/vmnotify +++ b/vmnotify @@ -250,6 +250,19 @@ EOF return; } +sub transcribe { + my $msgnum = 0 + $data{msgnum}; + my $fh; + open($fh, '-|', "ngcp-invoke-task --task transcribe_voicemail --dst localhost --data " . + "'{\"msgnum\":$msgnum,\"uuid\":\"$data{uuid}\"}' 2>&1 < /dev/null"); + my @out = <$fh>; + close($fh); + my $status = $?; + if ($status) { + $log->warn("Failed to invoke transcription, exit code $status, output: @out"); + } +} + sub get_etag { my $user = shift; my $domain = shift; @@ -281,7 +294,7 @@ sub main { my $extended = 1; foreach my $arg (qw(msgnum from date duration)) { - $data{$arg} = $ARGV[$idx] or $extended = 0; + defined($data{$arg} = $ARGV[$idx]) or $extended = 0; $idx++; } @@ -351,6 +364,11 @@ sub main { $CONFIG{EXT_NOTIFY} && $CONFIG{EXT_NOTIFY} eq "yes") { send_ext_notify(); } + + if ($extended && + $CONFIG{TRANSCRIBE} && $CONFIG{TRANSCRIBE} eq "yes") { + transcribe(); + } }; if ($EVAL_ERROR) { $log->error($EVAL_ERROR); diff --git a/vmnotify.conf b/vmnotify.conf index f81c196..b9c38af 100644 --- a/vmnotify.conf +++ b/vmnotify.conf @@ -3,3 +3,4 @@ LOCAL_IP=127.0.0.1 DEBUG=0 SIPFILE="/etc/ngcp-vmnotify/mwi.sip" EXT_NOTIFY=no +TRANSCRIBE=no