Solved

asterisk cmd Case or Switch statment

Posted on 2011-03-22
7
2,299 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 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Cisco SF300-48 and issues with DHCP/VLAN/Voice 2 922
VoIP Avaya Phones over VSAT link 3 56
Inbound Internet connection - Temp 5 441
Porting numbers 3 65
The Zaptel people (www.zaptel.com) got kind of annoyed with the fact that they were getting bombarded with searches for the zaptel driver system for Asterisk (not to mention they own the trademark on zaptel). So, they kindly requested that Digium ch…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

770 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