Separate SMS email destination based on ${DONGLENAME} in dial plan


#1

I have a vanilla asterisk box running Asterisk 11 and Chan_Dongle. It passes calls on to an Elastix box and SMS is handled locally and sent via gmail.

I have the following in my dial plan delivering SMS successfully to a single email destination…

[code]
exten => sms,1,Verbose(Incoming SMS from ${CALLERID(num)} ${BASE64_DECODE(${SMS_BASE64})})
exten => sms,n,System(echo "From: ${CALLERID(num)} fromemail@gmail.com\nTo: toemail@gmail.com\nSubject: SMS ${CALLERID(num)}\n\n${STRFTIME(${EPOCH},%Y-%m-%d %H:%M:%S)} - ${DONGLENAME} - ${CALLERID(num)}: " > /tmp/sms.txt)
exten => sms,n,Set(FILE(/tmp/sms.txt,a)=${BASE64_DECODE(${SMS_BASE64})})
exten => sms,n,System(sendmail -t < /tmp/sms.txt)
exten => sms,n,Hangup()
[/code}

I can see the originating dongle name as a variable there , so what I want to do is to deliver to abc@gmail.com if it comes from dongle0 and 123@gmail.com if it comes from dongle1. So I guess I need to capture the value of that variable and use it to lookup the email address based on maybe an array or a single email based on dongle name??

That seems like a lot of work as if I can just pass them on to the same elastix box that handles the calls where each corresponding extension already has an email address defined .


#2

You can do this easily with the internal ‘astdb’ database, Just insert key/value pairs that correspond with your numbers and routes.

https://wiki.asterisk.org/wiki/display/AST/Asterisk+Internal+Database

It would also be fairly trivial to do this with FUNC_ODBC and an external SQL database.


#3

Does not sound so “easy”


#4

It really is.

Create entries in the astb

‘database put routing dongle0 abc@gmail.com

‘database put routing dongle1 123@gmail.com

In your dialplan you can use the DB function to retrieve these emails.

exten => sms,1,Verbose(Incoming SMS from ${CALLERID(num)} ${BASE64_DECODE(${SMS_BASE64})})
exten => sms,n,System(echo "From: ${CALLERID(num)} fromemail@gmail.com\nTo: ${DB(routing/${DONGLENAME})} \nSubject: SMS ${CALLERID(num)}\n\n${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)} - ${DONGLENAME} - ${CALLERID(num)}: " > /tmp/sms.txt)
exten => sms,n,Set(FILE(/tmp/sms.txt,,,a)=${BASE64_DECODE(${SMS_BASE64})})
exten => sms,n,System(sendmail -t < /tmp/sms.txt)
exten => sms,n,Hangup()