How to play a sound file after user answers the call

I am using call files to make outbound calls and play sound files to users.
However, asterisk doesn’t wait till the user picks up the call. Often times, this leads to the sound file playing prematurely. How do I make sure the user has picked up the call before I play a sound file.

Here’s my call file:
Channel: DAHDI/G0/1234567123
MaxRetries: 2
RetryTime: 60
WaitTime: 30
Context: test-background2
Extension: s
Set: FileName=test_dialplan_background1
Archive: yes

Here’s my context in extensions.conf:
exten => s,1,Answer()
exten => s,2,Wait(15)
exten => s,3,Set(filename=${CUT(FileName,1)}.response)
exten => s,4,Set(newcount=0)
exten => s,5,Gotoif($[ $[ ${newcount} > 1] ]?test-background2,10,2:response)
exten => s,6(response),Background(caller_response)
exten => s,7,Set(newcount=$[${newcount} + 1])
exten => s,8,WaitExten(4)
exten => 3,1,Playback(appt_confirm)
exten => 3,2,System(/bin/echo “Key pressed is 3” >> /var/spool/asterisk/outgoing_done/${filename})
exten => 3,3,Hangup()
exten => 7,1,Playback(appt_cancel)
exten => 7,2,System(/bin/echo “Key pressed is 7” >> /var/spool/asterisk/outgoing_done/${filename})
exten => 7,3,Hangup()
exten => 9,1,System(/bin/echo “Key pressed is 9” >> /var/spool/asterisk/outgoing_done/${filename})
exten => 9,2,GoTo(test-background2,s,6)
exten => i,1,GoTo(test-background2,s,6)
exten => t,1,GoTo(test-background2,s,5)
exten => 10,1,Playback(caller_message)
exten => 10,2,Hangup()

Please help.

If you are using Analog lines you can’t, usually analog lines doen’t support answer supervision. Use Digital lines to do it or add some kind of pauses before the msg.

UK analogue lines mostly do support answer supervision. However if the line doesn’t support it and you enable it in chan_dahdi.conf, the call will appear never to be answered, so you need to ask you network operator if they offer polarity reversal answer supervision, and if so, enable it in chan_dahdi.conf.

Which property in chan_dahdi.conf sets answer supervision?

The first one with “answer” in its name. Note that this does not switch on answer supervision; that must be done by the network operator. What it does is cause Asterisk to wait for a particular type of answer supervision.

If the line doesn’t support answer supervision, is my AEX808 card from Digium useless for the purpose I am trying to achieve? I want make reminder calls to users and deliver messages upon answering the phone. I also want to tell the difference between a human answering the phone and leaving a voicemail.

Do I have to shift to sip phones to achieve this or can this be done with DAHDI?

This is a network operator issue, not a DAHDI one. Without answer supervision, you will have to resort to the various applications that attempt to detect, silence, speech, answering machines, etc.

SIP just pushes the problem back the ITSP, but the ITSP will almost certainly use an ISDN interface to the PSTN (as will all medium to large business users). Dahdi supports ISDN, but with different hardware.

I called my telephone provider but the customer service agents were unable to answer my question. I created a workaround for this problem by using the Backgrounddetect() application.

call file

Channel: DAHDI/G0/1234567890
MaxRetries: 2
RetryTime: 60
WaitTime: 30
Context: detect
Set: FileName=test-backgrounddetect2
Extension: s
Archive: yes

exten => s,1,Set(MACHINE=0)
exten => s,2,Answer()
exten => s,3,Wait(10)
exten => s,4,BackgroundDetect(silence/30, 1000, 300)
exten => s,5,NoOp(answering machine detected)
exten => s,6,Set(MACHINE=1)
exten => s,7,WaitForSilence(18000)
exten => s,8,Goto(answering-machine,s,1)

exten => talk,1,GotoIf($[${MACHINE}=1]?2:3)
exten => talk,2,Goto(answering-machine,s,1)
exten => talk,3,Goto(human,s,1)

The problem with this is that BackgroundDetect jumps to the talk extension before I pick up the call or going to the answering machine. I’ve modified the min parameter from 50 to100 to 300 but of no use. Why is it jumping to the talk extension within 5-10 secs? I’ve tried with 3 silence files - 5s,10s,30s.

How to play a sound file after user answers the call ??
I did
Channel: SIP/6000/1981
in var/spool/asterisk/outgoing/

after that in extension.conf

but sounds play before answering call and i want it works after answering call How I will do this

If the peer 6000 answers the call i.e. send 200 OK before actual end user does then there is noting you can do here.
Set sip debug on and check the SIP responses.

This is a six year old thread about using analogue lines; please start a new thread, next time.

As Satish says, if you are going through SIP and don’t get answer supervision at the right time, that is completely outside of the control of Asterisk.