Files
jp 857284abbf Initial build: Asterisk voicemail transcription + portal
- mailcmd replacement (vm_mailcmd.py): faster-whisper transcription (CPU int8),
  extractive summary + intent tags + spoken-digit number extraction,
  multipart/alternative HTML email, fail-safe relay of original message
- Telegram DM delivery (vm_telegram.py) with per-mailbox routing
- Caller-ID -> name (vm_contacts.py): file / google / carddav backends
- SQLite store (vm_store.py) with content-addressed audio
- FastAPI portal (vm_web.py): PIN login, list/play/delete, per-user settings,
  zero JS, loopback-only behind Apache TLS
- Backfill importer (vm_import.py) for existing spool recordings
- systemd unit, Apache vhost + certbot TLS, install.sh
- Docs: INSTALL, CONFIGURATION, ARCHITECTURE, OPERATIONS, SECURITY, TESTING

Verified end-to-end on mail.txt3.net: 157 historical messages backfilled,
live voicemail -> transcribed -> stored -> visible at https://vm.txt3.net.
2026-08-13 09:31:41 +01:00

63 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
# Installs the voicemail transcription mailcmd. Run with sudo.
set -euo pipefail
SRC=/home/jp/asterisk-vm
DEST=/opt/vm-transcribe
echo "== creating $DEST"
install -d -o asterisk -g asterisk -m 755 "$DEST" "$DEST/models"
echo "== python venv + faster-whisper"
if [ ! -x "$DEST/venv/bin/python3" ]; then
python3 -m venv "$DEST/venv"
"$DEST/venv/bin/pip" install -q --upgrade pip
"$DEST/venv/bin/pip" install -q faster-whisper
fi
echo "== installing script"
install -o root -g root -m 755 "$SRC/vm_mailcmd.py" "$DEST/vm_mailcmd.py"
install -o root -g root -m 755 "$SRC/vm_telegram.py" "$DEST/vm_telegram.py"
install -o root -g root -m 755 "$SRC/vm_tg_setup.py" "$DEST/vm_tg_setup.py"
chown -R asterisk:asterisk "$DEST/models"
echo "== telegram config (not overwritten if it already exists)"
if [ ! -f "$DEST/telegram.conf" ]; then
install -o root -g asterisk -m 640 "$SRC/telegram.conf" "$DEST/telegram.conf"
echo " created $DEST/telegram.conf - add your bot token and chat IDs"
else
echo " kept existing $DEST/telegram.conf"
fi
echo "== log file"
touch /var/log/asterisk/vm_mailcmd.log
chown asterisk:asterisk /var/log/asterisk/vm_mailcmd.log
chmod 640 /var/log/asterisk/vm_mailcmd.log
echo "== pre-downloading the whisper model as the asterisk user"
sudo -u asterisk "$DEST/venv/bin/python3" - <<EOF
from faster_whisper import WhisperModel
WhisperModel("base.en", device="cpu", compute_type="int8", download_root="$DEST/models")
print("model cached")
EOF
echo "== patching /etc/asterisk/voicemail.conf"
CONF=/etc/asterisk/voicemail.conf
cp -a "$CONF" "$CONF.bak-$(date +%Y%m%d%H%M%S)"
python3 - <<EOF
import re
p="$CONF"
s=open(p).read()
old="mailcmd=sendmail -t"
new="mailcmd=$DEST/venv/bin/python3 $DEST/vm_mailcmd.py"
assert s.count(old)==1, "anchor not found exactly once: %d" % s.count(old)
s=s.replace(old,new)
open(p,"w").write(s)
print("mailcmd set to:",new)
EOF
echo "== reloading asterisk voicemail"
asterisk -rx "voicemail reload" || asterisk -rx "module reload app_voicemail"
echo "DONE. Watch: tail -f /var/log/asterisk/vm_mailcmd.log"