How do I attach an AGI script to all incoming call pickups

I’m new to FreePBX / Asterisk and am looking for a way where I can hook an AGI script to trigger when someone picks up an incoming call whether it is from internal or external.

I took a guess at somehow cloning [from-sip-external] section from extensions.conf into extension_override_freepbx.conf then prepend it with the AGI command and script I need to run. but it didn’t change anything.

Can anyone give any advice on how to achieve this? Thanks.

Paul

Logs?

Are you sure it didn’t do “anything”? There are several possibilities that come to mind where it did what you told it, just not what you wanted.

It’s now partially working, but clearly, still something is up. In extension_override_freepbx.conf I put the following:

[from-internal]

exten => _20XX,1,AGI(ordercheck.php)
exten => _20XX,n,GotoIf(${ISNULL(${cust_name})}?end)
exten => _20XX,n,Set(CALLERID(name)=${cust_name})
exten => _20XX,n(end),Noop()

; these lines below were copied from the original section in extensions.conf
include => from-internal-noxfer
include => from-internal-xfer
include => bad-number ; auto-generated

The weird bug is that it stops some of the internal phones ringing eachother, but not all. the AGI script has nothing to do with the bug as far as I’m aware, as even when I take all the code out of the script, there is still the issue, is my config file correct? Is it overriding something it shouldn’t? What do I need to do to run the script succesfully?

I assume the php script below shouldn’t be an issue as it doesn’t set anything:

#!/usr/bin/php -q

<?php require_once "phpagi.php"; $agi = new AGI(); Below is the log file from a failed call : [2015-02-07 14:39:42] DEBUG[12959]: threadpool.c:1107 worker_idle: Worker thread idle timeout reached. Dying. [2015-02-07 14:39:42] DEBUG[12958]: threadpool.c:1107 worker_idle: Worker thread idle timeout reached. Dying. [2015-02-07 14:39:44] DEBUG[3788]: res_pjsip_session.c:263 handle_incoming_sdp: Negotiating incoming SDP media stream 'audio' using audio SDP handler [2015-02-07 14:39:44] DEBUG[3788]: rtp_engine.c:419 ast_rtp_instance_new: Using engine 'asterisk' for RTP instance '0x7f4e30b30498' [2015-02-07 14:39:44] DEBUG[3788]: res_rtp_asterisk.c:2435 ast_rtp_new: Allocated port 12226 for RTP instance '0x7f4e30b30498' [2015-02-07 14:39:44] DEBUG[3788]: rtp_engine.c:428 ast_rtp_instance_new: RTP instance '0x7f4e30b30498' is setup and ready to go [2015-02-07 14:39:44] DEBUG[3788]: res_rtp_asterisk.c:4677 ast_rtp_prop_set: Setup RTCP on RTP instance '0x7f4e30b30498' [2015-02-07 14:39:44] DEBUG[3788]: rtp_engine.c:648 ast_rtp_codecs_payloads_set_m_type: Setting payload 8 (0x7f4e30b7a518) based on m type on 0x7f4e2c0d63d0 [2015-02-07 14:39:44] DEBUG[3788]: rtp_engine.c:648 ast_rtp_codecs_payloads_set_m_type: Setting payload 4 (0x7f4e30b7a518) based on m type on 0x7f4e2c0d63d0 [2015-02-07 14:39:44] DEBUG[3788]: rtp_engine.c:648 ast_rtp_codecs_payloads_set_m_type: Setting payload 18 (0x7f4e30b7a518) based on m type on 0x7f4e2c0d63d0 [2015-02-07 14:39:44] DEBUG[3788]: rtp_engine.c:648 ast_rtp_codecs_payloads_set_m_type: Setting payload 0 (0x7f4e30b7a518) based on m type on 0x7f4e2c0d63d0 [2015-02-07 14:39:44] DEBUG[3788]: rtp_engine.c:648 ast_rtp_codecs_payloads_set_m_type: Setting payload 101 (0x7f4e30b7a518) based on m type on 0x7f4e2c0d63d0 [2015-02-07 14:39:44] DEBUG[3788]: res_pjsip_session.c:273 handle_incoming_sdp: Media stream 'audio' handled by audio [2015-02-07 14:39:44] DEBUG[12982][C-00000245]: pbx.c:4921 pbx_extension_helper: Launching 'AGI' -- Executing [[email protected]:1] AGI("PJSIP/2001-0000008d", "ordercheck.php") in new stack -- Launched AGI Script /var/lib/asterisk/agi-bin/ordercheck.php -- AGI Script ordercheck.php completed, returning 0 [2015-02-07 14:39:44] DEBUG[12982][C-00000245]: pbx.c:4921 pbx_extension_helper: Launching 'GotoIf' -- Executing [[email protected]:2] GotoIf("PJSIP/2001-0000008d", "1?end") in new stack -- Goto (from-internal,2003,4) [2015-02-07 14:39:44] DEBUG[12982][C-00000245]: pbx.c:4921 pbx_extension_helper: Launching 'NoOp' -- Executing [[email protected]:4] NoOp("PJSIP/2001-0000008d", "") in new stack [2015-02-07 14:39:44] DEBUG[12982][C-00000245]: pbx.c:4921 pbx_extension_helper: Launching 'Goto' -- Executing [[email protected]:5] Goto("PJSIP/2001-0000008d", "vmret,1") in new stack -- Goto (from-internal,vmret,1) [2015-02-07 14:39:44] DEBUG[12982][C-00000245]: pbx.c:4825 pbx_substitute_variables_helper_full: Expression result is '0' [2015-02-07 14:39:44] DEBUG[12982][C-00000245]: pbx.c:4921 pbx_extension_helper: Launching 'GotoIf' -- Executing [[email protected]:1] GotoIf("PJSIP/2001-0000008d", "0?playret") in new stack [2015-02-07 14:39:44] DEBUG[12982][C-00000245]: pbx.c:11661 pbx_builtin_gotoif: Not taking any branch [2015-02-07 14:39:44] DEBUG[12982][C-00000245]: pbx.c:4921 pbx_extension_helper: Launching 'Hangup' -- Executing [[email protected]:2] Hangup("PJSIP/2001-0000008d", "") in new stack [2015-02-07 14:39:44] DEBUG[12982][C-00000245]: channel.c:2550 ast_softhangup_nolock: Soft-Hanging (0x20) up channel 'PJSIP/2001-0000008d' [2015-02-07 14:39:44] DEBUG[12982][C-00000245]: pbx.c:6423 __ast_pbx_run: Spawn extension (from-internal,vmret,2) exited non-zero on 'PJSIP/2001-0000008d' == Spawn extension (from-internal, vmret, 2) exited non-zero on 'PJSIP/2001-0000008d' [2015-02-07 14:39:44] DEBUG[12982][C-00000245]: channel.c:2550 ast_softhangup_nolock: Soft-Hanging (0x10) up channel 'PJSIP/2001-0000008d' [2015-02-07 14:39:44] DEBUG[12982][C-00000245]: channel.c:2550 ast_softhangup_nolock: Soft-Hanging (0x80) up channel 'PJSIP/2001-0000008d' [2015-02-07 14:39:44] DEBUG[12982][C-00000245]: pbx.c:4921 pbx_extension_helper: Launching 'Hangup' -- Executing [[email protected]:1] Hangup("PJSIP/2001-0000008d", "") in new stack [2015-02-07 14:39:44] DEBUG[12982][C-00000245]: channel.c:2550 ast_softhangup_nolock: Soft-Hanging (0x20) up channel 'PJSIP/2001-0000008d' [2015-02-07 14:39:44] DEBUG[12982][C-00000245]: pbx.c:5992 ast_pbx_h_exten_run: Spawn extension (from-internal,h,1) exited non-zero on 'PJSIP/2001-0000008d' == Spawn extension (from-internal, h, 1) exited non-zero on 'PJSIP/2001-0000008d' [2015-02-07 14:39:44] DEBUG[12982][C-00000245]: channel.c:2699 ast_hangup: Hanging up channel 'PJSIP/2001-0000008d' [2015-02-07 14:39:44] DEBUG[12982][C-00000245]: chan_pjsip.c:1639 hangup_cause2sip: AST hangup cause 16 (no match found in PJSIP) [2015-02-07 14:39:44] DEBUG[3788]: res_rtp_asterisk.c:4732 ast_rtp_remote_address_set: Setting RTCP address on RTP instance '0x7f4e30b30498' [2015-02-07 14:39:44] DEBUG[3788]: rtp_engine.c:362 instance_destructor: Destroyed RTP instance '0x7f4e30b30498' [2015-02-07 14:39:44] DEBUG[3788]: taskprocessor.c:484 tps_taskprocessor_destroy: destroying taskprocessor 'd69c2382-7039-4838-8c8d-a7c513478b08' [2015-02-07 14:39:44] DEBUG[974]: cdr.c:1266 cdr_object_finalize: Finalized CDR for PJSIP/2001-0000008d - start 1423319984.497387 answer 0.000000 end 1423319984.549283 dispo FAILED [2015-02-07 14:39:44] DEBUG[974]: cdr.c:3255 post_cdr: Skipping CDR for PJSIP/2001-0000008d since we weren't answered And here is the log to the successful call : [2015-02-07 14:41:24] DEBUG[3788]: res_pjsip_session.c:263 handle_incoming_sdp: Negotiating incoming SDP media stream 'audio' using audio SDP handler [2015-02-07 14:41:24] DEBUG[3788]: rtp_engine.c:419 ast_rtp_instance_new: Using engine 'asterisk' for RTP instance '0x7f4e30b73b78' [2015-02-07 14:41:24] DEBUG[3788]: res_rtp_asterisk.c:2435 ast_rtp_new: Allocated port 18926 for RTP instance '0x7f4e30b73b78' [2015-02-07 14:41:24] DEBUG[3788]: rtp_engine.c:428 ast_rtp_instance_new: RTP instance '0x7f4e30b73b78' is setup and ready to go [2015-02-07 14:41:24] DEBUG[3788]: res_rtp_asterisk.c:4677 ast_rtp_prop_set: Setup RTCP on RTP instance '0x7f4e30b73b78' [2015-02-07 14:41:24] DEBUG[3788]: rtp_engine.c:648 ast_rtp_codecs_payloads_set_m_type: Setting payload 0 (0x7f4e300b0838) based on m type on 0x7f4e2c0d63d0 [2015-02-07 14:41:24] DEBUG[3788]: rtp_engine.c:648 ast_rtp_codecs_payloads_set_m_type: Setting payload 8 (0x7f4e300b0838) based on m type on 0x7f4e2c0d63d0 [2015-02-07 14:41:24] DEBUG[3788]: rtp_engine.c:648 ast_rtp_codecs_payloads_set_m_type: Setting payload 3 (0x7f4e300b0838) based on m type on 0x7f4e2c0d63d0 [2015-02-07 14:41:24] DEBUG[3788]: rtp_engine.c:648 ast_rtp_codecs_payloads_set_m_type: Setting payload 9 (0x7f4e300b0838) based on m type on 0x7f4e2c0d63d0 [2015-02-07 14:41:24] DEBUG[3788]: rtp_engine.c:648 ast_rtp_codecs_payloads_set_m_type: Setting payload 107 (0x7f4e300b0838) based on m type on 0x7f4e2c0d63d0 [2015-02-07 14:41:24] DEBUG[3788]: rtp_engine.c:648 ast_rtp_codecs_payloads_set_m_type: Setting payload 105 (0x7f4e30004028) based on m type on 0x7f4e2c0d63d0 [2015-02-07 14:41:24] DEBUG[3788]: rtp_engine.c:648 ast_rtp_codecs_payloads_set_m_type: Setting payload 109 (0x7f4e30b7f9a8) based on m type on 0x7f4e2c0d63d0 [2015-02-07 14:41:24] DEBUG[3788]: rtp_engine.c:648 ast_rtp_codecs_payloads_set_m_type: Setting payload 102 (0x7f4e30b7f9a8) based on m type on 0x7f4e2c0d63d0 [2015-02-07 14:41:24] DEBUG[3788]: rtp_engine.c:648 ast_rtp_codecs_payloads_set_m_type: Setting payload 125 (0x7f4e30b7f9a8) based on m type on 0x7f4e2c0d63d0 [2015-02-07 14:41:24] DEBUG[3788]: rtp_engine.c:648 ast_rtp_codecs_payloads_set_m_type: Setting payload 101 (0x7f4e30b7f9a8) based on m type on 0x7f4e2c0d63d0 [2015-02-07 14:41:24] DEBUG[3788]: res_pjsip_session.c:273 handle_incoming_sdp: Media stream 'audio' handled by audio [2015-02-07 14:41:24] DEBUG[13030][C-00000249]: pbx.c:4921 pbx_extension_helper: Launching 'AGI' -- Executing [[email protected]:1] AGI("PJSIP/2003-00000090", "ordercheck.php") in new stack -- Launched AGI Script /var/lib/asterisk/agi-bin/ordercheck.php -- AGI Script ordercheck.php completed, returning 0 [2015-02-07 14:41:24] DEBUG[13030][C-00000249]: pbx.c:4921 pbx_extension_helper: Launching 'GotoIf' -- Executing [[email protected]:2] GotoIf("PJSIP/2003-00000090", "1?end") in new stack -- Goto (from-internal,2001,4) [2015-02-07 14:41:24] DEBUG[13030][C-00000249]: pbx.c:4921 pbx_extension_helper: Launching 'NoOp' -- Executing [[email protected]:4] NoOp("PJSIP/2003-00000090", "") in new stack [2015-02-07 14:41:24] DEBUG[13030][C-00000249]: pbx.c:4921 pbx_extension_helper: Launching 'Gosub' -- Executing [[email protected]:5] Gosub("PJSIP/2003-00000090", "sub-presencestate-display,s,1(2001)") in new stack [2015-02-07 14:41:24] DEBUG[13030][C-00000249]: app_stack.c:606 gosub_exec: Channel PJSIP/2003-00000090 has no datastore, so we're allocating one. [2015-02-07 14:41:24] DEBUG[13030][C-00000249]: app_stack.c:648 gosub_exec: Setting 'ARG1' to '2001' [2015-02-07 14:41:24] DEBUG[13030][C-00000249]: db.c:376 db_get_common: Unable to find key '2001' in family 'CustomPresence' [2015-02-07 14:41:24] WARNING[13030][C-00000249]: func_presencestate.c:133 presence_read: PRESENCE_STATE unknown [2015-02-07 14:41:24] DEBUG[13030][C-00000249]: pbx.c:4921 pbx_extension_helper: Launching 'Goto' -- Executing [[email protected]:1] Goto("PJSIP/2003-00000090", "state-,1") in new stack -- Goto (sub-presencestate-display,state-,1) [2015-02-07 14:41:24] DEBUG[13030][C-00000249]: pbx.c:4921 pbx_extension_helper: Launching 'Set' -- Executing [[email protected]:1] Set("PJSIP/2003-00000090", "PRESENCESTATE_DISPLAY=") in new stack [2015-02-07 14:41:24] DEBUG[13030][C-00000249]: pbx.c:4921 pbx_extension_helper: Launching 'Return' -- Executing [[email protected]:2] Return("PJSIP/2003-00000090", "") in new stack [2015-02-07 14:41:24] DEBUG[13030][C-00000249]: pbx.c:4921 pbx_extension_helper: Launching 'Set' -- Executing [[email protected]:6] Set("PJSIP/2003-00000090", "CONNECTEDLINE(name)=paul") in new stack [2015-02-07 14:41:24] DEBUG[13030][C-00000249]: db.c:376 db_get_common: Unable to find key 'DND2001' in family 'CustomDevstate' [2015-02-07 14:41:24] DEBUG[13030][C-00000249]: pbx.c:4921 pbx_extension_helper: Launching 'Set' -- Executing [[email protected]:7] Set("PJSIP/2003-00000090", "FM_DIALSTATUS=NOT_INUSE") in new stack [2015-02-07 14:41:24] DEBUG[13030][C-00000249]: pbx.c:4921 pbx_extension_helper: Launching 'Set' -- Executing [[email protected]:8] Set("PJSIP/2003-00000090", "__EXTTOCALL=2001") in new stack [2015-02-07 14:41:24] DEBUG[13030][C-00000249]: pbx.c:4921 pbx_extension_helper: Launching 'Set' -- Executing [[email protected]:9] Set("PJSIP/2003-00000090", "__PICKUPMARK=2001") in new stack [2015-02-07 14:41:24] DEBUG[13030][C-00000249]: pbx.c:4921 pbx_extension_helper: Launching 'Macro' -- Executing [[email protected]:10] Macro("PJSIP/2003-00000090", "blkvm-setifempty,") in new stack [2015-02-07 14:41:24] DEBUG[13030][C-00000249]: pbx.c:4825 pbx_substitute_variables_helper_full: Expression result is '1' [2015-02-07 14:41:24] DEBUG[13030][C-00000249]: pbx.c:4921 pbx_extension_helper: Launching 'GotoIf' -- Executing [[email protected]:1] GotoIf("PJSIP/2003-00000090", "1?init") in new stack -- Goto (macro-blkvm-setifempty,s,4) [2015-02-07 14:41:24] DEBUG[13030][C-00000249]: app_macro.c:438 _macro_exec: Executed application: GotoIf [2015-02-07 14:41:24] DEBUG[13030][C-00000249]: pbx.c:4921 pbx_extension_helper: Launching 'Set' -- Executing [[email protected]:4] Set("PJSIP/2003-00000090", "__BLKVM_CHANNEL=PJSIP/2003-00000090") in new stack [2015-02-07 14:41:24] DEBUG[13030][C-00000249]: app_macro.c:438 _macro_exec: Executed application: Set [2015-02-07 14:41:24] DEBUG[13030][C-00000249]: pbx.c:4921 pbx_extension_helper: Launching 'Set' -- Executing [[email protected]:5] Set("PJSIP/2003-00000090", "SHARED(BLKVM,PJSIP/2003-00000090)=TRUE") in new stack [2015-02-07 14:41:24] DEBUG[13030][C-00000249]: app_macro.c:438 _macro_exec: Executed application: Set [2015-02-07 14:41:24] DEBUG[13030][C-00000249]: pbx.c:4921 pbx_extension_helper: Launching 'Set' -- Executing [[email protected]:6] Set("PJSIP/2003-00000090", "GOSUB_RETVAL=TRUE") in new stack [2015-02-07 14:41:24] DEBUG[13030][C-00000249]: app_macro.c:438 _macro_exec: Executed application: Set [2015-02-07 14:41:24] DEBUG[13030][C-00000249]: pbx.c:4921 pbx_extension_helper: Launching 'MacroExit' -- Executing [[email protected]:7] MacroExit("PJSIP/2003-00000090", "") in new stack [2015-02-07 14:41:24] DEBUG[13030][C-00000249]: pbx.c:4825 pbx_substitute_variables_helper_full: Expression result is '1'