How to incorporate AGI program execution into dialplan

We have an AGI program that generates a CallerID screen for display on our Cisco phones. Inbound calls from the PSTN are sent to a ring group but we need the CallerID screen to be displayed on all phones so that anyone can pick up the call.

I’m struggling to work out the right location for the AGI program’s execution. Right now it’s located in the [from-zaptel] context in extensions_additional.conf (obviously the wrong place because I have to remember to add it again every time I make a change).

[from-zaptel]
include => from-zaptel-custom
exten => _X.,1,Set(DID=${EXTEN})
exten => _X.,n,Goto(s,1)
exten => s,1,Noop(Entering from-zaptel with DID == ${DID})
exten => s,n,Ringing()
exten => s,n,Set(DID=${IF($["${DID}"= “”]?s:${DID})})
exten => s,n,Noop(DID is now ${DID})
exten => s,n,GotoIf($["${CHANNEL:0:3}"=“Zap”]?zapok:notzap)
exten => s,n(notzap),Goto(from-pstn,${DID},1)
exten => s,n,Macro(Hangupcall,dummy)
exten => s,n(zapok),Noop(Is a Zaptel Channel)
exten => s,n,Set(CHAN=${CHANNEL:4})
exten => s,n,Set(CHAN=${CUT(CHAN,-,1)})
exten => s,n,AGI(callerid.agi)
exten => s,n,Macro(from-zaptel-${CHAN},${DID},1)
exten => s,n,Noop(Returned from Macro from-zaptel-${CHAN})
exten => s,n,Goto(from-pstn,${DID},1)
exten => fax,1,Goto(ext-fax,in_fax,1)
; end of [from-zaptel]

Having looked at the recordingcheck AGI program and where it gets executed from within the dialplan it seems that my callerid.agi script is best defined as a macro. The problem is I can’t figure out with macros how to resume where I left i.e. execute the AGI program and then go to the next step in the dialplan.

I’d appreciate any suggestions for a suitable method for solving this problem.

Many thanks,

Kevin Clark
Connection Software

Use “/etc/asterisk/extensions_custom.conf” as the persistent conf file.

The AGI script will return to the line after its call, assuming the script does NOT itself send the call somewhere else in the dial plan (e.g. does NOT execute a goto). Typically, the AGI script will “talk back” to the dial plan through channel variable(s).

For example, your AGI script will SET MYAGI_VAR1="Jabberwalkie". The the rest of the dial plan can use the variable.

for example,

exten => 1,1,AGI(MYSCRIPT,${CALLERID(num)})
exten => 1,n,GotoIf($["${MYAGI_VAR1}" = "Jabberwalkie"]?branch-true:branch-false)
exten => 1,n(branch-true),...
exten => 1,n,...
exten => 1,n(branch-false),...
exten => 1,n,...

Assuming you want your script to light-off (execute) BEFORE any of the standard dial plan, then authoring the custom context from-zaptel-custom would do it.

In /etc/asterisk/extensions_custom.conf
[from-zaptel-custom]
exten => _.,1,AGI(<script_name>,arg1,...,argn)
exten => _.,n,...any other dial plan code as needed...
exten => _.,n,Goto(from-zaptel,s,1)

There are other ways too. Hopefully, these may get your thinking started in useful directions.

/S

Also, be careful about incorrect use of the “s” extension, as in,

exten => s,1,...
-- vs., for example, --
exten => _[0-9a-zA-Z*#].,1,...

Outside of a macro, “s” can be thought of to mean NOT KNOWN; it is not really a wild card/catch-all match. Be very aware that the values of channel variables, like ${EXTEN} for one, in an “s” vs., say, “_[0-9a-zA-Z*#].” exten, are NOT what you might expect.

/S

Following your recommendation I tried a few options which either resulted in the AGI program executing multiple times and/or the internal extension to which the DID is directed not ringing.

First I tried putting the AGI script in the custom context [from-zaptel-custom]:

[from-zaptel-custom]
exten => _.,1,AGI(callerid.agi)
exten => _.,n,Goto(from-zaptel,s,1)

This resulted in the AGI program not being executed but the internal extension still ringing.

Next I tried putting the AGI program in the ext-did custom context [ext-did-custom]:

[ext-did-custom]
exten => _.,1,AGI(callerid.agi)
exten => _.,n,Goto(ext-did,s,1)

This resulted in the AGI program being executed multiple times but the internal extension not ringing.

The only way that I have been able to achieve my goal is to ‘override’ the DID in a custom context. By ‘override’ I mean that I have copied the definition of the extension from the [ext-did] context in extensions_additional.conf, e.g.

[ext-did]
exten => zapchan8,1,Set(__FROM_DID=${EXTEN})
exten => zapchan8,n,ExecIf($[ “${CALLERID(name)}” = “” ] ,Set,CALLERID(name)=${CALLERID(num)})
exten => zapchan8,n,Set(FAX_RX=disabled)
exten => zapchan8,n,Set(_CALLINGPRES_SV=${CALLINGPRES${CALLINGPRES}})
exten => zapchan8,n,SetCallerPres(allowed_not_screened)
exten => zapchan8,n,Goto(from-did-direct,425,1)

And inserted it in its entirety into a custom context along with the call to to my AGI program, thus:

[ext-did-custom]
exten => zapchan8,1,Set(__FROM_DID=${EXTEN})
exten => zapchan8,n,ExecIf($[ “${CALLERID(name)}” = “” ] ,Set,CALLERID(name)=${CALLERID(num)})
exten => zapchan8,n,Set(FAX_RX=disabled)
exten => zapchan8,n,Set(_CALLINGPRES_SV=${CALLINGPRES${CALLINGPRES}})
exten => zapchan8,n,SetCallerPres(allowed_not_screened)
exten => zapchan8,n,AGI(callerid.agi)
exten => zapchan8,n,Goto(from-did-direct,425,1)

With the result that the AGI program is called just the once, the extension rings and can be answered.

Do you have any idea why the [from-zaptel-custom] and [ext-did-custom] context approaches had the results they did?

Thanks,

Kevin

After going around in circles I finally managed to locate the right place in the dialplan that gets our custom CallerID AGI program executed when an incoming call comes through on a trunk:

/etc/asterisk/extensions_custom.conf

[from-pstn-custom]
exten => _.,1,AGI(callerid.agi)
exten => _.,n,Goto(ext-did,${EXTEN},1)