Nesting Variables in Asterisk dialplan

Posted on 2011-03-03
Last Modified: 2012-06-21
Hello experts,

In my asterisk dialplan, when user dials extension 1, sip trunk (GSM1) should be dialled, and an email should be sent to (Email1) address. The same with extension 2,3 and 4

I wrote this in my dialplan:


exten => _[1234],1,dial(SIP/siptrunk/GSM${EVAL(${EXTEN})},60)

exten => h,1,System(/usr/local/bin/sendEmail -f -t Email${EVAL(${Email1})} -m 'This is a test message' )

In the verbose, I am having:

Executing [1@gsmplan:1] Dial("SIP/user-0000064b", "SIP/siptrunk/GSM1,60") in new stack

The problem is that it's dialing GSM1 while it should be replaced with it's variable value.

Any help?
Question by:Muhajreen
  • 3
  • 3
LVL 19

Accepted Solution

feptias earned 300 total points
ID: 35096703
Do you mean that you have a variable called GSM1??

If so, you have made two mistakes. First, the GSM must be within the EVAL brackets. Second, you are trying to use the Dahdi device format as the first argument to the Dial command, for a SIP call. SIP calls use a slightly different format for that first argument - for details see the section "Using the Dial Command with SIP Channels" at this link:

Try this:
    exten => _[1234],1,dial(SIP/${GSM${EXTEN}}@siptrunk,60)
 ...or this
    exten => _[1234],1,dial(SIP/${EVAL(GSM${EXTEN})}@siptrunk,60)


Author Comment

ID: 35109912
Thank you for your helpful post ! I was waiting for your response :)

Actually this worked perfectly:

exten => _[1234],1,dial(SIP/${GSM${EXTEN}}@siptrunk,60)

But this didn't work:

exten => h,1,Set(emailDest=${EVAL(Email${EXTEN})})
exten => h,2,System(/usr/local/bin/sendEmail -f -t ${emailDest} -m 'This is a test message' )

In console, I am getting: Set("SIP/gsmgw-00001184", "smsDest=GSMh")

Here are two problems: GSM and h.

Thank you in advance.

Author Comment

ID: 35109945
Sorry for the mistake, the verbose is:

Set("SIP/gsmgw-00001184", "emailDest=GSMh")
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

LVL 25

Expert Comment

by:Ron Malmstead
ID: 35109996
Try this....
If you accept this as part of your solution, please make sure Feptias get's points and best answer.

exten => _[1234],1,dial(SIP/${GSM${EXTEN}}@siptrunk,60)

exten => _[1234],n,Set(numdialed=${EXTEN})

exten => h,1,Set(emailDest=Email${numdialed})
exten => h,2,System(/usr/local/bin/sendEmail -f -t ${emailDest} -m 'This is a test message' )

LVL 25

Assisted Solution

by:Ron Malmstead
Ron Malmstead earned 200 total points
ID: 35110005
Wait... sorry I meant to reverse the first two lines...

exten => _[1234],1,Set(numdialed=${EXTEN})
exten => _[1234],n,dial(SIP/${GSM${EXTEN}}@siptrunk,60)

exten => h,1,Set(emailDest=Email${numdialed})
exten => h,2,System(/usr/local/bin/sendEmail -f -t ${emailDest} -m 'This is a test message' )

LVL 25

Expert Comment

by:Ron Malmstead
ID: 35110019
Remember that ${EXTEN} always evaluates the current extension....

Author Closing Comment

ID: 35110184
Thank you both ! Asterisk, EE and you are great !

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Skype for Business 2015 2 83
How do I change the password for my ShoreTel voicemail box? 4 84
VOIP grade small switch 4 68
POE switch 8 20
Hey there Heard about jingle, the add on for XMPP that enables point to point audio between two XMPP clients. No server config necessary. Actually quite a cool feature. However, how good is it if you can not use those voice capabilities to do a P…
As companies replace their old PBX phone systems with Unified IP Communications, many are finding out that legacy applications such as fax do not work well with VoIP. Fortunately, Cloud Faxing provides a cost-effective alternative that works over an…
Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Sending a Secure fax is easy with eFax Corporate ( First, just open a new email message. In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question