Solved

asterisk cmd Case or Switch statment

Posted on 2011-03-22
7
2,450 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 300 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 300 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
There are no good configuration guides for HP-H3C router to LYNC on the web. :( Big statement, but we havent been able to find one yet. We did find the following document useful, but the information was not enough to use H3C router for use as a L…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

751 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