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

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…

exten => sms,1,Verbose(Incoming SMS from {CALLERID(num)} {BASE64_DECODE({SMS_BASE64})}) exten => sms,n,System(echo "From: {CALLERID(num)}\nTo:\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()

I can see the originating dongle name as a variable there , so what I want to do is to deliver to if it comes from dongle0 and 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 .

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

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

1 Like

Does not sound so “easy”

It really is.

Create entries in the astb

‘database put routing dongle0

‘database put routing dongle1

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)}\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()

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.