Adding cell phone to quemembers

I have setup my dialplan so that agents can become queuemembers, and when a caller presses 5 they should be sent to the queue, and a message plays on the cell phone that says “you are recieving a call from your company press-1 to accept” this is to avoid the call going to personal vm on the cell phone. Then the call should connect, but the call flows normally until I press one, then asterisk hangs the call up. I cant figure out how to connect back to the caller.
here is the relevant sections of the dialplan:

exten => 5,1,Log(NOTICE, Queue call for for queuemembers)
exten => 5,n,Queue(hyperionworks-testqueue,t,30)
exten => 5,n,VoiceMail(123@hyperionworks,u)
exten => 5,n,Hangup()
[hyperionworks-queuemembers]
; When a call is added to the queue
exten => 9001,1,Log(NOTICE, Adding queue member to hyperionworks-testqueue)
exten => 9001,n,GotoIf($[${LEN(${CALLERID(num)})} >= 10]?external:local)

; Add external number (e.g., cellphone) to queue
exten => 9001,n(external),Log(NOTICE, Adding external number to queue)
exten => 9001,n,AddQueueMember(hyperionworks-testqueue,Local/${CALLERID(num)}@cellphone-queue/n) ; Adding cell to queue
exten => 9001,n,Goto(complete)

; Add local extension to queue
exten => 9001,n(local),Log(NOTICE, Adding local extension to queue)
exten => 9001,n,AddQueueMember(hyperionworks-testqueue,SIP/${CALLERID(num)}) ; For local SIP extension
exten => 9001,n,Goto(complete)

exten => 9001,n(complete),Answer()
exten => 9001,n,PlayBack(agent-loginok)
exten => 9001,n,Hangup()

; Removing member from the queue
exten => 9011,1,Log(NOTICE, Removing queue member)
exten => 9011,n,GotoIf($[${LEN(${CALLERID(num)})} >= 10]?external:local)

; Remove external number from queue
exten => 9011,n(external),Log(NOTICE, Removing external number from queue)
exten => 9011,n,RemoveQueueMember(hyperionworks-testqueue,Local/${CALLERID(num)}@cellphone-queue/n)
exten => 9011,n,Goto(complete)

; Remove local extension from queue
exten => 9011,n(local),Log(NOTICE, Removing local extension from queue)
exten => 9011,n,RemoveQueueMember(hyperionworks-testqueue,SIP/${CALLERID(num)})
exten => 9011,n,Goto(complete)

exten => 9011,n(complete),Answer()
exten => 9011,n,PlayBack(agent-logoutok)
exten => 9011,n,Hangup()

[cellphone-queue]
exten => _X.,1,NoOp(Handling call for external cell phone ${EXTEN})
exten => _X.,n,Dial(Local/${EXTEN}@internal-phone,M(cellphone-accept^${EXTEN})) ; Use the macro to handle call acceptance
exten => _X.,n,Hangup()

[macro-cellphone-accept]
exten => s,1,NoOp(Starting Cellphone Acceptance Macro for ${ARG1})
exten => s,n,Answer()
exten => s,n,Wait(2)
exten => s,n,Playback(recordings/press-1)
exten => s,n,Read(DIGIT,1,10)

; Check if ‘1’ was pressed to accept the call
exten => s,n,GotoIf($[“${DIGIT}” = “1”]?accepted:hangup)

; If accepted
exten => s,n(accepted),NoOp(Call Accepted)

; Capture the caller’s channel
exten => s,n,Set(CALLER_CHANNEL=${CHANNEL})

; Capture the peer channel
exten => s,n,Set(PEER_CHANNEL=${BRIDGEPEER})

; Log both channels for debugging purposes
exten => s,n,NoOp(CALLER_CHANNEL=${CALLER_CHANNEL} PEER_CHANNEL=${PEER_CHANNEL})

; Check if PEER_CHANNEL is properly set
exten => s,n,GotoIf($[“${PEER_CHANNEL}” != “”]?bridge:hangup)

; Bridge the two channels
exten => s,n(bridge),Bridge(${CALLER_CHANNEL},${PEER_CHANNEL})

; In case of failure, hang up
exten => s,n(hangup),NoOp(Hangup due to failure or no peer channel)
exten => s,n,Hangup()

exten => s,n,Return()

[internal-phone]
exten => _X.,1,NoOp(Dialing external number ${EXTEN} using LCR macro)
exten => _X.,n,Macro(hw-direct-dial,${EXTEN},${EXTEN},5) ; Call the LCR macro with necessary arguments
exten => _X.,n,Hangup()

Where did this macro-cellphone-accept come from?

Aside from that, it’s overly complicated and wouldn’t work. It doesn’t need to do anything with PEER_CHANNEL, or Bridge. In the case where it is accepted you just have to stop Macro execution and that’s that. For cases where it isn’t accepted you set the MACRO_RESULT dialplan variable[1].

[1] Dial - Asterisk Documentation

1 Like

You should use U, rather than M, because M is no longer supported, as of Asterisk 21.

The B channel is already up when M/U is executed, so the Answer serves no purpose.

You should not manipulate channels, including hangup, in the M/U code, but should set the appropriate channel variable to indicate whether the call is to be accepted or rejected. For U this is GOSUB_RESULT; details for M are not in the latest documentation, as macros no longer exist.

Asterisk GPT…thank you so much its working as expected now!

Sigh. I figured. It hallucinates… a lot.

so after making the changes it worked as expected. I was able to join the queuemembers with my cell phone, It would call my cell a play the message, after the caller pressed 5, i could press 1 and it would connect. I tried to port the code over to another client and it doesnt work. I attempted to test it using the original clients setup and it seems to trying to use the outbound macro for the other client. Is this because I have the cell phone added as an internal device? any insight would be greatly appreciated.

here is the dialplan:
exten => 5,1,Log(NOTICE, Queue call for for queuemembers)
exten => 5,n,Queue(hyperionworks-testqueue,t,30)
exten => 5,n,VoiceMail(123@hyperionworks,u)
exten => 5,n,Hangup()

[hyperionworks-queueout]
exten => s,1,Goto(1)
exten => 1,1,Voicemail(123@hyperionworks,u)

[hyperionworks-queuemembers]
; When a call is added to the queue
exten => 9001,1,Log(NOTICE, Adding queue member to hyperionworks-testqueue)
exten => 9001,n,GotoIf($[${LEN(${CALLERID(num)})} >= 10]?external:local)

; Add external number (e.g., cellphone) to queue
exten => 9001,n(external),Log(NOTICE, Adding external number to queue)
exten => 9001,n,AddQueueMember(hyperionworks-testqueue,Local/${CALLERID(num)}@cellphone-queue/n) ; Adding cell to queue
exten => 9001,n,Goto(complete)

; Add local extension to queue
exten => 9001,n(local),Log(NOTICE, Adding local extension to queue)
exten => 9001,n,AddQueueMember(hyperionworks-testqueue) ; For local SIP extension
exten => 9001,n,Goto(complete)

exten => 9001,n(complete),Answer()
exten => 9001,n,Wait(1)
exten => 9001,n,PlayBack(added)
exten => 9001,n,Hangup()

; Removing member from the queue
exten => 9011,1,Log(NOTICE, Removing queue member)
exten => 9011,n,GotoIf($[${LEN(${CALLERID(num)})} >= 10]?external:local)

; Remove external number from queue
exten => 9011,n(external),Log(NOTICE, Removing external number from queue)
exten => 9011,n,RemoveQueueMember(hyperionworks-testqueue,Local/${CALLERID(num)}@cellphone-queue/n)
exten => 9011,n,Goto(complete)

; Remove local extension from queue
exten => 9011,n(local),Log(NOTICE, Removing local extension from queue)
exten => 9011,n,RemoveQueueMember(hyperionworks-testqueue)
exten => 9011,n,Goto(complete)

exten => 9011,n(complete),Answer()
exten => 9011,n,Wait(1)
exten => 9011,n,PlayBack(removed)
exten => 9011,n,Hangup()

[cellphone-queue]
exten => _X.,1,NoOp(Handling call for external cell phone ${EXTEN})
exten => _X.,n,Dial(Local/${EXTEN}@internal-phone,M(cellphone-accept^${EXTEN})) ; Use the macro to handle call acceptance
exten => _X.,n,Hangup()

[macro-cellphone-accept]
exten => s,1,NoOp(Starting Cellphone Acceptance Macro for ${ARG1})
exten => s,n,Answer()
exten => s,n,Wait(2)
exten => s,n,Playback(recordings/press-1)
exten => s,n,Read(DIGIT,1,10)

; Check if ‘1’ was pressed to accept the call
exten => s,n,GotoIf($[“${DIGIT}” = “1”]?accepted:rejected)

; If accepted, stop macro execution
exten => s,n(accepted),NoOp(Call Accepted)
exten => s,n,MacroExit()

; If rejected, set MACRO_RESULT to FAILURE
exten => s,n(rejected),NoOp(Call Rejected)
exten => s,n,Set(MACRO_RESULT=FAILURE)
exten => s,n,Hangup()

[internal-phone]
exten => _X.,1,NoOp(Dialing external number ${EXTEN} using LCR macro)
exten => _X.,n,Macro(hw-direct-dial,${EXTEN},${EXTEN},5) ; Call the LCR macro with necessary arguments
exten => _X.,n,Hangup()

[macro-hw-direct-dial]
; Macro to dial out using LCR.
; This macro queries a MySQL DB and returns a list of providers in
; order of ascending cost, and it tries them in succession until one
; of them accepts the call.
; Usage: context,extension,maxchannels
exten => s,1,Log(NOTICE, Executing AGI LCR Script)
exten => s,n,Set(GROUP()=${ARG1})
exten => s,n,GotoIf($[ ${GROUP_COUNT(${ARG1})} > ${ARG3}]?s-MAXEDOUT,1)
exten => s,n,Log(NOTICE, ARG2 ${ARG2})
exten => s,n,Set(CALLERID(num)=${IF($[ ${LEN(${CALLERID(num)})} != 10 ] ? 6024459832 : ${CALLERID(num)})})
exten => s,n,Set(CALLFILENAME=/var/spool/asterisk/monitor/${CALLERID(num)}-${EXTEN}-${STRFTIME(${EPOCH},%Y%m%d-%H%M%S)})
exten => s,n,Monitor(wav,${CALLFILENAME},m)
exten => s,n,Set(CDR(accountcode)=out-domestic)
exten => s,n,AGI(/opt/scripts/lcr.php,${ARG2})
exten => s,n,GotoIf($[ ${TOTAL_PROVIDERS} < 1 ]?s-NOPROVIDERS,1)
exten => s,n,Set(CALL_ATTEMPT=1)
exten => s,n(retry),Set(PROVIDER=${EVAL(${PROVIDER${CALL_ATTEMPT}})})
exten => s,n,Log(NOTICE, Dialing ${ARG2} via ${PROVIDER})
exten => s,n,Dial(SIP/${${PROVIDER}}/${ARG2},300,KrX)
exten => s,n,GotoIf($[ “${CALL_ATTEMPT}” >= “${TOTAL_PROVIDERS}” ]?s-CANCEL,1)
exten => s,n,Set(CALL_ATTEMPT=$[ ${CALL_ATTEMPT} + 1 ])
exten => s,n,Goto(s-${DIALSTATUS},1)

exten => s-NOANSWER,1,Noop()
exten => s-CANCEL,1,Hangup()
exten => s-HANGUP,1,Hangup()

exten => s-BUSY,1,Goto(s,retry)
exten => s-CHANUNAVAIL,1,Goto(s,retry)
exten => s-CONGESTION,1,Goto(s,retry)

exten => s-NOPROVIDERS,1,Log(NOTICE, There are no providers to complete the call to ${ARG2})
exten => s-NOPROVIDERS,n,Hangup()

exten => s-MAXEDOUT,1,Log(NOTICE, Outbound call failed, lines maxed for ${ARG1})
exten => s-MAXEDOUT,n,Playback(recordings/all-outgoing-lines-unavailable)
exten => s-MAXEDOUT,n,Playback(recordings/pls-try-call-later)
exten => s-MAXEDOUT,n,Hangup()

Here is a log snippet:

[2024-10-01 08:18:17] VERBOSE[17998][C-0000698f] app_queue.c: Called Local/4802686917@cellphone-queue/n
[2024-10-01 08:18:17] VERBOSE[18033][C-0000698f] pbx.c: Executing [4802686917@cellphone-queue:2] Dial(“Local/4802686917@cellphone-queue-00007ca1;2”, “Local/4802686917@internal-phone,M(cellphone-accept^4802686917)”) in new stack
[2024-10-01 08:18:17] VERBOSE[18033][C-0000698f] app_dial.c: Called Local/4802686917@internal-phone
[2024-10-01 08:18:17] VERBOSE[18034][C-0000698f] pbx.c: Executing [4802686917@internal-phone:1] NoOp(“Local/4802686917@internal-phone-00007ca2;2”, “Dialing external number 4802686917 using LCR macro”) in new stack
[2024-10-01 08:18:17] WARNING[18033][C-0000698f] app_dial.c: Invalid timeout specified: ‘M(cellphone-accept^4802686917)’. Setting timeout to infinite
[2024-10-01 08:18:17] VERBOSE[18034][C-0000698f] pbx.c: Executing [4802686917@internal-phone:2] Macro(“Local/4802686917@internal-phone-00007ca2;2”, “detours-direct-dial,4802686917,4802686917,5”) in new stack
[2024-10-01 08:18:17] WARNING[18034][C-0000698f] app_macro.c: No such context ‘macro-detours-direct-dial’ for macro ‘detours-direct-dial’. Was called by 4802686917@internal-phone
[2024-10-01 08:18:17] VERBOSE[18034][C-0000698f] pbx.c: Executing [4802686917@internal-phone:3] Hangup(“Local/4802686917@internal-phone-00007ca2;2”, “”) in new stack
[2024-10-01 08:18:17] VERBOSE[18034][C-0000698f] pbx.c: Spawn extension (internal-phone, 4802686917, 3) exited non-zero on ‘Local/4802686917@internal-phone-00007ca2;2’
[2024-10-01 08:18:17] VERBOSE[18033][C-0000698f] app_dial.c: No one is available to answer at this time (1:0/0/0)
[2024-10-01 08:18:17] VERBOSE[18033][C-0000698f] pbx.c: Executing [4802686917@cellphone-queue:3] Hangup(“Local/4802686917@cellphone-queue-00007ca1;2”, “”) in new stack
[2024-10-01 08:18:17] VERBOSE[18033][C-0000698f] pbx.c: Spawn extension (cellphone-queue, 4802686917, 3) exited non-zero on ‘Local/4802686917@cellphone-queue-00007ca1;2’
[2024-10-01 08:18:17] VERBOSE[17998][C-0000698f] app_queue.c: Nobody picked up in 0 ms
[2024-10-01 08:18:19] VERBOSE[18035][C-0000698f] pbx.c: Executing [4802686917@cellphone-queue:1] NoOp(“Local/4802686917@cellphone-queue-00007ca3;2”, “Handling call for external cell phone 4802686917”) in new stack
[2024-10-01 08:18:19] VERBOSE[18035][C-0000698f] pbx.c: Executing [4802686917@cellphone-queue:2] Dial(“Local/4802686917@cellphone-queue-00007ca3;2”, “Local/4802686917@internal-phone,M(cellphone-accept^4802686917)”) in new stack
[2024-10-01 08:18:19] VERBOSE[17998][C-0000698f] app_queue.c: Called Local/4802686917@cellphone-queue/n
[2024-10-01 08:18:19] VERBOSE[18035][C-0000698f] app_dial.c: Called Local/4802686917@internal-phone
[2024-10-01 08:18:19] WARNING[18035][C-0000698f] app_dial.c: Invalid timeout specified: ‘M(cellphone-accept^4802686917)’. Setting timeout to infinite
[2024-10-01 08:18:19] VERBOSE[18036][C-0000698f] pbx.c: Executing [4802686917@internal-phone:1] NoOp(“Local/4802686917@internal-phone-00007ca4;2”, “Dialing external number 4802686917 using LCR macro”) in new stack
[2024-10-01 08:18:19] VERBOSE[18036][C-0000698f] pbx.c: Executing [4802686917@internal-phone:2] Macro(“Local/4802686917@internal-phone-00007ca4;2”, “detours-direct-dial,4802686917,4802686917,5”) in new stack
[2024-10-01 08:18:19] WARNING[18036][C-0000698f] app_macro.c: No such context ‘macro-detours-direct-dial’ for macro ‘detours-direct-dial’. Was called by 4802686917@internal-phone
[2024-10-01 08:18:19] VERBOSE[18036][C-0000698f] pbx.c: Executing [4802686917@internal-phone:3] Hangup(“Local/4802686917@internal-phone-00007ca4;2”, “”) in new stack
[2024-10-01 08:18:19] VERBOSE[18036][C-0000698f] pbx.c: Spawn extension (internal-phone, 4802686917, 3) exited non-zero on ‘Local/4802686917@internal-phone-00007ca4;2’
[2024-10-01 08:18:19] VERBOSE[18035][C-0000698f] app_dial.c: No one is available to answer at this time (1:0/0/0)
[2024-10-01 08:18:19] VERBOSE[18035][C-0000698f] pbx.c: Executing [4802686917@cellphone-queue:3] Hangup(“Local/4802686917@cellphone-queue-00007ca3;2”, “”) in new stack
[2024-10-01 08:18:19] VERBOSE[18035][C-0000698f] pbx.c: Spawn extension (cellphone-queue, 4802686917, 3) exited non-zero on ‘Local/4802686917@cellphone-queue-00007ca3;2’
[2024-10-01 08:18:19] VERBOSE[17998][C-0000698f] app_queue.c: Nobody picked up in 0 ms
[2024-10-01 08:18:21] VERBOSE[18037][C-0000698f] pbx.c: Executing [4802686917@cellphone-queue:1] NoOp(“Local/4802686917@cellphone-queue-00007ca5;2”, “Handling call for external cell phone 4802686917”) in new stack
[2024-10-01 08:18:21] VERBOSE[17998][C-0000698f] app_queue.c: Called Local/4802686917@cellphone-queue/n
[2024-10-01 08:18:21] VERBOSE[18037][C-0000698f] pbx.c: Executing [4802686917@cellphone-queue:2] Dial(“Local/4802686917@cellphone-queue-00007ca5;2”, “Local/4802686917@internal-phone,M(cellphone-accept^4802686917)”) in new stack
[2024-10-01 08:18:21] VERBOSE[18037][C-0000698f] app_dial.c: Called Local/4802686917@internal-phone
[2024-10-01 08:18:21] WARNING[18037][C-0000698f] app_dial.c: Invalid timeout specified: ‘M(cellphone-accept^4802686917)’. Setting timeout to infinite
[2024-10-01 08:18:21] VERBOSE[18038][C-0000698f] pbx.c: Executing [4802686917@internal-phone:1] NoOp(“Local/4802686917@internal-phone-00007ca6;2”, “Dialing external number 4802686917 using LCR macro”) in new stack
[2024-10-01 08:18:21] VERBOSE[18038][C-0000698f] pbx.c: Executing [4802686917@internal-phone:2] Macro(“Local/4802686917@internal-phone-00007ca6;2”, “detours-direct-dial,4802686917,4802686917,5”) in new stack
[2024-10-01 08:18:21] WARNING[18038][C-0000698f] app_macro.c: No such context ‘macro-detours-direct-dial’ for macro ‘detours-direct-dial’. Was called by 4802686917@internal-phone
[2024-10-01 08:18:21] VERBOSE[18038][C-0000698f] pbx.c: Executing [4802686917@internal-phone:3] Hangup(“Local/4802686917@internal-phone-00007ca6;2”, “”) in new stack
[2024-10-01 08:18:21] VERBOSE[18038][C-0000698f] pbx.c: Spawn extension (internal-phone, 4802686917, 3) exited non-zero on ‘Local/4802686917@internal-phone-00007ca6;2’
[2024-10-01 08:18:21] VERBOSE[18037][C-0000698f] app_dial.c: No one is available to answer at this time (1:0/0/0)
[2024-10-01 08:18:21] VERBOSE[18037][C-0000698f] pbx.c: Executing [4802686917@cellphone-queue:3] Hangup(“Local/4802686917@cellphone-queue-00007ca5;2”, “”) in new stack
[2024-10-01 08:18:21] VERBOSE[18037][C-0000698f] pbx.c: Spawn extension (cellphone-queue, 4802686917, 3) exited non-zero on ‘Local/4802686917@cellphone-queue-00007ca5;2’
[2024-10-01 08:18:21] VERBOSE[17998][C-0000698f] app_queue.c: Nobody picked up in 0 ms
[2024-10-01 08:18:23] VERBOSE[18045][C-0000698f] pbx.c: Executing [4802686917@cellphone-queue:1] NoOp(“Local/4802686917@cellphone-queue-00007ca7;2”, “Handling call for external cell phone 4802686917”) in new stack
[2024-10-01 08:18:23] VERBOSE[18045][C-0000698f] pbx.c: Executing [4802686917@cellphone-queue:2] Dial(“Local/4802686917@cellphone-queue-00007ca7;2”, “Local/4802686917@internal-phone,M(cellphone-accept^4802686917)”) in new stack
[2024-10-01 08:18:23] VERBOSE[17998][C-0000698f] app_queue.c: Called Local/4802686917@cellphone-queue/n
[2024-10-01 08:18:23] VERBOSE[18045][C-0000698f] app_dial.c: Called Local/4802686917@internal-phone
[2024-10-01 08:18:23] WARNING[18045][C-0000698f] app_dial.c: Invalid timeout specified: ‘M(cellphone-accept^4802686917)’. Setting timeout to infinite
[2024-10-01 08:18:23] VERBOSE[18046][C-0000698f] pbx.c: Executing [4802686917@internal-phone:1] NoOp(“Local/4802686917@internal-phone-00007ca8;2”, “Dialing external number 4802686917 using LCR macro”) in new stack
[2024-10-01 08:18:23] VERBOSE[18046][C-0000698f] pbx.c: Executing [4802686917@internal-phone:2] Macro(“Local/4802686917@internal-phone-00007ca8;2”, “detours-direct-dial,4802686917,4802686917,5”) in new stack
[2024-10-01 08:18:23] WARNING[18046][C-0000698f] app_macro.c: No such context ‘macro-detours-direct-dial’ for macro ‘detours-direct-dial’. Was called by 4802686917@internal-phone
[2024-10-01 08:18:23] VERBOSE[18046][C-0000698f] pbx.c: Executing [4802686917@internal-phone:3] Hangup(“Local/4802686917@internal-phone-00007ca8;2”, “”) in new stack
[2024-10-01 08:18:23] VERBOSE[18046][C-0000698f] pbx.c: Spawn extension (internal-phone, 4802686917, 3) exited non-zero on ‘Local/4802686917@internal-phone-00007ca8;2’
[2024-10-01 08:18:23] VERBOSE[18045][C-0000698f] app_dial.c: No one is available to answer at this time (1:0/0/0)
[2024-10-01 08:18:23] VERBOSE[18045][C-0000698f] pbx.c: Executing [4802686917@cellphone-queue:3] Hangup(“Local/4802686917@cellphone-queue-00007ca7;2”, “”) in new stack
[2024-10-01 08:18:23] VERBOSE[18045][C-0000698f] pbx.c: Spawn extension (cellphone-queue, 4802686917, 3) exited non-zero on ‘Local/4802686917@cellphone-queue-00007ca7;2’
[2024-10-01 08:18:23] VERBOSE[17998][C-0000698f] app_queue.c: Nobody picked up in 0 ms

Dialplan does what you tell it to do, so that has to be in the dialplan in use. Specifically…

Context internal-phone priority 2.