Asterisk, How can i play an audio file

Shyju Pulari picture Shyju Pulari · Jan 31, 2014 · Viewed 7.5k times · Source

Here is the dial plan

[testInComingCalls]

exten => s,1,Answer

exten => 30953025,1,Dial(SIP/20000,20)

I would like to play an audio file as soon as somebody answered the call..

Please give me some idea how to call a php file, send the input and based on the output forward the call.

Answer

Matt Jordan picture Matt Jordan · Feb 4, 2014

Since most of the Dial options act on the called party, not the caller, you have to get a little creative. It is a little odd to do such things to the caller as opposed to the called party, but hey, it's Asterisk: there's usually a way to do whatever you want.

One approach would be to use the lesser known (and somewhat strange) G option. Quoting from the documentation:

If the call is answered, transfer the calling party to the specified priority and the called party to the specified priority plus one.

  • context
  • exten
  • priority

Basically, the G option takes the caller/called channel and - instead of bridging them together - bounces both of them out to the dialplan. You can then get a little creative to perform your Playback operation before putting them in a Bridge together. The following Dialplan should work (caveat: I haven't tested this and I'm sitting on a laptop on a couch, but this should get you close):

[default]

exten => 1000,1,NoOp()
 same => n,Dial(SIP/alice,,G(default^bridge_and_play^1))
 same => n,Hangup()

exten => bridge_and_play,1,Goto(jump_caller,1)
 same => n,Goto(jump_called,1)
 same => n,Hangup()

exten => jump_caller,1,NoOp()
 same => n,Answer()
 same => n,Playback(tt-monkeys)
 same => n,Bridge(${bridge_this})
 same => n,Hangup()

exten => jump_called,1,NoOp()
 same => n,Set(MASTER_CHANNEL(bridge_this)=${CHANNEL})
 same => n,Wait(1000)
 same => n,Hangup()