#!/bin/bash
cp /var/lib/asterisk/sounds/pt-BR/digits/pt-as.wav /var/lib/asterisk/sounds/pt-BR/digits/pt-sss.wav
psql -U xcontact -c 'CREATE TABLE IF NOT EXISTS public.voicemail_messages (dir character varying(255) NOT NULL, msgnum integer NOT NULL, context character varying(80), macrocontext character varying(80), callerid character varying(80), origtime character varying, duration character varying, recording bytea, flag character varying(30), category character varying(30), mailboxuser character varying(30), mailboxcontext character varying(30), msg_id character varying(40), PRIMARY KEY (dir, msgnum));'
psql -U xcontact -c 'CREATE INDEX IF NOT EXISTS voicemail_messages_dir ON public.voicemail_messages USING btree (dir);'
cat > /etc/asterisk/voicemail.conf <<EOF
[general]
serveremail = xcontactemail@gmail.com
attach = yes
fromstring = Xcontact Voicemail
sendvoicemail = yes
emailonly = no
emailsubject = Mensagem de voz de ${VM_CALLERID}
emailbody = Prezado ${VM_NAME} ,\n\n  Você recebeu uma mensagem em seu correio de voz de ${VM_CALLERID} em ${STRFTIME(${EPOCH},,%d/%m/%Y %H:%M)}. \n\n Segue em anexo.\n\n----\nXcontact Voicemail
format=wav
maxmsg=100
maxsecs=60
minsecs=3
skipms=3000
maxsilence=10
silencethreshold=128
saycid=yes
maxlogins=3
odbcstorage=asterisk
odbctable=voicemail_messages

; Exemplos
[Internos]
5130305506 => 0000,Max,max.samberg@x5s.com.br
5130305507 => 0000,jorge,jorge.martins@x5s.com.br
5130305503 => 4321,Andre,andre.sarmento@x5s.com.br
5130305502 => 0000,Daniel,daniel.lauck@x5s.com.br
5130305505 => 0000,Adriano,adriano.ferreira@x5s.com.br
5501 => 2048,Fernando,fernando.rossato@x5s.com.br
EOF
asterisk -rx 'module unload app_voicemail.so'
asterisk -rx 'module load app_voicemail.so'