SendDTMF after first and second time answered

I’m using SIP named MKY,
it’ll play a message to inform you how many minutes you have in this account after dialing,
so I did exten=>_0XXXXXXXXX,1,Dial(sip/mky/${EXTEN},20,D(#)) to cancel this message (by send DTMF #).
However, I want to sendDTMF after the real number which I want to call answered (to implement PSTN extension number),
so I add a macro

exten=>_0XXXXXXXXX,1,Dial(sip/mky/${EXTEN},20,M(ext))
[macro-ext]
exten=>s,1,Answer()
exten=>s,n,SendDTMF(#)
exten=>s,n,Wait(10)
exten=>s,n,SendDTMF(123)

it will sendDTMF(#) after first time answered, wait 10secs and then sendDTMF(123).
I want to replace Wait(10 with function to detect answer tone.
My question is whether Asterisk can detect second answer tone and send DTMF?
If so, how?

Thank you.

The Answer in your macro does nothing useful, as the outgoing side is already up. (Many uses elsewhere are inappropriate, too.)

What do you mean by answer tone? The only use I know for that term only applies to (fax) modems.

I am not aware of any specific tone detection dialplan applications, except for DTMF. Depending on exactly what happens, you might be able to use answering machine detection or silence detection ones.

As far as Asterisk is concerned, and for that matter the PSTN, the call is answered when the receiving system goes off hook. Anything after that is part of the call for all but the receiving system.

Thank you,
It seems the second answer only go through RTP,
so Asterisk cannot detect it.
Answer machine detection looks useful, I’m going to read it.