AGI Variable DEXTEN not being passed to custom module

Problem: I can’t seem to get the agent name via the variable DEXTEN in my custom module.

I have a custom module which gets the agent name via the following:

(which works on an FreePBX 12/Ast 11/Distro 6 install), but not on SNG7/FreePBX 14 install w/ configs copied using the conversion tool.

(Bare with me, I’m not 100% familiar with all this)

functions.php

/* 	Generates dialplan
	We call this with retrieve_conf
*/
function bsurvey_get_config($engine) {
	dbug("I am here @ get config");
	global $ext;  // is this the best way to pass this?
	global $conferences_conf;
	global $core_conf;
	switch($engine) {
		case "asterisk":
			$surveylist = bsurvey_list(true);
			dbug("I am here @ get config");
			$DYN='';
			if(is_array($surveylist)) {
				foreach($surveylist as $item) {
					$thisitem = bsurvey_get(ltrim($item['id']));
					// add dialplan
					//$ext->add('bsurvey', $item['id'], '', new ext_wait(10));
					$ext->add('bsurvey', $item['id'], '', new ext_set('bsurvey_name',$item['displayname']));
					$ext->add('bsurvey', $item['id'], '', new ext_set('bsurvey_start','${CDR(start)}'));
					$ext->add('bsurvey', $item['id'], '', new ext_set('bsurvey_unqiueid','${CDR(uniqueid)}'));
					$ext->add('bsurvey', $item['id'], '', new ext_set('bsurvey_agent','${DEXTEN}'));
					$ext->add('bsurvey', $item['id'], '', new ext_set('bsurvey_aname_key=/AMPUSER/${DEXTEN}/cidname'));
					$ext->add('bsurvey', $item['id'], '', new ext_set('bsurvey_aname','${DB(${bsurvey_aname_key})}'));
//					$ext->add('bsurvey', $item['id'], '', new extension('Dumpchan'));
					$ext->add('bsurvey', $item['id'], '', new extension('AGI(bsurvey.php)'));

bsurvey.php

$AGI->exec('Set','bsurvey_agent_name=${DB(/AMPUSER/'.$bsurvey_agent.'/cidname)}');
$r=$AGI->database_get('AMPUSER/'.$bsurvey_agent,'cidname');
adebug("This is the bsurvey_agent= $bsurvey_agent");

[root@voip2 agi]# cat /etc/asterisk/extensions | grep bsur*

DYNAMIC_FEATURES = bsurvey1#apprecord
[bsurvey]
include => bsurvey-custom
exten => 1,1,Set(bsurvey_name=support)
exten => 1,n,Set(bsurvey_start=${CDR(start)})
exten => 1,n,Set(bsurvey_unqiueid=${CDR(uniqueid)})
exten => 1,n,Set(bsurvey_agent=${DEXTEN})
exten => 1,n,Set(bsurvey_aname_key=/AMPUSER/${DEXTEN}/cidname=)
exten => 1,n,Set(bsurvey_aname=${DB(${bsurvey_aname_key})})
exten => 1,n,AGI(bsurvey.php)
;--== end of [bsurvey] ==--;
[macro-bsurvey]
include => macro-bsurvey-custom
exten => s,n,ChannelRedirect(${BRIDGEPEER},bsurvey,${ARG1},1)
;--== end of [macro-bsurvey] ==--;
[root@voip2 agi]#

Replace DEXTEN with AMPUSER

@tm1000 Hello again,

I tried replacing it in each of these lines independent, and both together like so:

$ext->add('bsurvey', $item['id'], '', new ext_set('bsurvey_agent','${DEXTEN}'));
$ext->add('bsurvey', $item['id'], '', new ext_set('bsurvey_aname_key=/AMPUSER/${DEXTEN}/cidname'));


$ext->add('bsurvey', $item['id'], '', new ext_set('bsurvey_agent','${AMPUSER}'));
$ext->add('bsurvey', $item['id'], '', new ext_set('bsurvey_aname_key=/AMPUSER/${AMPUSER}/cidname'));

Just to clairfiy, the name I am looking to resolve is the agent whom took the call. All this does it stop the survey from working :(. It skips asking questions, but gets to the end of the survey w/ “Thank you”, but the bsurvey_agent= (blank).

This is a little above me as you can probably guess…, was there a change in FreePBX 14 or is this somehow a configuration issue, possibly something didn’t get carried over w/ the Conversion Tool?

There were several changes to DEXTEN in FreePBX 13 not 14. But you didn’t use 13

Why would using AMPUSER stop your survey from working? Anyways you can see in the dialplan logs what variables are set and decipher from there. Or post the full log here and we can do it for you.

1 Like

@tm1000 Here is an asterisk output from an attempted survey:

You were correct, changing to AMPUSER did not break anything, it was already in a broken state from testing, so I started from scratch, the survey worked, but the same end result, no agent name was stored in DB.

Note:

-- Executing [1@bsurvey:4] Set("Local/847@from-queue-001f9172;2", "bsurvey_agent=847") in new stack
-- Executing [1@bsurvey:5] Set("Local/847@from-queue-001f9172;2", "bsurvey_aname_key=/AMPUSER/847/cidname=") in new stack

The above is not on the FreePBX 14 server.

Here is a working output from the Prod Server:

--  Feature Found: bsurvey1 exten: bsurvey1
-- Executing [s@macro-bsurvey:1] DumpChan("SIP/2041-0001fb1a", "") in new stack

Dumping Info For Channel: SIP/2041-0001fb1a:
================================================================================
Info:
Name=               SIP/2041-0001fb1a
Type=               SIP
UniqueID=           1489802868.4267836
LinkedID=           1489802868.4267779
CallerIDNum=        2041
CallerIDName=       John Smith
ConnectedLineIDNum= 2151234567
ConnectedLineIDName=M0:DG-SAINT ALBANS NY
DNIDDigits=         (N/A)
RDNIS=              (N/A)
Parkinglot=         default
Language=           en
State=              Up (6)
Rings=              0
NativeFormat=       (ulaw)
WriteFormat=        ulaw
ReadFormat=         ulaw
RawWriteFormat=     ulaw
RawReadFormat=      ulaw
WriteTranscode=     No
ReadTranscode=      No
1stFileDescriptor=  31
Framesin=           700
Framesout=          680
TimetoHangup=       0
ElapsedTime=        0h0m16s
DirectBridge=       <none>
IndirectBridge=     <none>
Context=            macro-bsurvey
Extension=          s
Priority=           1
CallGroup=
PickupGroup=
Application=        DumpChan
Data=               (Empty)
Blocking_in=        (Not Blocking)

Variables:
MACRO_DEPTH=1
ARG1=1
MACRO_PRIORITY=1
MACRO_CONTEXT=macro-dial-one
MACRO_EXTEN=s
DYNAMIC_FEATURENAME=bsurvey1
DYNAMIC_PEERNAME=Local/847@from-queue-001f9172;2
BRIDGEPEER=Local/847@from-queue-001f9172;2
GOSUB_RETVAL=
FORWARD_CONTEXT=from-internal
CFIGNORE=
MACRO_RESULT=
DIALEDPEERNUMBER=2041
[email protected]:5060
KEEPCID=TRUE
CWIGNORE=TRUE
SAVEDCIDNAME=DG-SAINT ALBANS NY
REC_STATUS=RECORDING
RECORD_ID=Local/847@from-queue-001f9172;2
MIXMON_ID=0x7fb820805220
CALLFILENAME=external-847-613-20170317-220748-1489802868.4267833
REC_POLICY_MODE=FORCE
MOHCLASS=Classical-Piano
NODEST=613
QUEUEWAIT=1489802868
TTL=64
CALLEE_ACCOUNCODE=
CALLINGPRES_SV=allowed_not_screened
FROM_DID=2674951179
MON_FMT=wav
TIMESTR=20170317-220748
YEAR=2017
MONTH=03
DAY=17
DIRECTION=INBOUND
================================================================================
-- Executing [s@macro-bsurvey:2] ChannelRedirect("SIP/2041-0001fb1a", "Local/847@from-queue-001f9172;2,bsurvey,1,1") in new stack
   > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('HANGUP',{ts '2017-03-17 22:08:04.17720'},'John Smith','2041','2041','','','s','bsurvey','SIP/2041-0001fb1a','AppDial','(Outgoing Line)',3,'','1489802868.4267836','1489802868.4267779','','','')]
   > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('CHAN_END',{ts '2017-03-17 22:08:04.18012'},'John Smith','2041','2041','','','s','bsurvey','SIP/2041-0001fb1a','AppDial','(Outgoing Line)',3,'','1489802868.4267836','1489802868.4267779','','','')]
  == Spawn extension (bsurvey, 1, 1) exited non-zero on 'Local/847@from-queue-001f9172;2' in macro 'dial-one'
  == Spawn extension (bsurvey, 1, 1) exited non-zero on 'Local/847@from-queue-001f9172;2'
-- Executing [1@bsurvey:1] Set("Local/847@from-queue-001f9172;2", "bsurvey_name=support") in new stack
-- Executing [1@bsurvey:2] Set("Local/847@from-queue-001f9172;2", "bsurvey_start=2017-03-17 22:07:48") in new stack
-- Executing [1@bsurvey:3] Set("Local/847@from-queue-001f9172;2", "bsurvey_unqiueid=1489802868.4267833") in new stack
-- Executing [1@bsurvey:4] Set("Local/847@from-queue-001f9172;2", "bsurvey_agent=847") in new stack
-- Executing [1@bsurvey:5] Set("Local/847@from-queue-001f9172;2", "bsurvey_aname_key=/AMPUSER/847/cidname=") in new stack
-- Executing [1@bsurvey:6] Set("Local/847@from-queue-001f9172;2", "bsurvey_aname=") in new stack
-- Executing [1@bsurvey:7] AGI("Local/847@from-queue-001f9172;2", "bsurvey.php") in new stack
-- Launched AGI Script /var/lib/asterisk/agi-bin/bsurvey.php
-- bsurvey.php: Starting New survey
-- AGI Script Executing Application: (Set) Options: (bsurvey_agent_name=${DB(/AMPUSER/847/cidname)})
   > bsurvey.php: Running SQL Command SELECT a.*,b.`displayname` as dp FROM bsurvey as a left join recordings as b on b.id=a.`rec_id` WHERE a.`id` = '1'
   > bsurvey.php: Connected to MySQL database OK.
   > bsurvey.php: Selected database OK.
-- <Local/847@from-queue-001f9172;2> Playing 'Alt_SV_Announce.slin' (escape_digits=1234567890) (sample_offset 0) (language 'en')
   > bsurvey.php: Running SQL Command select `id` from survey.bsurvey_cdrs limit 0
-- bsurvey.php: TABLE CREATED
   > bsurvey.php: Running SQL Command SELECT rec_id,bsurvey_id,b.filename as file,a.displayname,a.res_start,a.res_end FROM bsurvey_recs a left join recordings as b on a.rec_id= b.id where bsurvey_id='1' ORDER BY a.id
-- bsurvey.php: Do questions
-- bsurvey.php: REC Array
-- bsurvey.php: (
-- bsurvey.php:     [rec_id] => 36
-- bsurvey.php:     [bsurvey_id] => 1
-- bsurvey.php:     [file] => custom/Alt_SV_Q1
-- bsurvey.php:     [displayname] => Call Satisfaction
-- bsurvey.php:     [res_start] => 1
-- bsurvey.php:     [res_end] => 5
-- bsurvey.php: )
-- bsurvey.php:
   > bsurvey.php: Running SQL Command insert into survey.bsurvey_cdrs(survey_name,question,res_start ,res_end,rec_file,unqiueid,
   > bsurvey.php:                   calldate,cid,answer,agent,agent_name) values
   > bsurvey.php:   ('support','Call Satisfaction','1','5','custom/Alt_SV_Q1','1489802868.4267833',
   > bsurvey.php:                   '2017-03-17 22:07:48','','','847','John Smith')
   > bsurvey.php: Running SQL Command select id from survey.bsurvey_cdrs where survey_name='support' and  question = 'Call Satisfaction' and  unqiueid='1489802868.4267833' and agent_name = 'John Smith'  limit 1
-- <Local/847@from-queue-001f9172;2> Playing 'custom/Alt_SV_Q1.slin' (language 'en')
   > bsurvey.php: Running SQL Command update survey.bsurvey_cdrs set answer='5' where id=572413
-- bsurvey.php: Do questions
-- bsurvey.php: REC Array
-- bsurvey.php: (
-- bsurvey.php:     [rec_id] => 37
-- bsurvey.php:     [bsurvey_id] => 1
-- bsurvey.php:     [file] => custom/Alt_SV_Q2
-- bsurvey.php:     [displayname] => Production Satisfaction
-- bsurvey.php:     [res_start] => 1
-- bsurvey.php:     [res_end] => 5
-- bsurvey.php: )
-- bsurvey.php:
   > bsurvey.php: Running SQL Command insert into survey.bsurvey_cdrs(survey_name,question,res_start ,res_end,rec_file,unqiueid,
   > bsurvey.php:                   calldate,cid,answer,agent,agent_name) values
   > bsurvey.php:   ('support','Production Satisfaction','1','5','custom/Alt_SV_Q2','1489802868.4267833',
   > bsurvey.php:                   '2017-03-17 22:07:48','','','847','John Smith')
   > bsurvey.php: Running SQL Command select id from survey.bsurvey_cdrs where survey_name='support' and  question = 'Production Satisfaction' and  unqiueid='1489802868.4267833' and agent_name = 'John Smith'  limit 1
-- <Local/847@from-queue-001f9172;2> Playing 'custom/Alt_SV_Q2.slin' (language 'en')
  == Manager 'v3' logged on from 10.1.10.8
  == Manager 'v3' logged off from 10.1.10.8
   > bsurvey.php: Running SQL Command update survey.bsurvey_cdrs set answer='5' where id=572414
-- bsurvey.php: Do questions
-- bsurvey.php: REC
-- <Local/847@from-queue-001f9172;2> Playing 'bsurvey-thanku.slin' (escape_digits=123456789) (sample_offset 0) (language 'en')
-- <Local/847@from-queue-001f9172;2>AGI Script bsurvey.php completed, returning 4
  == Spawn extension (bsurvey, 1, 7) exited non-zero on 'Local/847@from-queue-001f9172;2'
  == MixMonitor close filestream (mixed)
   > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('HANGUP',{ts '2017-03-17 22:08:15.747109'},'M0:DG-SAINT ALBANS NY','2151234567','2151234567','','','1','bsurvey','Local/847@from-queue-001f9172;2','','',3,'','1489802868.4267833','1489802868.4267779','','','')]
-- Executing [h@ext-queues:1] Macro("SIP/Digium_Prod-0001fb19", "hangupcall,") in new stack
   > [INSERT INTO cdr (calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata,duration,billsec,disposition,amaflags,uniqueid,recordingfile) VALUES ({ ts '2017-03-17 22:07:48' },'"M0:DG-SAINT ALBANS NY" <2151234567>','2151234567','1','bsurvey','Local/847@from-queue-001f9172;2','SIP/2041-0001fb1a','AGI','HANGUP',27,25,'ANSWERED',3,'1489802868.4267833','external-847-613-20170317-220748-1489802868.4267833.wav')]
-- Executing [s@macro-hangupcall:1] ExecIf("SIP/Digium_Prod-0001fb19", "0?Set(CDR(recordingfile)=.wav)") in new stack
  == End MixMonitor Recording Local/847@from-queue-001f9172;2
   > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('BRIDGE_END',{ts '2017-03-17 22:08:15.747303'},'DG-SAINT ALBANS NY','2151234567','2151234567','','2674951179','613','ext-queues','SIP/Digium_Prod-0001fb19','Queue','613,t,,custom/Ans_Support1_q,,,,,,',3,'','1489802868.4267779','1489802868.4267779','Local/847@from-queue-001f9172;1','','')]
-- Executing [s@macro-hangupcall:2] GotoIf("SIP/Digium_Prod-0001fb19", "1?theend") in new stack
-- Goto (macro-hangupcall,s,4)
-- Executing [s@macro-hangupcall:4] Hangup("SIP/Digium_Prod-0001fb19", "") in new stack
  == Spawn extension (macro-hangupcall, s, 4) exited non-zero on 'SIP/Digium_Prod-0001fb19' in macro 'hangupcall'
  == Spawn extension (ext-queues, h, 1) exited non-zero on 'SIP/Digium_Prod-0001fb19'
   > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('CHAN_END',{ts '2017-03-17 22:08:15.747913'},'M0:DG-SAINT ALBANS NY','2151234567','2151234567','','','1','bsurvey','Local/847@from-queue-001f9172;2','','',3,'','1489802868.4267833','1489802868.4267779','','','')]
   > [INSERT INTO cdr (calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata,duration,billsec,disposition,amaflags,uniqueid,did,cnum,cnam) VALUES ({ ts '2017-03-17 22:07:48' },'"DG-SAINT ALBANS NY" <2151234567>','2151234567','613','ext-queues','SIP/Digium_Prod-0001fb19','John Smith','Queue','613,t,,custom/Ans_Support1_q,,,,,,',27,27,'ANSWERED',3,'1489802868.4267779','2674951179','2151234567','DG-SAINT ALBANS NY')]
   > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('HANGUP',{ts '2017-03-17 22:08:15.749848'},'','2674951179','','','','613','from-queue','Local/847@from-queue-001f9172;1','AppQueue','(Outgoing Line)',3,'','1489802868.4267832','1489802868.4267779','','','')]
   > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('CHAN_END',{ts '2017-03-17 22:08:15.749887'},'','2674951179','','','','613','from-queue','Local/847@from-queue-001f9172;1','AppQueue','(Outgoing Line)',3,'','1489802868.4267832','1489802868.4267779','','','')]
  == Spawn extension (ext-queues, 613, 41) exited non-zero on 'SIP/Digium_Prod-0001fb19'
   > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('HANGUP',{ts '2017-03-17 22:08:15.751117'},'DG-SAINT ALBANS NY','2151234567','2151234567','','2674951179','613','ext-queues','SIP/Digium_Prod-0001fb19','','',3,'','1489802868.4267779','1489802868.4267779','','','')]
   > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('CHAN_END',{ts '2017-03-17 22:08:15.751394'},'DG-SAINT ALBANS NY','2151234567','2151234567','','2674951179','613','ext-queues','SIP/Digium_Prod-0001fb19','','',3,'','1489802868.4267779','1489802868.4267779','','','')]
   > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('LINKEDID_END',{ts '2017-03-17 22:08:15.751411'},'DG-SAINT ALBANS NY','2151234567','2151234567','','2674951179','613','ext-queues','SIP/Digium_Prod-0001fb19','','',3,'','1489802868.4267779','1489802868.4267779','','','')]
voip1*CLI>
Disconnected from Asterisk server
Asterisk cleanly ending (0).
Executing last minute cleanups
[root@voip1 ~]#

FreePBX 14 w/o changing Code:

voip2*CLI>
    --  Feature Found: bsurvey1 exten: bsurvey1
    -- Executing [s@macro-bsurvey:1] DumpChan("SIP/2041-00000064", "") in new stack

Dumping Info For Channel: SIP/2041-00000064:
================================================================================
Info:
Name=               SIP/2041-00000064
Type=               SIP
UniqueID=           1490131213.3922
LinkedID=           1490131212.3865
CallerIDNum=        2041
CallerIDName=       John Smith
ConnectedLineIDNum= Anonymous
ConnectedLineIDName=M0:TK-Anonymous
DNIDDigits=         (N/A)
RDNIS=              (N/A)
Parkinglot=         default
Language=           en
State=              Up (6)
Rings=              0
NativeFormat=       (ulaw)
WriteFormat=        ulaw
ReadFormat=         ulaw
RawWriteFormat=     ulaw
RawReadFormat=      ulaw
WriteTranscode=     No
ReadTranscode=      No
1stFileDescriptor=  37
Framesin=           224
Framesout=          210
TimetoHangup=       0
ElapsedTime=        0h0m11s
DirectBridge=       <none>
IndirectBridge=     <none>
Context=            macro-bsurvey
Extension=          s
Priority=           1
CallGroup=
PickupGroup=
Application=        DumpChan
Data=               (Empty)
Blocking_in=        (Not Blocking)

Variables:
MACRO_DEPTH=1
ARG1=1
MACRO_PRIORITY=1
MACRO_CONTEXT=macro-dial
MACRO_EXTEN=s
DYNAMIC_FEATURENAME=bsurvey1
DYNAMIC_PEERNAME=Local/847@from-queue-00000774;2
BRIDGEPEER=Local/847@from-queue-00000774;2
SIPADDHEADER03=
SIPADDHEADER02=
SIPADDHEADER01=
SIPADDHEADER04=
GOSUB_RETVAL=
FORWARD_CONTEXT=from-internal
CFIGNORE=
MACRO_RESULT=
sipkey=
SIPHEADERKEYS=
DIALEDPEERNUMBER=2041
[email protected]:5060
CWIGNORE=
KEEPCID=TRUE
SAVEDCIDNAME=TK-Anonymous
REC_STATUS=RECORDING
RECORD_ID=Local/847@from-queue-00000774;2
MIXMON_ID=0x7fa1ec009e50
CALLFILENAME=external-847-613-20170321-172012-1490131213.3919
REC_POLICY_MODE=FORCE
FROMQ=true
MOHCLASS=classical-piano
NODEST=613
QUEUEWAIT=1490131213
TTL=64
CALLEE_ACCOUNCODE=
REALCALLERIDNUM=Anonymous
CALLINGNUMPRES_SV=allowed_not_screened
CALLINGNAMEPRES_SV=allowed_not_screened
REVERSAL_REJECT=FALSE
FROM_DID=2675555555
MON_FMT=wav
TIMESTR=20170321-172012
YEAR=2017
MONTH=03
DAY=21
DIRECTION=INBOUND
================================================================================
    -- Executing [s@macro-bsurvey:2] ChannelRedirect("SIP/2041-00000064", "Local/847@from-queue-00000774;2,bsurvey,1,1") in new stack
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('HANGUP',{ts '2017-03-21 17:20:24.587388'},'John Smith','2041','2041','','','s','bsurvey','SIP/2041-00000064','AppDial','(Outgoing Line)',3,'','1490131213.3922','1490131212.3865','','','')]
  == Spawn extension (bsurvey, 1, 1) exited non-zero on 'Local/847@from-queue-00000774;2' in macro 'dial'
  == Spawn extension (bsurvey, 1, 1) exited non-zero on 'Local/847@from-queue-00000774;2'
    -- Executing [1@bsurvey:1] Set("Local/847@from-queue-00000774;2", "bsurvey_name=support") in new stack
    -- Executing [1@bsurvey:2] Set("Local/847@from-queue-00000774;2", "bsurvey_start=2017-03-21 17:20:13") in new stack
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('CHAN_END',{ts '2017-03-21 17:20:24.588019'},'John Smith','2041','2041','','','s','bsurvey','SIP/2041-00000064','AppDial','(Outgoing Line)',3,'','1490131213.3922','1490131212.3865','','','')]
    -- Executing [1@bsurvey:3] Set("Local/847@from-queue-00000774;2", "bsurvey_unqiueid=1490131213.3919") in new stack
    -- Executing [1@bsurvey:4] Set("Local/847@from-queue-00000774;2", "bsurvey_agent=") in new stack
    -- Executing [1@bsurvey:5] Set("Local/847@from-queue-00000774;2", "bsurvey_aname_key=/AMPUSER//cidname=") in new stack
    -- Executing [1@bsurvey:6] Set("Local/847@from-queue-00000774;2", "bsurvey_aname=") in new stack
    -- Executing [1@bsurvey:7] AGI("Local/847@from-queue-00000774;2", "bsurvey.php") in new stack
    -- Launched AGI Script /var/lib/asterisk/agi-bin/bsurvey.php
    -- bsurvey.php: Starting New survey
    -- AGI Script Executing Application: (Set) Options: (bsurvey_agent_name=${DB(/AMPUSER//cidname)})
       > bsurvey.php: Running SQL Command SELECT a.*,b.`displayname` as dp FROM bsurvey as a left join recordings as b on b.id=a.`rec_id` WHERE a.`id` = '1'
       > bsurvey.php: Connected to MySQL database OK.
       > bsurvey.php: Selected database OK.
[2017-03-21 17:20:24] WARNING[25000][C-00000039]: file.c:701 ast_openstream_full: File Alt_SV_Announce does not exist in any format
       > bsurvey.php: Running SQL Command select `id` from survey.bsurvey_cdrs limit 0
    -- bsurvey.php: TABLE CREATED
       > bsurvey.php: Running SQL Command SELECT rec_id,bsurvey_id,b.filename as file,a.displayname,a.res_start,a.res_end FROM bsurvey_recs a left join recordings as b on a.rec_id= b.id where bsurvey_id='1' ORDER BY a.id
    -- bsurvey.php: Do questions
    -- bsurvey.php: REC Array
    -- bsurvey.php: (
    -- bsurvey.php:     [rec_id] => 65
    -- bsurvey.php:     [bsurvey_id] => 1
    -- bsurvey.php:     [file] => custom/alt_sv_q1
    -- bsurvey.php:     [displayname] => Call Satisfaction
    -- bsurvey.php:     [res_start] => 1
    -- bsurvey.php:     [res_end] => 5
    -- bsurvey.php: )
    -- bsurvey.php:
       > bsurvey.php: Running SQL Command insert into survey.bsurvey_cdrs(survey_name,question,res_start ,res_end,rec_file,unqiueid,
       > bsurvey.php:                   calldate,cid,answer,agent,agent_name) values
       > bsurvey.php:   ('support','Call Satisfaction','1','5','custom/alt_sv_q1','1490131213.3919',
       > bsurvey.php:                   '2017-03-21 17:20:13','','','','')
       > bsurvey.php: Running SQL Command select id from survey.bsurvey_cdrs where survey_name='support' and  question = 'Call Satisfaction' and  unqiueid='1490131213.3919' and agent_name = ''  limit 1
    -- <Local/847@from-queue-00000774;2> Playing 'custom/alt_sv_q1.slin' (language 'en')
       > bsurvey.php: Running SQL Command update survey.bsurvey_cdrs set answer='5' where id=571304
    -- bsurvey.php: Do questions
    -- bsurvey.php: REC Array
    -- bsurvey.php: (
    -- bsurvey.php:     [rec_id] => 66
    -- bsurvey.php:     [bsurvey_id] => 1
    -- bsurvey.php:     [file] => custom/alt_sv_q2
    -- bsurvey.php:     [displayname] => Product Satisfaction
    -- bsurvey.php:     [res_start] => 1
    -- bsurvey.php:     [res_end] => 5
    -- bsurvey.php: )
    -- bsurvey.php:
       > bsurvey.php: Running SQL Command insert into survey.bsurvey_cdrs(survey_name,question,res_start ,res_end,rec_file,unqiueid,
       > bsurvey.php:                   calldate,cid,answer,agent,agent_name) values
       > bsurvey.php:   ('support','Product Satisfaction','1','5','custom/alt_sv_q2','1490131213.3919',
       > bsurvey.php:                   '2017-03-21 17:20:13','','','','')
       > bsurvey.php: Running SQL Command select id from survey.bsurvey_cdrs where survey_name='support' and  question = 'Product Satisfaction' and  unqiueid='1490131213.3919' and agent_name = ''  limit 1
    -- <Local/847@from-queue-00000774;2> Playing 'custom/alt_sv_q2.slin' (language 'en')
       > bsurvey.php: Running SQL Command update survey.bsurvey_cdrs set answer='5' where id=571305
    -- bsurvey.php: Do questions
    -- bsurvey.php: REC
    -- <Local/847@from-queue-00000774;2> Playing 'bsurvey-thanku.slin' (escape_digits=123456789) (sample_offset 0) (language 'en')
    -- <Local/847@from-queue-00000774;2>AGI Script bsurvey.php completed, returning -1
    -- Executing [h@ext-queues:1] Macro("SIP/Digium_Test-00000063", "hangupcall,") in new stack
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('HANGUP',{ts '2017-03-21 17:20:35.766299'},'M0:TK-Anonymous','Anonymous','Anonymous','','','1','bsurvey','Local/847@from-queue-00000774;2','','',3,'','1490131213.3919','1490131212.3865','','','')]
    -- Executing [s@macro-hangupcall:1] ExecIf("SIP/Digium_Test-00000063", "0?Set(CDR(recordingfile)=.wav)") in new stack
    -- Executing [s@macro-hangupcall:2] GotoIf("SIP/Digium_Test-00000063", "1?theend") in new stack
    -- Goto (macro-hangupcall,s,4)
    -- Executing [s@macro-hangupcall:4] ExecIf("SIP/Digium_Test-00000063", "0?Set(CDR(recordingfile)=)") in new stack
    -- Executing [s@macro-hangupcall:5] Hangup("SIP/Digium_Test-00000063", "") in new stack
  == Spawn extension (macro-hangupcall, s, 5) exited non-zero on 'SIP/Digium_Test-00000063' in macro 'hangupcall'
  == Spawn extension (ext-queues, h, 1) exited non-zero on 'SIP/Digium_Test-00000063'
       > [INSERT INTO cdr (calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata,duration,billsec,disposition,amaflags,uniqueid,recordingfile) VALUES ({ ts '2017-03-21 17:20:13' },'"M0:TK-Anonymous" <Anonymous>','Anonymous','847','from-queue-exten-only','Local/847@from-queue-00000774;2','SIP/2041-00000064','AGI','HANGUP',22,15,'ANSWERED',3,'1490131213.3919','external-847-613-20170321-172012-1490131213.3919.wav')]
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('BRIDGE_END',{ts '2017-03-21 17:20:35.766469'},'TK-Anonymous','Anonymous','Anonymous','','2675555555','613','ext-queues','SIP/Digium_Test-00000063','Queue','613,t,,,,,,,,',3,'','1490131212.3865','1490131212.3865','Local/847@from-queue-00000774;1','','')]
  == MixMonitor close filestream (mixed)
  == End MixMonitor Recording Local/847@from-queue-00000774;2
       > [INSERT INTO cdr (calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata,duration,billsec,disposition,amaflags,uniqueid,did,cnum,cnam) VALUES ({ ts '2017-03-21 17:20:12' },'"TK-Anonymous" <Anonymous>','Anonymous','613','ext-queues','SIP/Digium_Test-00000063','Local/847@from-queue-00000774;1','Queue','613,t,,,,,,,,',23,23,'ANSWERED',3,'1490131212.3865','2675555555','Anonymous','TK-Anonymous')]
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('CHAN_END',{ts '2017-03-21 17:20:35.771676'},'M0:TK-Anonymous','Anonymous','Anonymous','','','1','bsurvey','Local/847@from-queue-00000774;2','','',3,'','1490131213.3919','1490131212.3865','','','')]
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('HANGUP',{ts '2017-03-21 17:20:35.773284'},'John Smith','2041','','','','613','from-queue','Local/847@from-queue-00000774;1','AppQueue','(Outgoing Line)',3,'','1490131213.3918','1490131212.3865','','','')]
  == Spawn extension (ext-queues, 613, 41) exited non-zero on 'SIP/Digium_Test-00000063'
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('CHAN_END',{ts '2017-03-21 17:20:35.773345'},'John Smith','2041','','','','613','from-queue','Local/847@from-queue-00000774;1','AppQueue','(Outgoing Line)',3,'','1490131213.3918','1490131212.3865','','','')]
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('APP_END',{ts '2017-03-21 17:20:35.774492'},'TK-Anonymous','Anonymous','Anonymous','','2675555555','613','ext-queues','SIP/Digium_Test-00000063','Queue','613,t,,,,,,,,',3,'','1490131212.3865','1490131212.3865','','','')]
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('HANGUP',{ts '2017-03-21 17:20:35.774608'},'TK-Anonymous','Anonymous','Anonymous','','2675555555','613','ext-queues','SIP/Digium_Test-00000063','','',3,'','1490131212.3865','1490131212.3865','','','')]
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('CHAN_END',{ts '2017-03-21 17:20:35.775133'},'TK-Anonymous','Anonymous','Anonymous','','2675555555','613','ext-queues','SIP/Digium_Test-00000063','','',3,'','1490131212.3865','1490131212.3865','','','')]
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('LINKEDID_END',{ts '2017-03-21 17:20:35.775157'},'TK-Anonymous','Anonymous','Anonymous','','2675555555','613','ext-queues','SIP/Digium_Test-00000063','','',3,'','1490131212.3865','1490131212.3865','','','')]
voip2*CLI>
Disconnected from Asterisk server
Asterisk cleanly ending (0).
Executing last minute cleanups
[root@voip2 ~]#

FreePBX 14 w/ AMPUSER like above:

voip2*CLI>
    --  Feature Found: bsurvey1 exten: bsurvey1
    -- Executing [s@macro-bsurvey:1] DumpChan("Local/847@from-queue-00000790;1", "") in new stack

Dumping Info For Channel: Local/847@from-queue-00000790;1:
================================================================================
Info:
Name=               Local/847@from-queue-00000790;1
Type=               Local
UniqueID=           1490131327.3976
LinkedID=           1490131326.3923
CallerIDNum=        2041
CallerIDName=       John Smith
ConnectedLineIDNum= Anonymous
ConnectedLineIDName=TK-Anonymous
DNIDDigits=         (N/A)
RDNIS=              (N/A)
Parkinglot=
Language=           en
State=              Up (6)
Rings=              0
NativeFormat=       (ulaw)
WriteFormat=        ulaw
ReadFormat=         ulaw
RawWriteFormat=     ulaw
RawReadFormat=      ulaw
WriteTranscode=     No
ReadTranscode=      No
1stFileDescriptor=  -1
Framesin=           540
Framesout=          526
TimetoHangup=       0
ElapsedTime=        0h0m14s
DirectBridge=       <none>
IndirectBridge=     <none>
Context=            macro-bsurvey
Extension=          s
Priority=           1
CallGroup=
PickupGroup=
Application=        DumpChan
Data=               (Empty)
Blocking_in=        (Not Blocking)

Variables:
MACRO_DEPTH=1
ARG1=1
MACRO_PRIORITY=1
MACRO_CONTEXT=from-queue
MACRO_EXTEN=613
DYNAMIC_FEATURENAME=bsurvey1
DYNAMIC_PEERNAME=SIP/Digium_Test-00000065
[email protected]
BRIDGEPEER=SIP/Digium_Test-00000065
SIPADDHEADER01=
SIPADDHEADER02=
SIPADDHEADER03=
SIPADDHEADER04=
MEMBERREALTIME=0
MEMBERDYNAMIC=1
MEMBERPENALTY=0
MEMBERLASTCALL=1490131235
MEMBERCALLS=27
MEMBERNAME=John Smith
MEMBERINTERFACE=Local/847@from-queue/n
MOHCLASS=classical-piano
FORWARD_CONTEXT=block-cf
CFIGNORE=TRUE
CWIGNORE=TRUE
REC_POLICY_MODE=NO
NODEST=613
QUEUEWAIT=1490131327
TTL=64
CALLEE_ACCOUNCODE=
REALCALLERIDNUM=Anonymous
CALLINGNUMPRES_SV=allowed_not_screened
CALLINGNAMEPRES_SV=allowed_not_screened
REVERSAL_REJECT=FALSE
FROM_DID=2675555555
MON_FMT=wav
TIMESTR=20170321-172206
YEAR=2017
MONTH=03
DAY=21
REC_STATUS=INITIALIZED
DIRECTION=INBOUND
================================================================================
    -- Executing [s@macro-bsurvey:2] ChannelRedirect("Local/847@from-queue-00000790;1", "SIP/Digium_Test-00000065,bsurvey,1,1") in new stack
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('HANGUP',{ts '2017-03-21 17:22:21.36848'},'John Smith','2041','','','','613','from-queue','Local/847@from-queue-00000790;1','AppQueue','(Outgoing Line)',3,'','1490131327.3976','1490131326.3923','','','')]
  == Spawn extension (bsurvey, 1, 1) exited non-zero on 'SIP/Digium_Test-00000065'
    -- Executing [1@bsurvey:1] Set("SIP/Digium_Test-00000065", "bsurvey_name=support") in new stack
    -- Executing [1@bsurvey:2] Set("SIP/Digium_Test-00000065", "bsurvey_start=2017-03-21 17:22:06") in new stack
    -- Executing [h@macro-dial:1] Macro("Local/847@from-queue-00000790;2", "hangupcall,") in new stack
    -- Executing [1@bsurvey:3] Set("SIP/Digium_Test-00000065", "bsurvey_unqiueid=1490131326.3923") in new stack
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('CHAN_END',{ts '2017-03-21 17:22:21.37218'},'John Smith','2041','','','','613','from-queue','Local/847@from-queue-00000790;1','AppQueue','(Outgoing Line)',3,'','1490131327.3976','1490131326.3923','','','')]
    -- Executing [1@bsurvey:4] Set("SIP/Digium_Test-00000065", "bsurvey_agent=") in new stack
    -- Executing [1@bsurvey:5] Set("SIP/Digium_Test-00000065", "bsurvey_aname_key=/AMPUSER//cidname=") in new stack
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('BRIDGE_END',{ts '2017-03-21 17:22:21.37458'},'M0:TK-Anonymous','Anonymous','Anonymous','','','s','macro-dial','Local/847@from-queue-00000790;2','Dial','SIP/2041,,trM(auto-blkvm)b(func-apply-sipheaders^s^1),',3,'','1490131327.3977','1490131326.3923','SIP/2041-00000066','','')]
    -- Executing [1@bsurvey:6] Set("SIP/Digium_Test-00000065", "bsurvey_aname=") in new stack
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('APP_END',{ts '2017-03-21 17:22:21.38407'},'TK-Anonymous','Anonymous','Anonymous','','2675555555','1','bsurvey','SIP/Digium_Test-00000065','Queue','613,t,,,,,,,,',3,'','1490131326.3923','1490131326.3923','','','')]
    -- Executing [1@bsurvey:7] AGI("SIP/Digium_Test-00000065", "bsurvey.php") in new stack
    -- Executing [s@macro-hangupcall:1] ExecIf("Local/847@from-queue-00000790;2", "0?Set(CDR(recordingfile)=external-847-613-20170321-172206-1490131327.3977.wav)") in new stack
    -- Launched AGI Script /var/lib/asterisk/agi-bin/bsurvey.php
    -- Executing [s@macro-hangupcall:2] GotoIf("Local/847@from-queue-00000790;2", "1?theend") in new stack
    -- Goto (macro-hangupcall,s,4)
    -- Executing [s@macro-hangupcall:4] ExecIf("Local/847@from-queue-00000790;2", "0?Set(CDR(recordingfile)=)") in new stack
    -- Executing [s@macro-hangupcall:5] Hangup("Local/847@from-queue-00000790;2", "") in new stack
  == Spawn extension (macro-hangupcall, s, 5) exited non-zero on 'Local/847@from-queue-00000790;2' in macro 'hangupcall'
  == Spawn extension (macro-dial, h, 1) exited non-zero on 'Local/847@from-queue-00000790;2'
       > [INSERT INTO cdr (calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata,duration,billsec,disposition,amaflags,uniqueid,recordingfile) VALUES ({ ts '2017-03-21 17:22:07' },'"M0:TK-Anonymous" <Anonymous>','Anonymous','847','from-queue-exten-only','Local/847@from-queue-00000790;2','SIP/2041-00000066','Dial','SIP/2041,,trM(auto-blkvm)b(func-apply-sipheaders^s^1),',14,11,'ANSWERED',3,'1490131327.3977','external-847-613-20170321-172206-1490131327.3977.wav')]
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('HANGUP',{ts '2017-03-21 17:22:21.52702'},'John Smith','2041','2041','','','s','macro-dial','SIP/2041-00000066','AppDial','(Outgoing Line)',3,'','1490131327.3980','1490131326.3923','','','')]
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('CHAN_END',{ts '2017-03-21 17:22:21.53286'},'John Smith','2041','2041','','','s','macro-dial','SIP/2041-00000066','AppDial','(Outgoing Line)',3,'','1490131327.3980','1490131326.3923','','','')]
  == Spawn extension (macro-dial, s, 19) exited non-zero on 'Local/847@from-queue-00000790;2' in macro 'dial'
  == Spawn extension (from-queue-exten-only, 847, 7) exited non-zero on 'Local/847@from-queue-00000790;2'
  == MixMonitor close filestream (mixed)
  == End MixMonitor Recording Local/847@from-queue-00000790;2
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('HANGUP',{ts '2017-03-21 17:22:21.55324'},'M0:TK-Anonymous','Anonymous','Anonymous','','','847','from-queue-exten-only','Local/847@from-queue-00000790;2','','',3,'','1490131327.3977','1490131326.3923','','','')]
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('CHAN_END',{ts '2017-03-21 17:22:21.55410'},'M0:TK-Anonymous','Anonymous','Anonymous','','','847','from-queue-exten-only','Local/847@from-queue-00000790;2','','',3,'','1490131327.3977','1490131326.3923','','','')]
    -- bsurvey.php: Starting New survey
    -- AGI Script Executing Application: (Set) Options: (bsurvey_agent_name=${DB(/AMPUSER//cidname)})
       > bsurvey.php: Running SQL Command SELECT a.*,b.`displayname` as dp FROM bsurvey as a left join recordings as b on b.id=a.`rec_id` WHERE a.`id` = '1'
       > bsurvey.php: Connected to MySQL database OK.
       > bsurvey.php: Selected database OK.
[2017-03-21 17:22:21] WARNING[26164][C-0000003a]: file.c:701 ast_openstream_full: File Alt_SV_Announce does not exist in any format
       > bsurvey.php: Running SQL Command select `id` from survey.bsurvey_cdrs limit 0
    -- bsurvey.php: TABLE CREATED
       > bsurvey.php: Running SQL Command SELECT rec_id,bsurvey_id,b.filename as file,a.displayname,a.res_start,a.res_end FROM bsurvey_recs a left join recordings as b on a.rec_id= b.id where bsurvey_id='1' ORDER BY a.id
    -- bsurvey.php: Do questions
    -- bsurvey.php: REC Array
    -- bsurvey.php: (
    -- bsurvey.php:     [rec_id] => 65
    -- bsurvey.php:     [bsurvey_id] => 1
    -- bsurvey.php:     [file] => custom/alt_sv_q1
    -- bsurvey.php:     [displayname] => Call Satisfaction
    -- bsurvey.php:     [res_start] => 1
    -- bsurvey.php:     [res_end] => 5
    -- bsurvey.php: )
    -- bsurvey.php:
       > bsurvey.php: Running SQL Command insert into survey.bsurvey_cdrs(survey_name,question,res_start ,res_end,rec_file,unqiueid,
       > bsurvey.php:                   calldate,cid,answer,agent,agent_name) values
       > bsurvey.php:   ('support','Call Satisfaction','1','5','custom/alt_sv_q1','1490131326.3923',
       > bsurvey.php:                   '2017-03-21 17:22:06','','','','')
       > bsurvey.php: Running SQL Command select id from survey.bsurvey_cdrs where survey_name='support' and  question = 'Call Satisfaction' and  unqiueid='1490131326.3923' and agent_name = ''  limit 1
    -- <SIP/Digium_Test-00000065> Playing 'custom/alt_sv_q1.slin' (language 'en')
       > bsurvey.php: Running SQL Command update survey.bsurvey_cdrs set answer='5' where id=571306
    -- bsurvey.php: Do questions
    -- bsurvey.php: REC Array
    -- bsurvey.php: (
    -- bsurvey.php:     [rec_id] => 66
    -- bsurvey.php:     [bsurvey_id] => 1
    -- bsurvey.php:     [file] => custom/alt_sv_q2
    -- bsurvey.php:     [displayname] => Product Satisfaction
    -- bsurvey.php:     [res_start] => 1
    -- bsurvey.php:     [res_end] => 5
    -- bsurvey.php: )
    -- bsurvey.php:
       > bsurvey.php: Running SQL Command insert into survey.bsurvey_cdrs(survey_name,question,res_start ,res_end,rec_file,unqiueid,
       > bsurvey.php:                   calldate,cid,answer,agent,agent_name) values
       > bsurvey.php:   ('support','Product Satisfaction','1','5','custom/alt_sv_q2','1490131326.3923',
       > bsurvey.php:                   '2017-03-21 17:22:06','','','','')
       > bsurvey.php: Running SQL Command select id from survey.bsurvey_cdrs where survey_name='support' and  question = 'Product Satisfaction' and  unqiueid='1490131326.3923' and agent_name = ''  limit 1
    -- <SIP/Digium_Test-00000065> Playing 'custom/alt_sv_q2.slin' (language 'en')
       > bsurvey.php: Running SQL Command update survey.bsurvey_cdrs set answer='5' where id=571307
    -- bsurvey.php: Do questions
    -- bsurvey.php: REC
    -- <SIP/Digium_Test-00000065> Playing 'bsurvey-thanku.slin' (escape_digits=123456789) (sample_offset 0) (language 'en')
    -- <SIP/Digium_Test-00000065>AGI Script bsurvey.php completed, returning -1
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('HANGUP',{ts '2017-03-21 17:22:33.860202'},'TK-Anonymous','Anonymous','Anonymous','','2675555555','1','bsurvey','SIP/Digium_Test-00000065','','',3,'','1490131326.3923','1490131326.3923','','','')]
       > [INSERT INTO cdr (calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata,duration,billsec,disposition,amaflags,uniqueid,did,cnum,cnam) VALUES ({ ts '2017-03-21 17:22:06' },'"TK-Anonymous" <Anonymous>','Anonymous','613','ext-queues','SIP/Digium_Test-00000065','Local/847@from-queue-00000790;1','AGI','HANGUP',27,27,'ANSWERED',3,'1490131326.3923','2675555555','Anonymous','TK-Anonymous')]
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('CHAN_END',{ts '2017-03-21 17:22:33.865824'},'TK-Anonymous','Anonymous','Anonymous','','2675555555','1','bsurvey','SIP/Digium_Test-00000065','','',3,'','1490131326.3923','1490131326.3923','','','')]
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('LINKEDID_END',{ts '2017-03-21 17:22:33.865868'},'TK-Anonymous','Anonymous','Anonymous','','2675555555','1','bsurvey','SIP/Digium_Test-00000065','','',3,'','1490131326.3923','1490131326.3923','','','')]
voip2*CLI>
Disconnected from Asterisk server
Asterisk cleanly ending (0).
Executing last minute cleanups
[root@voip2 ~]#

This is totally broken. Did you not notice this? What are you trying to do here exactly? Get the cidname from the Asterisk DB?

Because not even this will work:

@tm1000 Sorry if I haven’t been clear.

This is a post phone call survey module. On our production system, w/ the FreePBX 12 etc everything works as expected, when I tried the same module on FreePBX 14, the survey saves everything but the agent name, it plays the recordings and saves the input, but can’t seem to get the variable 'bsurvey_agent= '.

The “working” code, was taking as an example of the output from our production system, the other 2 logs are non-working versions. One using /AMPUSER/${DEXTEN}/ and the other using /AMPUSER/${AMPUSER}/

Does that clear it up?

But why are you sending the key that way? Did you know you can query the Asterisk Database right in the dialplan?

Sorry I can’t make sense of your work. I have no idea where bsurvey is getting inserted. I don’t think anyone could really without you posting the full dialplan.

Then you tell me this:

But then this next thing… if you just changed AMPUSER then you also changed a whole lot more and arent telling me because now you are in a local channel. In the example above you aren’t in a local channel.

Seriously it’s like you are changing more than I am asking here (as if your inserted survey changed splice locations) and it’s getting really frustrating.

1 Like

@tm1000 I will be totally honest, I’m still learning everything there is about FreePBX and Asterisk. I haven’t created custom dialplans on the CLI yet. This module was created by somebody else whom I no longer have contact with.

Why indeed is a good question…

I see what you are describing w/ Local vs SIP, I will start 100% fresh and confirm if that happens with only changing DEXTEN to AMPUSER.

I’m assuming you want this code in functions.php:

$ext->add('bsurvey', $item['id'], '', new ext_set('bsurvey_agent','${AMPUSER}'));
$ext->add('bsurvey', $item['id'], '', new ext_set('bsurvey_aname_key=/AMPUSER/${AMPUSER}/cidname'));

Much as I would like to help, what the F is your " post phone call survey module." and where did it come from? does it work (apparently not )and what do you expect it to do?

In your first two examples you are NOT in a local channel. Then you tell me you only changed AMPUSER and suddenly you are in a local channel. I dont know how that is?

1 Like

The problem is as soon as a call goes through a queue (which is where you’re having the problem), everything changes. You need to keep everything the same.

1 Like

Looking at this more. Each example is in a different context.

Talking with @xrobau about this more. Why don’t you just post this module to github

3 Likes

@tm1000 I will post it on github, I’ve never posted on GIT, so it’ll take a minute to figure it out, but I have an acct.

Here is the output w/ AMPUSER:

w/ AMPUSER

voip2*CLI>
    --  Feature Found: bsurvey1 exten: bsurvey1
    -- Executing [s@macro-bsurvey:1] DumpChan("SIP/2041-00000074", "") in new stack

Dumping Info For Channel: SIP/2041-00000074:
================================================================================
Info:
Name=               SIP/2041-00000074
Type=               SIP
UniqueID=           1490137814.6962
LinkedID=           1490137813.6905
CallerIDNum=        2041
CallerIDName=       John Smith
ConnectedLineIDNum= +12155555555
ConnectedLineIDName=M0:TK-SAINT ALBANS NY
DNIDDigits=         (N/A)
RDNIS=              (N/A)
Parkinglot=         default
Language=           en
State=              Up (6)
Rings=              0
NativeFormat=       (ulaw)
WriteFormat=        ulaw
ReadFormat=         ulaw
RawWriteFormat=     ulaw
RawReadFormat=      ulaw
WriteTranscode=     No
ReadTranscode=      No
1stFileDescriptor=  42
Framesin=           413
Framesout=          399
TimetoHangup=       0
ElapsedTime=        0h0m15s
DirectBridge=       <none>
IndirectBridge=     <none>
Context=            macro-bsurvey
Extension=          s
Priority=           1
CallGroup=
PickupGroup=
Application=        DumpChan
Data=               (Empty)
Blocking_in=        (Not Blocking)

Variables:
MACRO_DEPTH=1
ARG1=1
MACRO_PRIORITY=1
MACRO_CONTEXT=macro-dial
MACRO_EXTEN=s
DYNAMIC_FEATURENAME=bsurvey1
DYNAMIC_PEERNAME=Local/847@from-queue-00000d5c;2
BRIDGEPEER=Local/847@from-queue-00000d5c;2
SIPADDHEADER03=
SIPADDHEADER02=
SIPADDHEADER01=
SIPADDHEADER04=
GOSUB_RETVAL=
FORWARD_CONTEXT=from-internal
CFIGNORE=
MACRO_RESULT=
sipkey=
SIPHEADERKEYS=
DIALEDPEERNUMBER=2041
[email protected]:5060
CWIGNORE=
KEEPCID=TRUE
SAVEDCIDNAME=TK-SAINT ALBANS NY
REC_STATUS=RECORDING
RECORD_ID=Local/847@from-queue-00000d5c;2
MIXMON_ID=0x7fa244000aa0
CALLFILENAME=external-847-613-20170321-191013-1490137814.6959
REC_POLICY_MODE=FORCE
FROMQ=true
MOHCLASS=classical-piano
NODEST=613
QUEUEWAIT=1490137814
TTL=64
CALLEE_ACCOUNCODE=
REALCALLERIDNUM=+12155555555
CALLINGNUMPRES_SV=allowed_not_screened
CALLINGNAMEPRES_SV=allowed_not_screened
REVERSAL_REJECT=FALSE
FROM_DID=2675555555
MON_FMT=wav
TIMESTR=20170321-191013
YEAR=2017
MONTH=03
DAY=21
DIRECTION=INBOUND
================================================================================
    -- Executing [s@macro-bsurvey:2] ChannelRedirect("SIP/2041-00000074", "Local/847@from-queue-00000d5c;2,bsurvey,1,1") in new stack
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('HANGUP',{ts '2017-03-21 19:10:29.80419'},'John Smith','2041','2041','','','s','bsurvey','SIP/2041-00000074','AppDial','(Outgoing Line)',3,'','1490137814.6962','1490137813.6905','','','')]
  == Spawn extension (bsurvey, 1, 1) exited non-zero on 'Local/847@from-queue-00000d5c;2' in macro 'dial'
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('CHAN_END',{ts '2017-03-21 19:10:29.81394'},'John Smith','2041','2041','','','s','bsurvey','SIP/2041-00000074','AppDial','(Outgoing Line)',3,'','1490137814.6962','1490137813.6905','','','')]
  == Spawn extension (bsurvey, 1, 1) exited non-zero on 'Local/847@from-queue-00000d5c;2'
    -- Executing [1@bsurvey:1] Set("Local/847@from-queue-00000d5c;2", "bsurvey_name=support") in new stack
    -- Executing [1@bsurvey:2] Set("Local/847@from-queue-00000d5c;2", "bsurvey_start=2017-03-21 19:10:14") in new stack
    -- Executing [1@bsurvey:3] Set("Local/847@from-queue-00000d5c;2", "bsurvey_unqiueid=1490137814.6959") in new stack
    -- Executing [1@bsurvey:4] Set("Local/847@from-queue-00000d5c;2", "bsurvey_agent=") in new stack
    -- Executing [1@bsurvey:5] Set("Local/847@from-queue-00000d5c;2", "bsurvey_aname_key=/AMPUSER//cidname=") in new stack
    -- Executing [1@bsurvey:6] Set("Local/847@from-queue-00000d5c;2", "bsurvey_aname=") in new stack
    -- Executing [1@bsurvey:7] AGI("Local/847@from-queue-00000d5c;2", "bsurvey.php") in new stack
    -- Launched AGI Script /var/lib/asterisk/agi-bin/bsurvey.php
    -- bsurvey.php: Starting New survey
    -- AGI Script Executing Application: (Set) Options: (bsurvey_agent_name=${DB(/AMPUSER//cidname)})
       > bsurvey.php: Running SQL Command SELECT a.*,b.`displayname` as dp FROM bsurvey as a left join recordings as b on b.id=a.`rec_id` WHERE a.`id` = '1'
       > bsurvey.php: Connected to MySQL database OK.
       > bsurvey.php: Selected database OK.
[2017-03-21 19:10:29] WARNING[12544][C-0000003d]: file.c:701 ast_openstream_full: File Alt_SV_Announce does not exist in any format
       > bsurvey.php: Running SQL Command select `id` from survey.bsurvey_cdrs limit 0
    -- bsurvey.php: TABLE CREATED
       > bsurvey.php: Running SQL Command SELECT rec_id,bsurvey_id,b.filename as file,a.displayname,a.res_start,a.res_end FROM bsurvey_recs a left join recordings as b on a.rec_id= b.id where bsurvey_id='1' ORDER BY a.id
    -- bsurvey.php: Do questions
    -- bsurvey.php: REC Array
    -- bsurvey.php: (
    -- bsurvey.php:     [rec_id] => 65
    -- bsurvey.php:     [bsurvey_id] => 1
    -- bsurvey.php:     [file] => custom/alt_sv_q1
    -- bsurvey.php:     [displayname] => Call Satisfaction
    -- bsurvey.php:     [res_start] => 1
    -- bsurvey.php:     [res_end] => 5
    -- bsurvey.php: )
    -- bsurvey.php:
       > bsurvey.php: Running SQL Command insert into survey.bsurvey_cdrs(survey_name,question,res_start ,res_end,rec_file,unqiueid,
       > bsurvey.php:                   calldate,cid,answer,agent,agent_name) values
       > bsurvey.php:   ('support','Call Satisfaction','1','5','custom/alt_sv_q1','1490137814.6959',
       > bsurvey.php:                   '2017-03-21 19:10:14','','','','')
       > bsurvey.php: Running SQL Command select id from survey.bsurvey_cdrs where survey_name='support' and  question = 'Call Satisfaction' and  unqiueid='1490137814.6959' and agent_name = ''  limit 1
    -- <Local/847@from-queue-00000d5c;2> Playing 'custom/alt_sv_q1.slin' (language 'en')
       > bsurvey.php: Running SQL Command update survey.bsurvey_cdrs set answer='5' where id=571310
    -- bsurvey.php: Do questions
    -- bsurvey.php: REC Array
    -- bsurvey.php: (
    -- bsurvey.php:     [rec_id] => 66
    -- bsurvey.php:     [bsurvey_id] => 1
    -- bsurvey.php:     [file] => custom/alt_sv_q2
    -- bsurvey.php:     [displayname] => Product Satisfaction
    -- bsurvey.php:     [res_start] => 1
    -- bsurvey.php:     [res_end] => 5
    -- bsurvey.php: )
    -- bsurvey.php:
       > bsurvey.php: Running SQL Command insert into survey.bsurvey_cdrs(survey_name,question,res_start ,res_end,rec_file,unqiueid,
       > bsurvey.php:                   calldate,cid,answer,agent,agent_name) values
       > bsurvey.php:   ('support','Product Satisfaction','1','5','custom/alt_sv_q2','1490137814.6959',
       > bsurvey.php:                   '2017-03-21 19:10:14','','','','')
       > bsurvey.php: Running SQL Command select id from survey.bsurvey_cdrs where survey_name='support' and  question = 'Product Satisfaction' and  unqiueid='1490137814.6959' and agent_name = ''  limit 1
    -- <Local/847@from-queue-00000d5c;2> Playing 'custom/alt_sv_q2.slin' (language 'en')
       > bsurvey.php: Running SQL Command update survey.bsurvey_cdrs set answer='5' where id=571311
    -- bsurvey.php: Do questions
    -- bsurvey.php: REC
    -- <Local/847@from-queue-00000d5c;2> Playing 'bsurvey-thanku.slin' (escape_digits=123456789) (sample_offset 0) (language 'en')
    -- <Local/847@from-queue-00000d5c;2>AGI Script bsurvey.php completed, returning -1
  == MixMonitor close filestream (mixed)
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('HANGUP',{ts '2017-03-21 19:10:38.193612'},'M0:TK-SAINT ALBANS NY','+12155555555','+12155555555','','','1','bsurvey','Local/847@from-queue-00000d5c;2','','',3,'','1490137814.6959','1490137813.6905','','','')]
    -- Executing [h@ext-queues:1] Macro("SIP/Digium_Test-00000073", "hangupcall,") in new stack
       > [INSERT INTO cdr (calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata,duration,billsec,disposition,amaflags,uniqueid,recordingfile) VALUES ({ ts '2017-03-21 19:10:14' },'"M0:TK-SAINT ALBANS NY" <+12155555555>','+12155555555','847','from-queue-exten-only','Local/847@from-queue-00000d5c;2','SIP/2041-00000074','AGI','HANGUP',24,17,'ANSWERED',3,'1490137814.6959','external-847-613-20170321-191013-1490137814.6959.wav')]
    -- Executing [s@macro-hangupcall:1] ExecIf("SIP/Digium_Test-00000073", "0?Set(CDR(recordingfile)=.wav)") in new stack
    -- Executing [s@macro-hangupcall:2] GotoIf("SIP/Digium_Test-00000073", "1?theend") in new stack
    -- Goto (macro-hangupcall,s,4)
    -- Executing [s@macro-hangupcall:4] ExecIf("SIP/Digium_Test-00000073", "0?Set(CDR(recordingfile)=)") in new stack
    -- Executing [s@macro-hangupcall:5] Hangup("SIP/Digium_Test-00000073", "") in new stack
  == Spawn extension (macro-hangupcall, s, 5) exited non-zero on 'SIP/Digium_Test-00000073' in macro 'hangupcall'
  == Spawn extension (ext-queues, h, 1) exited non-zero on 'SIP/Digium_Test-00000073'
  == End MixMonitor Recording Local/847@from-queue-00000d5c;2
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('BRIDGE_END',{ts '2017-03-21 19:10:38.193942'},'TK-SAINT ALBANS NY','+12155555555','+12155555555','','2675555555','613','ext-queues','SIP/Digium_Test-00000073','Queue','613,t,,,,,,,,',3,'','1490137813.6905','1490137813.6905','Local/847@from-queue-00000d5c;1','','')]
       > [INSERT INTO cdr (calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata,duration,billsec,disposition,amaflags,uniqueid,did,cnum,cnam) VALUES ({ ts '2017-03-21 19:10:13' },'"TK-SAINT ALBANS NY" <+12155555555>','+12155555555','613','ext-queues','SIP/Digium_Test-00000073','Local/847@from-queue-00000d5c;1','Queue','613,t,,,,,,,,',25,25,'ANSWERED',3,'1490137813.6905','2675555555','+12155555555','TK-SAINT ALBANS NY')]
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('CHAN_END',{ts '2017-03-21 19:10:38.198881'},'M0:TK-SAINT ALBANS NY','+12155555555','+12155555555','','','1','bsurvey','Local/847@from-queue-00000d5c;2','','',3,'','1490137814.6959','1490137813.6905','','','')]
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('HANGUP',{ts '2017-03-21 19:10:38.200578'},'John Smith','2041','','','','613','from-queue','Local/847@from-queue-00000d5c;1','AppQueue','(Outgoing Line)',3,'','1490137814.6958','1490137813.6905','','','')]
  == Spawn extension (ext-queues, 613, 41) exited non-zero on 'SIP/Digium_Test-00000073'
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('CHAN_END',{ts '2017-03-21 19:10:38.200640'},'John Smith','2041','','','','613','from-queue','Local/847@from-queue-00000d5c;1','AppQueue','(Outgoing Line)',3,'','1490137814.6958','1490137813.6905','','','')]
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('APP_END',{ts '2017-03-21 19:10:38.201788'},'TK-SAINT ALBANS NY','+12155555555','+12155555555','','2675555555','613','ext-queues','SIP/Digium_Test-00000073','Queue','613,t,,,,,,,,',3,'','1490137813.6905','1490137813.6905','','','')]
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('HANGUP',{ts '2017-03-21 19:10:38.201990'},'TK-SAINT ALBANS NY','+12155555555','+12155555555','','2675555555','613','ext-queues','SIP/Digium_Test-00000073','','',3,'','1490137813.6905','1490137813.6905','','','')]
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('CHAN_END',{ts '2017-03-21 19:10:38.202566'},'TK-SAINT ALBANS NY','+12155555555','+12155555555','','2675555555','613','ext-queues','SIP/Digium_Test-00000073','','',3,'','1490137813.6905','1490137813.6905','','','')]
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('LINKEDID_END',{ts '2017-03-21 19:10:38.202593'},'TK-SAINT ALBANS NY','+12155555555','+12155555555','','2675555555','613','ext-queues','SIP/Digium_Test-00000073','','',3,'','1490137813.6905','1490137813.6905','','','')]
voip2*CLI>
Disconnected from Asterisk server
Asterisk cleanly ending (0).
Executing last minute cleanups

W/ DEXTEN

voip2*CLI>
    --  Feature Found: bsurvey1 exten: bsurvey1
    -- Executing [s@macro-bsurvey:1] DumpChan("SIP/2041-00000072", "") in new stack

Dumping Info For Channel: SIP/2041-00000072:
================================================================================
Info:
Name=               SIP/2041-00000072
Type=               SIP
UniqueID=           1490137696.6904
LinkedID=           1490137683.6790
CallerIDNum=        2041
CallerIDName=       John Smith
ConnectedLineIDNum= +12155555555
ConnectedLineIDName=M0:TK-SAINT ALBANS NY
DNIDDigits=         (N/A)
RDNIS=              (N/A)
Parkinglot=         default
Language=           en
State=              Up (6)
Rings=              0
NativeFormat=       (ulaw)
WriteFormat=        ulaw
ReadFormat=         ulaw
RawWriteFormat=     ulaw
RawReadFormat=      ulaw
WriteTranscode=     No
ReadTranscode=      No
1stFileDescriptor=  36
Framesin=           305
Framesout=          292
TimetoHangup=       0
ElapsedTime=        0h0m8s
DirectBridge=       <none>
IndirectBridge=     <none>
Context=            macro-bsurvey
Extension=          s
Priority=           1
CallGroup=
PickupGroup=
Application=        DumpChan
Data=               (Empty)
Blocking_in=        (Not Blocking)

Variables:
MACRO_DEPTH=1
ARG1=1
MACRO_PRIORITY=1
MACRO_CONTEXT=macro-dial
MACRO_EXTEN=s
DYNAMIC_FEATURENAME=bsurvey1
DYNAMIC_PEERNAME=Local/847@from-queue-00000d40;2
BRIDGEPEER=Local/847@from-queue-00000d40;2
SIPADDHEADER01=
SIPADDHEADER03=
SIPADDHEADER02=
SIPADDHEADER04=
GOSUB_RETVAL=
FORWARD_CONTEXT=from-internal
CFIGNORE=
MACRO_RESULT=
sipkey=
SIPHEADERKEYS=
DIALEDPEERNUMBER=2041
[email protected]:5060
CWIGNORE=
KEEPCID=TRUE
SAVEDCIDNAME=TK-SAINT ALBANS NY
REC_STATUS=RECORDING
RECORD_ID=Local/847@from-queue-00000d40;2
MIXMON_ID=0x7fa1c8133a60
CALLFILENAME=external-847-613-20170321-190803-1490137696.6901
REC_POLICY_MODE=FORCE
FROMQ=true
MOHCLASS=classical-piano
NODEST=613
QUEUEWAIT=1490137683
TTL=64
CALLEE_ACCOUNCODE=
REALCALLERIDNUM=+12155555555
CALLINGNUMPRES_SV=allowed_not_screened
CALLINGNAMEPRES_SV=allowed_not_screened
REVERSAL_REJECT=FALSE
FROM_DID=2675555555
MON_FMT=wav
TIMESTR=20170321-190803
YEAR=2017
MONTH=03
DAY=21
DIRECTION=INBOUND
================================================================================
    -- Executing [s@macro-bsurvey:2] ChannelRedirect("SIP/2041-00000072", "Local/847@from-queue-00000d40;2,bsurvey,1,1") in new stack
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('HANGUP',{ts '2017-03-21 19:08:24.244458'},'John Smith','2041','2041','','','s','bsurvey','SIP/2041-00000072','AppDial','(Outgoing Line)',3,'','1490137696.6904','1490137683.6790','','','')]
  == Spawn extension (bsurvey, 1, 1) exited non-zero on 'Local/847@from-queue-00000d40;2' in macro 'dial'
  == Spawn extension (bsurvey, 1, 1) exited non-zero on 'Local/847@from-queue-00000d40;2'
    -- Executing [1@bsurvey:1] Set("Local/847@from-queue-00000d40;2", "bsurvey_name=support") in new stack
    -- Executing [1@bsurvey:2] Set("Local/847@from-queue-00000d40;2", "bsurvey_start=2017-03-21 19:08:16") in new stack
    -- Executing [1@bsurvey:3] Set("Local/847@from-queue-00000d40;2", "bsurvey_unqiueid=1490137696.6901") in new stack
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('CHAN_END',{ts '2017-03-21 19:08:24.245096'},'John Smith','2041','2041','','','s','bsurvey','SIP/2041-00000072','AppDial','(Outgoing Line)',3,'','1490137696.6904','1490137683.6790','','','')]
    -- Executing [1@bsurvey:4] Set("Local/847@from-queue-00000d40;2", "bsurvey_agent=") in new stack
    -- Executing [1@bsurvey:5] Set("Local/847@from-queue-00000d40;2", "bsurvey_aname_key=/AMPUSER//cidname=") in new stack
    -- Executing [1@bsurvey:6] Set("Local/847@from-queue-00000d40;2", "bsurvey_aname=") in new stack
    -- Executing [1@bsurvey:7] AGI("Local/847@from-queue-00000d40;2", "bsurvey.php") in new stack
    -- Launched AGI Script /var/lib/asterisk/agi-bin/bsurvey.php
    -- bsurvey.php: Starting New survey
    -- AGI Script Executing Application: (Set) Options: (bsurvey_agent_name=${DB(/AMPUSER//cidname)})
       > bsurvey.php: Running SQL Command SELECT a.*,b.`displayname` as dp FROM bsurvey as a left join recordings as b on b.id=a.`rec_id` WHERE a.`id` = '1'
       > bsurvey.php: Connected to MySQL database OK.
       > bsurvey.php: Selected database OK.
[2017-03-21 19:08:24] WARNING[11761][C-0000003c]: file.c:701 ast_openstream_full: File Alt_SV_Announce does not exist in any format
       > bsurvey.php: Running SQL Command select `id` from survey.bsurvey_cdrs limit 0
    -- bsurvey.php: TABLE CREATED
       > bsurvey.php: Running SQL Command SELECT rec_id,bsurvey_id,b.filename as file,a.displayname,a.res_start,a.res_end FROM bsurvey_recs a left join recordings as b on a.rec_id= b.id where bsurvey_id='1' ORDER BY a.id
    -- bsurvey.php: Do questions
    -- bsurvey.php: REC Array
    -- bsurvey.php: (
    -- bsurvey.php:     [rec_id] => 65
    -- bsurvey.php:     [bsurvey_id] => 1
    -- bsurvey.php:     [file] => custom/alt_sv_q1
    -- bsurvey.php:     [displayname] => Call Satisfaction
    -- bsurvey.php:     [res_start] => 1
    -- bsurvey.php:     [res_end] => 5
    -- bsurvey.php: )
    -- bsurvey.php:
       > bsurvey.php: Running SQL Command insert into survey.bsurvey_cdrs(survey_name,question,res_start ,res_end,rec_file,unqiueid,
       > bsurvey.php:                   calldate,cid,answer,agent,agent_name) values
       > bsurvey.php:   ('support','Call Satisfaction','1','5','custom/alt_sv_q1','1490137696.6901',
       > bsurvey.php:                   '2017-03-21 19:08:16','','','','')
       > bsurvey.php: Running SQL Command select id from survey.bsurvey_cdrs where survey_name='support' and  question = 'Call Satisfaction' and  unqiueid='1490137696.6901' and agent_name = ''  limit 1
    -- <Local/847@from-queue-00000d40;2> Playing 'custom/alt_sv_q1.slin' (language 'en')
       > bsurvey.php: Running SQL Command update survey.bsurvey_cdrs set answer='5' where id=571308
    -- bsurvey.php: Do questions
    -- bsurvey.php: REC Array
    -- bsurvey.php: (
    -- bsurvey.php:     [rec_id] => 66
    -- bsurvey.php:     [bsurvey_id] => 1
    -- bsurvey.php:     [file] => custom/alt_sv_q2
    -- bsurvey.php:     [displayname] => Product Satisfaction
    -- bsurvey.php:     [res_start] => 1
    -- bsurvey.php:     [res_end] => 5
    -- bsurvey.php: )
    -- bsurvey.php:
       > bsurvey.php: Running SQL Command insert into survey.bsurvey_cdrs(survey_name,question,res_start ,res_end,rec_file,unqiueid,
       > bsurvey.php:                   calldate,cid,answer,agent,agent_name) values
       > bsurvey.php:   ('support','Product Satisfaction','1','5','custom/alt_sv_q2','1490137696.6901',
       > bsurvey.php:                   '2017-03-21 19:08:16','','','','')
       > bsurvey.php: Running SQL Command select id from survey.bsurvey_cdrs where survey_name='support' and  question = 'Product Satisfaction' and  unqiueid='1490137696.6901' and agent_name = ''  limit 1
    -- <Local/847@from-queue-00000d40;2> Playing 'custom/alt_sv_q2.slin' (language 'en')
       > bsurvey.php: Running SQL Command update survey.bsurvey_cdrs set answer='5' where id=571309
    -- bsurvey.php: Do questions
    -- bsurvey.php: REC
    -- <Local/847@from-queue-00000d40;2> Playing 'bsurvey-thanku.slin' (escape_digits=123456789) (sample_offset 0) (language 'en')
    -- <Local/847@from-queue-00000d40;2>AGI Script bsurvey.php completed, returning -1
  == MixMonitor close filestream (mixed)
    -- Executing [h@ext-queues:1] Macro("SIP/Digium_Test-00000070", "hangupcall,") in new stack
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('HANGUP',{ts '2017-03-21 19:08:37.835866'},'M0:TK-SAINT ALBANS NY','+12155555555','+12155555555','','','1','bsurvey','Local/847@from-queue-00000d40;2','','',3,'','1490137696.6901','1490137683.6790','','','')]
    -- Executing [s@macro-hangupcall:1] ExecIf("SIP/Digium_Test-00000070", "0?Set(CDR(recordingfile)=.wav)") in new stack
    -- Executing [s@macro-hangupcall:2] GotoIf("SIP/Digium_Test-00000070", "1?theend") in new stack
    -- Goto (macro-hangupcall,s,4)
    -- Executing [s@macro-hangupcall:4] ExecIf("SIP/Digium_Test-00000070", "0?Set(CDR(recordingfile)=)") in new stack
    -- Executing [s@macro-hangupcall:5] Hangup("SIP/Digium_Test-00000070", "") in new stack
  == Spawn extension (macro-hangupcall, s, 5) exited non-zero on 'SIP/Digium_Test-00000070' in macro 'hangupcall'
  == Spawn extension (ext-queues, h, 1) exited non-zero on 'SIP/Digium_Test-00000070'
       > [INSERT INTO cdr (calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata,duration,billsec,disposition,amaflags,uniqueid,recordingfile) VALUES ({ ts '2017-03-21 19:08:16' },'"M0:TK-SAINT ALBANS NY" <+12155555555>','+12155555555','847','from-queue-exten-only','Local/847@from-queue-00000d40;2','SIP/2041-00000072','AGI','HANGUP',21,19,'ANSWERED',3,'1490137696.6901','external-847-613-20170321-190803-1490137696.6901.wav')]
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('BRIDGE_END',{ts '2017-03-21 19:08:37.836169'},'TK-SAINT ALBANS NY','+12155555555','+12155555555','','2675555555','613','ext-queues','SIP/Digium_Test-00000070','Queue','613,t,,,,,,,,',3,'','1490137683.6790','1490137683.6790','Local/847@from-queue-00000d40;1','','')]
       > [INSERT INTO cdr (calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata,duration,billsec,disposition,amaflags,uniqueid,did,cnum,cnam) VALUES ({ ts '2017-03-21 19:08:03' },'"TK-SAINT ALBANS NY" <+12155555555>','+12155555555','613','ext-queues','SIP/Digium_Test-00000070','Local/847@from-queue-00000d40;1','Queue','613,t,,,,,,,,',34,34,'ANSWERED',3,'1490137683.6790','2675555555','+12155555555','TK-SAINT ALBANS NY')]
  == End MixMonitor Recording Local/847@from-queue-00000d40;2
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('CHAN_END',{ts '2017-03-21 19:08:37.843187'},'M0:TK-SAINT ALBANS NY','+12155555555','+12155555555','','','1','bsurvey','Local/847@from-queue-00000d40;2','','',3,'','1490137696.6901','1490137683.6790','','','')]
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('HANGUP',{ts '2017-03-21 19:08:37.844705'},'John Smith','2041','','','','613','from-queue','Local/847@from-queue-00000d40;1','AppQueue','(Outgoing Line)',3,'','1490137696.6900','1490137683.6790','','','')]
  == Spawn extension (ext-queues, 613, 41) exited non-zero on 'SIP/Digium_Test-00000070'
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('CHAN_END',{ts '2017-03-21 19:08:37.844767'},'John Smith','2041','','','','613','from-queue','Local/847@from-queue-00000d40;1','AppQueue','(Outgoing Line)',3,'','1490137696.6900','1490137683.6790','','','')]
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('APP_END',{ts '2017-03-21 19:08:37.845890'},'TK-SAINT ALBANS NY','+12155555555','+12155555555','','2675555555','613','ext-queues','SIP/Digium_Test-00000070','Queue','613,t,,,,,,,,',3,'','1490137683.6790','1490137683.6790','','','')]
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('HANGUP',{ts '2017-03-21 19:08:37.846015'},'TK-SAINT ALBANS NY','+12155555555','+12155555555','','2675555555','613','ext-queues','SIP/Digium_Test-00000070','','',3,'','1490137683.6790','1490137683.6790','','','')]
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('CHAN_END',{ts '2017-03-21 19:08:37.846474'},'TK-SAINT ALBANS NY','+12155555555','+12155555555','','2675555555','613','ext-queues','SIP/Digium_Test-00000070','','',3,'','1490137683.6790','1490137683.6790','','','')]
       > [INSERT INTO cel (eventtype,eventtime,cid_name,cid_num,cid_ani,cid_rdnis,cid_dnid,exten,context,channame,appname,appdata,amaflags,accountcode,uniqueid,linkedid,peer,userdeftype,userfield) VALUES ('LINKEDID_END',{ts '2017-03-21 19:08:37.846498'},'TK-SAINT ALBANS NY','+12155555555','+12155555555','','2675555555','613','ext-queues','SIP/Digium_Test-00000070','','',3,'','1490137683.6790','1490137683.6790','','','')]
voip2*CLI>

@dicko The survey does work w/ FreePBX 12 + Ast 11 + Distro 6 as mentioned earlier, I have no idea who made it though.

Change ${DEXTEN} (or now ${AMPUSER}) to ${DIALEDPEERNUMBER}

and all will come to a happy end

however you should still post this to github because there’s no point in passing the database key in asterisk to have an AGI query it when you can just do the same in Asterisk itself.

@tm1000 That didn’t seem to do the trick, still no bsurvey_agent …, but I posted the code on Github.

I have a feeling its not the greatest module you have ever seen, but its currently working lol, and I can’t upgrade untill it works. (On the new FreePBX 14)

https://github.com/FreeSoftwareServers/BSurvey

Considering where your chandump is at and what chandump is reporting the fact that no variable works for you is strange

Also why this?

DYNAMIC_FEATURES = bsurvey1#apprecord