-
Notifications
You must be signed in to change notification settings - Fork 1
/
asterisk_voicemail_parser
executable file
·34 lines (27 loc) · 1.13 KB
/
asterisk_voicemail_parser
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/sh -eu
#
# Reads Asterisk voicemail messages and sends them to Matrix rooms
# which have #tele-EXTENSION:hacklab.fi alias. Works on Telegram
# bridged channels, too!
# Read configuration
. "`dirname $0`/matrix.conf"
. "`dirname $0`/functions.sh"
# Get Asterisk phone number. Do it without reading too much input (-u)
cid=`sed -un '/^X-Asterisk-CallerID/{s/[^:]*: //p;q}'`
# Unpacking message payload
dir=`mktemp -d`
cd $dir
munpack -t
myname=`sed -rn '/,$/{s/,$//p;q}' <part1`
mynum=`sed -rn '/mailbox/{s/[^0-9]*([0-9]*).*/\1/p;q}' <part1`
room="#tele-$mynum:$alias_homeserver"
export audioname="Viesti numerosta $cid"
# Encode audio
opusenc --artist "Numero $cid" --title "Viesti käyttäjälle $myname" -- *.wav viesti.opus
# Composing Matrix message. Specs: https://matrix.org/docs/spec/client_server/latest#m-audio
room_id="`get_id "$room"`"
matrix POST media/r0/upload audio/ogg <viesti.opus |
jq '{"body": env.audioname, "msgtype": "m.audio", "info": {"mimetype":"audio/ogg"}, "url": .content_uri }' |
matrix PUT "client/r0/rooms/$room_id/send/m.room.message/`uuidgen`" application/json
# Removing the temp dir
rm -r "$dir"