Switch with cases statement in Asterisk extensions.conf

What I want to implement is a switch(${CALLERID(number)}) case 1: case 2: statement like in a programming language. Is there possible to implement like this in an asterisk configuration file?
I mention that I use an Asterisk 11.16 version.

Sure… In AEL. Here’s a snippet from one of my hosts:

// peer IP address
                switch  (${CUT(CHANNEL,/,1)})
                        {
                        case PJSIP:
                                set(PEERIP=${CUT(CHANNEL(pjsip,remote_addr),:,1)});
                                break;
                        case SIP:
                                set(PEERIP=${CHANNEL(peerip)});
                                break;
                        default:
                                set(PEERIP=unknown);
                                break;
                        };

@sedwards
Ok. Thanks for the prompt response. I have another question about how can I obtain the iax subscriber caller id which I will set in iax.conf file as callerid=3251 and for 4251 iax friend subscriber i have callerid=4251, and in extensions.conf I will have the following dialplan:

`exten => 3251, 1, Dial(IAX2/3251,5)

same => n, VoiceMail(333@cont_voice)

    same => n, PlayBack(vm-goodbye)
    same => n, HangUp()

exten => 4251, 1, Dial(IAX2/4251,5)
same => n, VoiceMail(444@cont_voice)
same => n, PlayBack(vm-goodbye)
same => n, HangUp()
exten => 410, 1, Answer()
same => n, VoiceMailMain(IF(${CALLERID(num)}==3251)?333@cont_voice:444@cont_voice)
same => n, Hangup()
exten => 123, 1, VMAuthenticate(@cont_voice)
same => 2, SayDigits(${AUTH_MAILBOX})
When I try to authenticate in VoiceMailMain with calling from 3251 number to 410 in zoiper app the VoiceMailMain app not recognize my $(CALLERID).

Note that AEL would handle the switch by generating a context with the possible switch values as extensions. To make good use of it you need to understand what it is doing, and that this is not a general switch, but rather a convenient way of using the extension matching mechanisms.

What have you tried?

Does the ${CALLERID()} function yield any clues?

@sedwards Thanks again for reply. I managed to solve the problem with CALLERID variable. Now I have another question. Will I be able to obtain the context which is declared for an iax subscriber CALLERID. For example I set context for 3251 iax subscriber to be cont_iax and I set the CALLERID number for the 3251 subscriber in Zoiper app as 3251. Now I want to obtain the context in which is this CALLERID declared.

I haven’t used IAX in years as I suspect most members on this forum.

It has some really cool features, but it seems to have fallen out of favor.

The IAXPEER() function may give you what you want.

1 Like

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