Last CallerID ends up as agent in queue!

We have an odd problem with our call center agents who log into our customer service queues using a custom script that ends up subscribing the last caller’s CallerID number as a logged in queue agent. This is something of a problem, as I’m sure you can imagine!

Here is the macro we call via *26 and use to allow our agents to log in:

exten => s,1,Wait(1)
exten => s,n,Macro(user-callerid,SKIPTTL,)
exten => s,n,Set(CALLBACKNUM=${AMPUSER})
exten => s,n,AddQueueMember(15000,Local/${CALLBACKNUM}@from-internal/n)
exten => s,n,AddQueueMember(15001,Local/${CALLBACKNUM}@from-internal/n)
exten => s,n,AddQueueMember(15100,Local/${CALLBACKNUM}@from-internal/n)
exten => s,n,AddQueueMember(15101,Local/${CALLBACKNUM}@from-internal/n)
exten => s,n,AddQueueMember(15200,Local/${CALLBACKNUM}@from-internal/n)
exten => s,n,AddQueueMember(15201,Local/${CALLBACKNUM}@from-internal/n)
exten => s,n,AddQueueMember(15400,Local/${CALLBACKNUM}@from-internal/n)
exten => s,n,AddQueueMember(15401,Local/${CALLBACKNUM}@from-internal/n)
exten => s,n,AddQueueMember(15402,Local/${CALLBACKNUM}@from-internal/n)
exten => s,n,AddQueueMember(15403,Local/${CALLBACKNUM}@from-internal/n)
exten => s,n,AddQueueMember(15500,Local/${CALLBACKNUM}@from-internal/n)
exten => s,n,System( echo "${EPOCH}|${UNIQUEID}|NONE|Agent/${CALLBASCKNUM}|AGENTLOGIN|-" >> /var/log/asterisk/queue_log )
exten => s,n,UserEvent(Agentlogin,Agent: ${CALLBACKNUM})
exten => s,n,Wait(1)
exten => s,n,Playback(agent-loginok&with&extension)
exten => s,n,SayDigits(${CALLBACKNUM})
exten => s,n,Macro(user-callerid,)
exten => s,n,dbDel(DND/${AMPUSER})
exten => s,n,Set(STATE=NOT_INUSE)
exten => s,n,Gosub(app-dnd-off,sstate,1)
exten => s,n(hook_1),Playback(do-not-disturb&de-activated)
exten => s,n,Macro(hangupcall,)
exten => sstate,1,Set(DEVSTATE(Custom:DND${AMPUSER})=${STATE})
exten => sstate,n,Set(DEVICES=${DB(AMPUSER/${AMPUSER}/device)})
exten => sstate,n,GotoIf($["${DEVICES}" = "" ]?return)
exten => sstate,n,Set(LOOPCNT=${FIELDQTY(DEVICES,&)})
exten => sstate,n,Set(ITER=1)
exten => sstate,n(begin),Set(DEVSTATE(Custom:DEVDND${CUT(DEVICES,&,${ITER})})=${STATE})
exten => sstate,n,Set(ITER=$[${ITER} + 1])
exten => sstate,n,GotoIf($[${ITER} <= ${LOOPCNT}]?begin)
exten => sstate,n(return),Return()

; end of [macro-call-center-customer-service-login]

Any idea how Asterisk gets the CallerID number of the most recent caller to the extension that executes this macro as the agent number to be subscribed?

Hi… we have continued to try to troubleshoot this issue, but have found no solution. I’m assuming it is either a major bug in our macro or a major bug in FreePBX. Please let me know if I need to provide additional details to assist in figuring this out… Thanks!

I’m about 99.9999% confident that it is not a bug in FreePBX, so you’ll have to take a closer look at your macro and/or custom script.