[asterisk-users] application call to Gosub affects flow of control, and needs to be re-written using AEL

Zeeshan Zakaria zishanov at gmail.com
Fri Jul 23 09:44:33 CDT 2010


Hi,

I try to avoid any warnings, as they can  turn into errors later.

I remember having problems with GoSub long time ago, don't remember what it
was, but I moved to macros after that.

For what you are trying to achieve, I use macros. Just jump to a macro,
evaluate what you need to, save the results in variables, and use these
variables in the calling context to proceed further. For example, in my
context for outbound calls, called [outbound], I jump to macro
[user-account-info], get account info, come back to [outbound], then jump to
[blacklist], check the caller ID against a blacklist, come back to
[outbound], jump to two other macros, and finally I have all the info I need
to proceed with a call, stored in various variables. Based on these
variables I trigger the Dial command, or do something else as needed.

In your case, you can make it even simpler, e.g. like this:

context outboundSimple {
        _9X. => {
                // prepare callerid, secret, ...
                /// ...

                // start call routing
if("${EXTEN:1:3}"="06") {
&pstnInterface2(${EXTEN:1});
}
else {
&pstnInterface1(${EXTEN:1});
};
                // back, handle return status
        };

h => {
&dialstatus(${DIALSTATUS},${EXTEN:1});
};

}


macro pstnInterface1(number) {

                // setup the interface callerid/secret status

                ChanIsAvail(DAHDI/g1);
                if( ! ${ISNULL(${AVAILORIGCHAN})} ) {
                        Dial(DAHDI/g1/${number},,${dialopts});
                };

catch h {
&dialstatus(${DIALSTATUS},${number});
};

}

macro pstnInterface2(number) {

                // setup the interface callerid/secret status

                ChanIsAvail(SIP/....);
                if( ! ${ISNULL(${AVAILORIGCHAN})} ) {
                        Dial(SIP/.../${number},,${dialopts});
                };

catch h {
&dialstatus(${DIALSTATUS},${number});
};
}

On Fri, Jul 23, 2010 at 9:50 AM, Benoit <maverick at maverick.eu.org> wrote:

>
> Hi,
>
> For some reason (outbound call tracking) I've got a few different
> outbound call process (using a macro for queuemetrics logging, or direct
> call)
> i wanted to factorise the routing process so i came up with something
> like the following. All in one it's working like expected, however
> every "ael reload" command trigger a lot of warning like that
>
>     "application call to Gosub affects flow of control, and needs to be
> re-written using AEL if, while, goto, etc. keywords instead!"
>
> But i fail to see how i could do it another way, any idea/suggestion ?
>
>
> Extraction of the outbound processing structure:
>
> context outboundSimple {
>         _9X. => {
>                 // prepare callerid, secret, ...
>                 /// ...
>
>                 // start call routing
>                 Gosub(pstnRouting,${EXTEN:1},1);
>                 // back, handle return status
> &dialstatus(${DIALSTATUS},${EXTEN:1});
>                 }
> }
>
> context outboundQueue1 {
>         _9X. => {
>                 // prepare callerid, secret, ...
>                 /// ...
>
> &qmoutqdial(${EXTEN:1},DAHDI/g1/${EXTEN:1},queue-out,Agent/${AgentNum});
>                 }
> }
>
> context outboundQueue2 {
> ....
> }
>
> // outbound call logging for queuemetrics:
> macro qmoutqdial( clid, dialstring, queue, agent )
> {
>         start_dial_time = ${EPOCH};
>         QueueLog(${queue},${UNIQUEID},${agent},CALLOUTBOUND,-|${clid});
>
>
>
> Set(dialopts=gWKU(queuelog_connect_event^${queue}^${UNIQUEID}^${agent}^${start_dial_time}));
>         Gosub(pstnRouting,${clid},1);
>
>         end_dial_time = ${EPOCH};
>         verb = COMPLETECALLER;
> &queuelog_hangup_event(${queue},${UNIQUEID},${agent},${start_dial_time});
>         return;
> }
>
>
> // central call routing rules
> context pstnRouting {
>
>         _06XXXXXXXX => { Gosub(pstnInterface2,${EXTEN},1); Return; }
>         ....
>
>         // left over
>         _X. =>  { Gosub(pstnInterface1,${EXTEN},1); Return; }
> }
>
> context pstnInterface1 {
>         _X. => {
>                 // setup the interface callerid/secret status
>
>                 ChanIsAvail(DAHDI/g1);
>                 if( ! ${ISNULL(${AVAILORIGCHAN})} ) {
>                         Dial(DAHDI/g1/${ext},,${dialopts});
>                 }
>                 Return;
>                 }
> }
>
> context pstnInterface2 {
>         _X. => {
>                 // setup the interface callerid/secret status
>
>                 ChanIsAvail(SIP/....);
>                 if( ! ${ISNULL(${AVAILORIGCHAN})} ) {
>                         Dial(SIP/.../${ext},,${dialopts});
>                 }
>                 Return;
>                 }
> }
>
>
> --
> _____________________________________________________________________
> -- Bandwidth and Colocation Provided by http://www.api-digital.com --
> New to Asterisk? Join us for a live introductory webinar every Thurs:
>               http://www.asterisk.org/hello
>
> asterisk-users mailing list
> To UNSUBSCRIBE or update options visit:
>   http://lists.digium.com/mailman/listinfo/asterisk-users
>



-- 
Zeeshan A Zakaria
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-users/attachments/20100723/88194e00/attachment.htm 


More information about the asterisk-users mailing list