Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

asterisk cmd Case or Switch statment

Posted on 2011-03-22
7
Medium Priority
?
2,771 Views
Last Modified: 2013-11-12
Trying to write something in the macro language. or Asterisk, in the .conf files

is there a case or switch statement for this ?

can you show me a good lanuage reference
http://www.voip-info.org/wiki/view/Asterisk+cmd+Goto
this site is ok, but the search engine not smart.

What I want to do is somethign like

 IF extension = 300
         if arg2:2:5 = "505   set flag =1
         if arg2:2:5 = "533   set flag =2
         if arg2:2:5 = "544   set flag =3
 end if

or as a case
if extension = 300
switch(arg2:2:5)
     case 505 : set flag =1 break
     case 533 : set flag =2 break
     case 544 : set flag =3 break
else
     set flag=3
end

Will accept suggestions. how to do it better

The Lanuage looks like this
exten => a,n,Set(FLAG1=1})
exten => a,n,GotoIf($ARG2}" = "1"]?acontext)
BLA BLA BLA

0
Comment
Question by:yahoolane
7 Comments
 
LVL 32

Expert Comment

by:DrDamnit
ID: 35195021
Dialplan has no switch or case statements.

Alternatively, you can use AGI with PHP and get the job done quite easily.

I use this:
http://phpagi.sourceforge.net/
0
 
LVL 32

Expert Comment

by:DrDamnit
ID: 35220649
Have you tried this? Do you understand my solution?
0
 
LVL 25

Accepted Solution

by:
Ron Malmstead earned 1200 total points
ID: 35235894
Something like this maybe...

exten => s,n,ExecIf($[${ARG2:1:3} = 500]?Set(FLAG=0))
exten => s,n,ExecIf($[${ARG2:1:3} = 501]?Set(FLAG=1))
exten => s,n,ExecIf($[${ARG2:1:3} = 502]?Set(FLAG=2))

exten => s,n,GotoIf($[${FLAG} = 0]?label0)
exten => s,n,GotoIf($[${FLAG} = 1]?label1)
exten => s,n,GotoIf($[${FLAG} = 2]?label2)
exten => s,n,NoOp(Condition not met.  Hangup!)
exten => s,n,MacroExit()

exten => s,n(lable0),........
exten => s,n,MacroExit()
exten => s,n(lable1),........
exten => s,n,MacroExit()
exten => s,n(lable2),........
exten => s,n,MacroExit()


0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 32

Expert Comment

by:DrDamnit
ID: 35236947
Ooooooooo. Nice post xuser... That should do the trick...
0
 
LVL 19

Expert Comment

by:feptias
ID: 35378018
Here is yet another approach that I use sometimes:

[globals]
CASE505=1
CASE533=2
CASE544=3

[acontext]
..
exten => s,n,Set(flag=${CASE${ARG2:2:3}})

It is a very compact way of doing multiple cases, but is weak regarding default values where, say, ARG2 doesn't match any of the expected cases. I'm sure that extra code could be added to assign a default value to flag if needed.

I notice that the question also asks how to construct an if-then-else block. I would do it like this:

[acontext]
..
exten => _X.,n,Gotoif($[${EXTEN} = 300] ? match)
; Is not 300
exten => _X.,n,Noop(Extension does not equal 300)
exten => _X.,n,...
exten => _X.,n,Goto(done)
; Is 300
exten => _X.,n(match),Noop(Extension does equal 300)
exten => _X.,n,...
;
exten => _X.,n(done),...
0
 
LVL 25

Assisted Solution

by:Ron Malmstead
Ron Malmstead earned 1200 total points
ID: 35730279
[selectcase]

exten => s,1(select case),NoOp(Case ${ARG2:1:3})
exten => s,n,GotoIf($[${ARG2:1:3} <> ""]?case${ARG2:1:3}:select case)
exten => s,n,Hangup()

exten => s,n(case500),NoOp(500)
exten => s,n,Hangup()

exten => s,n(case550),NoOp(550)
exten => s,n,Hangup()

exten => s,n(case580),NoOp(580)
exten => s,n,Hangup()

0
 
LVL 1

Author Closing Comment

by:yahoolane
ID: 35985137
I did not try the
[selectcase]

But Looked great,

I did more of flags and big IF statments
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

The point of this post is to give you a copy/paste installation solution to setting up Asterisk 1.6 on Ubuntu 9.04 (or similar) server. # Setup the system apt-get install subversion apt-get install make apt-get install linux-source kernel-p…
Why do some people recommend buying business VoIP from an ISP? What are the benefits to my company? What are the costs?
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Loops Section Overview

916 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