AMI Originate a call and play a sound to the caller

Hello,

So I have a dial plan and a simple AMI script to get an agent to call an outside line that’s working great but when I try to add a sound file to play to the caller’s line it’s failing.

AMI Where internalPhoneline is the extension and target is a customer’s phone #

        $originateRequest = "Action: Originate\r\n";
        $originateRequest .= "Channel: Local/$internalPhoneline@from-internal\r\n";
        $originateRequest .= "Callerid: Playit\r\n";
        $originateRequest .= "Exten:  do_chanspy\r\n";
        $originateRequest .= "Context: test-2\r\n";
        $originateRequest .= "Variable: ActionID=PlayBack\r\n";
        $originateRequest .= "Variable: WhatToPlay=tt-monkeys\r\n";
        $originateRequest .= "Variable: WhoHear=DAHDI/i2/1$target\r\n";
        $originateRequest .= "Priority: 1\r\n";
        $originateRequest .= "Async: yes\r\n\r\n";
        $originateRequest .= "ActionID: PlayBack\r\n";
        // Send originate request
        $originate = stream_socket_sendto($socket, $originateRequest);

Dialplan

[test-2]
exten => do_playback,1,Answer()
exten => do_playback,n,UserEvent(BeforePlayBack,ActionID:${ActionID} & ${UNIQUEID} & ${CHANNEL} & ${WhatToPlay} & ${WhoHear})
exten => do_playback,n,Wait(0.3)
exten => do_playback,n,Playback(${WhatToPlay})
; PLAYBACKSTATUS - SUCCESS FAILED
exten => do_playback,n,UserEvent(AfterPlayBack,ActionID:${ActionID} & ${UNIQUEID} & ${CHANNEL} & ${WhatToPlay} & ${WhoHear} & ${PLAYBACKSTATUS})
exten => do_playback,n,Hangup()

exten => do_chanspy,1,Answer()
exten => do_chanspy,n,NoOp(‘READY TO PLAY’)
exten => do_chanspy,n,UserEvent(BeforeChanSpy,ActionID:${ActionID} & ${UNIQUEID} & ${CHANNEL} & ${WhatToPlay} & ${WhoHear})
exten => do_chanspy,n,ChanSpy(${WhoHear},qW)
exten => do_chanspy,n,UserEvent(AfterChanSpy,ActionID:${ActionID} & ${UNIQUEID} & ${CHANNEL} & ${WhatToPlay} & ${WhoHear})
exten => do_chanspy,n,Hangup()

Logs

[2017-04-28 09:28:02] VERBOSE[2119][C-002bdb1b] pbx.c: – Executing [do_chanspy@scott-test-2:3] UserEvent(“Local/614@from-internal-0004e327;1”, “BeforeChanSpy,ActionID:PlayBack & 1493396880.970099 & Local/614@from-internal-0004e327;1 & tt-monkeys & DAHDI/i2/18315210245”) in new stack
Executing [do_chanspy@scott-test-2:3] UserEvent(“Local/614@from-internal-0004e327;1”, “BeforeChanSpy,ActionID:PlayBack & 1493396880.970099 & Local/614@from-internal-0004e327;1 & tt-monkeys & DAHDI/i2/18315210245”) in new stack

If I change Channel: Local/$internalPhoneline@from-internal
to Channel: Local/$internalPhoneline@do_playback or
I get an error of no dialplan

Looks like chanspy isn’t working. Without the call to the dial plan I get both lines connected

Thanks in advance,

I’m not sure to understand what are you trying to do but just as an aside I will post this because I think it is related to what you are trying to do and also it will help others.

Playback a message to a channel it is a very requested feature but it is little tricky, and that’s why most of the people with basic or intermediate knowledge get stuck trying to achieve this goal.

Here you have a basic example of one of the many ways to achieve this task

  1. First inject the audio using chanspy to the target channel

[spy_sound]
exten=>_x.,1,Answer()
same=>n,Wait(1)
same=>n,Noop( /${EXTEN} ${SID})
same=>n,ChanSpy(SIP/${EXTEN},qB)
same=>n,hangup()

Play the sound file to the target channel using local channel and originate command

  1. asterisk -x “originate Local/101@spy_sound application playback demo-thanks”

This will play a message to the SIP device 101 assuming 101 is in a call (caller and callee will hear the message).

Thanks for your reply.

I’m starting to understand. What I’m trying to do is have the originate
play the sound file to an agent “You have a call back from the support
queue” then connect the call to the customer.

I found this example for the originate call -

Action: Originate
Channel: Local/do_playback at cfmc_cdi_private
Exten: do_chanspy
Context: cfmc_cdi_private
Priority: 1
Variable: CfMC_ActionID=PlayBack
Variable: CfMC_WhatToPlay=lyrics-louie-louie
Variable: CfMC_WhoHear=SIP/GXP280_18-00000002
ActionID: PlayBack
Async: true

exten => do_playback,1,Answer()
exten => do_playback,n,UserEvent(BeforePlayBack,ActionID:${CfMC_ActionID}
& ${UNIQUEID} & ${CHANNEL} & ${CfMC_WhatToPlay} & ${CfMC_WhoHear})
exten => do_playback,n,Wait(0.3)
exten => do_playback,n,Playback(${CfMC_WhatToPlay})
; PLAYBACKSTATUS - SUCCESS FAILED
exten => do_playback,n,UserEvent(AfterPlayBack,ActionID:${CfMC_ActionID} &
${UNIQUEID} & ${CHANNEL} & ${CfMC_WhatToPlay} & ${CfMC_WhoHear} &
${PLAYBACKSTATUS})
exten => do_playback,n,Hangup()

exten => do_chanspy,1,Answer()
exten => do_chanspy,n,UserEvent(BeforeChanSpy,ActionID:${CfMC_ActionID} &
${UNIQUEID} & ${CHANNEL} & ${CfMC_WhatToPlay} & ${CfMC_WhoHear})
exten => do_chanspy,n,ChanSpy(${CfMC_WhoHear},qW)
exten => do_chanspy,n,UserEvent(AfterChanSpy,ActionID:${CfMC_ActionID} &
${UNIQUEID} & ${CHANNEL} & ${CfMC_WhatToPlay} & ${CfMC_WhoHear})
exten => do_chanspy,n,Hangup()

In this example of the originate command, what would “Local/do_playback at
cfmc_cdi_private” refer to? I understand that is the local channel but
specifically the “at cfmc_cdi_private” as the example uses it for both the
channel and the context? Would this be a context like from-internal? I
think once I understand that I’ll be able to modify the script to do what
we are looking for.

Thanks for your excellent guidance,

You dont need to use chanspy to achieve the above statement, just use local channel to dial to the agent using the dial option A( x ) - Play an announcement to the called party, where x is the prompt to be played
x - The file to play to the called party

Hello,

Just FYI,

The asterisk call you sent ends up with a “No such command” error after
I’ve added the dialplan to extensions_custom.conf

[root@newpbx asterisk]# asterisk -x “originate Local/614@spy_sound
application playback demo-thanks”

No such command ‘originate Local/614@spy_sound application playback
demo-thanks’ (type ‘core show help originate Local/614@spy_sound’ for other
possible commands)

Looking into it now.

Cheers,

Run this command asterisk -x " core show help " | grep -i originate and post the output

the command must run in a single line but you add the command on 2 lines that is the issue I guess.

Dot it like this in a single line \

asterisk -x “originate Local/614@spy_sound application playback demo-thanks”

Just needed to add “channel” to the asterisk 1.8 call

asterisk -x “channel originate Local/614@spy_sound application playback demo-thanks”

Still getting
2017-05-01 14:13:23] VERBOSE[18865][C-002bf97e] pbx.c: – Executing [614@spy_sound:1] Answer(“Local/614@spy_sound-0004fd5f;2”, “”) in new stack
[2017-05-01 14:13:23] VERBOSE[18866][C-002bf97e] pbx.c: – Launching playback(custom/ELITE-Support-queue.wav) on Local/614@spy_sound-0004fd5f;1
[2017-05-01 14:13:23] WARNING[18866][C-002bf97e] app_playback.c: ast_streamfile failed on Local/614@spy_sound-0004fd5f;1 for custom/ELITE-Support-queue.wav
[2017-05-01 14:13:23] VERBOSE[18865][C-002bf97e] pbx.c: == Spawn extension (spy_sound, 614, 1) exited non-zero on ‘Local/614@spy_sound-0004fd5f;2’

Thanks for looking…
no sound when using the Dial instead of ChanSpy –

Got it. Here is a working example

// Prepare originate request //
$originateRequest = “Action: Originate\r\n”;
$originateRequest .= “Channel: Local/xxx@from-internal\r\n”;
$originateRequest .= “Callerid: Support\r\n”;
$originateRequest .= “Exten: do_playback\r\n”;
$originateRequest .= “Context: $context\r\n”;
$originateRequest .= “Variable: ActionID=PlayBack\r\n”;
$originateRequest .= “Variable: WhatToPlay=custom/support_queue\r\n”;
$originateRequest .= “Variable: WhoHear=Local/xxx”;
$originateRequest .= “Priority: 1\r\n”;
$originateRequest .= “Async: yes\r\n\r\n”;
$originateRequest .= “ActionID: PlayBack\r\n”;
// Send originate request
$originate = stream_socket_sendto($socket, $originateRequest);

[$context]
exten => do_playback,1,Answer()
exten => do_playback,n,UserEvent(BeforePlayBack,ActionID:${ActionID} & ${UNIQUEID} & ${CHANNEL} & ${WhatToPlay} & ${WhoHear})
exten => do_playback,n,Wait(0.3)
exten => do_playback,n,Playback(${WhatToPlay})
exten => do_playback,n,UserEvent(AfterPlayBack,ActionID:${ActionID} & ${UNIQUEID} & ${CHANNEL} & ${WhatToPlay} & ${WhoHear} & ${PLAYBACKSTATUS})
exten => do_playback,n,DIAL(DAHDI/i2/$number-to-call,g)
exten => do_playback,n,Log(NOTICE, Call back queue result: ${DIALSTATUS})
; exten => do_playback,n,Hangup()

Thanks for pointing me in the right direction.

1 Like