Skip to content

Asterisk SMS уведомления при неответе

CentOS 6.5 Asterisk 12 GSM шлюз 2N VoiceBlue Lite, 4 GSM канала, две исходящих группы 8881 и 8882 SMS сервер https://github.com/ttobi/2n-sms-server

SIP/gsm-gate = GSG шлюз SIP/cityoperator = Оператор IP-телефонии

officemobilephones - база Астериска в которую добавляем телефоны сотрудников вручную, т.е. СМС-ки шлем только своим сотрудниками, а не всем мобильным номерам.

/etc/asterisk/sip.conf

qweqwe qwe qweqwe=1212 
1212= 12
[s.petrov]
...
context=office
...

/etc/asterisk/extension.conf

[gsm-dial]
exten => h,1,Noop(${DB(officemobilephones/${mobilephone})})
exten => h,n,Gotoif($[${DB(officemobilephones/${mobilephone})}=1]?start:noop)
exten => h,n(start),GotoIF($["${mobilephone}"=""]?noop)
exten => h,n,Noop(${DIALSTATUS})
exten => h,n,GotoIF($["${DIALSTATUS}"="NOANSWER"]?sendsms)
exten => h,n,GotoIF($["${DIALSTATUS}"="BUSY"]?sendsms)
exten => h,n,GotoIF($["${DIALSTATUS}"="CANCEL"]?sendsms)
exten => h,n,GotoIF($["${DIALSTATUS}"="CHANUNAVAIL"]?sendsms)
exten => h,n,GoTo(,h,noop)
exten => h,n(sendsms),System(/etc/asterisk/sendsms.sh ${mobilephone} "Vy propustili zvonok vid ${CALLERID(NAME)} (${callernum}) ${STRFTIME(${EPOCH},,%d.%m.%Y o %H:%M)}")
exten => h,n(noop),Noop()

exten => _X.,1,Noop(${EXTEN:0:3})
 same => n,Set(mobilephone=${EXTEN})
 same => n,Set(mcode=${EXTEN:0:3})
 same => n,Set(callernum=${CALLERID(num)})

;MTS
 same => n,GotoIf($[$[${mcode}=050] | $[${mcode}=066] ]?MTS)
 same => n,GotoIf($[$[${mcode}=095] | $[${mcode}=099] ]?MTS)

;KYIVSTAR
 same => n,GotoIf($[$[${mcode}=067] | $[${mcode}=096] ]?KYIVSTAR)
 same => n,GotoIf($[$[${mcode}=097] | $[${mcode}=098] ]?KYIVSTAR)
 same => n,GotoIf($[$[${mcode}=039] ]?KYIVSTAR)

[office]
exten => h,1,Noop()
exten => h,n(start),GotoIF($["${mobilephone}"=""]?noop)
exten => h,n,GotoIF($["${DIALSTATUS}"="NOANSWER"]?sendsms)
exten => h,n,GotoIF($["${DIALSTATUS}"="BUSY"]?sendsms)
exten => h,n,GotoIF($["${DIALSTATUS}"="CANCEL"]?sendsms)
exten => h,n,GotoIF($["${DIALSTATUS}"="CHANUNAVAIL"]?sendsms)
exten => h,n,GoTo(office,h,noop)
exten => h,n(sendsms),System(/etc/asterisk/sendsms.sh ${mobilephone} "Vy propustili zvonok vid ${CALLERID(NAME)} (${callernum}) ${STRFTIME(${EPOCH},,%d.%m.%Y o %H:%M)}")
exten => h,n(noop),Noop()
...
include => office-number
...

exten => _0501XXXXXXX,1,Goto(gsm-dial,${EXTEN},1)
exten => _066XXXXXXX,1,Goto(gsm-dial,${EXTEN},1)
exten => _095XXXXXXX,1,Goto(gsm-dial,${EXTEN},1)
exten => _098XXXXXXX,1,Dial(SIP/gsm-gate/8881${EXTEN})

[office-number]
#include "office-number.conf"

/etc/asterisk/office-number.conf

# внутренний абонент - сотрудник, с переадресаций на мобильный в рабочее время
exten => 1001,1,Dial(SIP/s.petrov,18,Ttj)
exten => 1001,n,Macro(dial,0123456789)
# возможно указать 2 номера
# example: exten => 1001,n,Macro(dial,0123456789,0223333333)

# Макрос
[macro-dial]
exten => s,1,GotoIfTime(09:00-18:30,mon-fri,*,*?macro-dial,${EXTEN},first)
exten => s,2,Hangup()
exten => s,n(first),Set(mobilephone=${ARG1})
exten => s,n,Set(callernum=${CALLERID(num)})
exten => s,n,Dial(SIP/gsm-gate/8881${ARG1})
exten => s,n,GotoIF($["${DIALSTATUS}"="BUSY"]?exitcall)
exten => s,n,Dial(SIP/gsm-gate/8882${ARG1})
exten => s,n,GotoIF($["${DIALSTATUS}"="BUSY"]?exitcall)
exten => s,n,Set(CALLERID(number)=0223333333)
exten => s,n,Dial(SIP/sip-operator/${ARG1})
exten => s,n,GotoIF($["${DIALSTATUS}"="BUSY"]?exitcall)
exten => s,n,Set(CALLERID(number)=0112222222)
exten => s,n,Dial(SIP/cityoperator/${ARG1})
exten => s,n,GotoIF($["${DIALSTATUS}"="BUSY"]?exitcall)
exten => s,n,GotoIf($[${ARG2}>""]?second)
exten => s,n,Hangup()
exten => s,n(second),Set(mobilephone=${ARG2})
exten => s,n,Dial(SIP/gsm-gate/8881${ARG2})
exten => s,n,GotoIF($["${DIALSTATUS}"="BUSY"]?exitcall)
exten => s,n,Dial(SIP/gsm-gate/8882${ARG2})
exten => s,n,GotoIF($["${DIALSTATUS}"="BUSY"]?exitcall)
exten => s,n,Set(CALLERID(number)=0223333333)
exten => s,n,Dial(SIP/sip-operator/${ARG2})
exten => s,n,GotoIF($["${DIALSTATUS}"="BUSY"]?exitcall)
exten => s,n,Set(CALLERID(number)=0112222222)
exten => s,n,Dial(SIP/cityoperator/${ARG2})
exten => s,n(exitcall),Hangup()

/etc/asterisk/sendsms.sh

#!/bin/sh
to=$1
message=`echo $2 | sed 's/ /%20/g'`
url="http://sms.domain.local:8080"
parameters="rcpt=$to&msg=$message"
log=/var/log/asterisk/sendsms.log
echo `date +"%Y-%m-%d %H:%M:%S"` TO : $to MESSAGE: $2 >>$log
/usr/bin/curl -d "$parameters" "$url"