Initiate Playback on SIP Refer before Dial

Can anyone tell me how to initiate a playback of a sound file when someone initiates a transfer or “REFER” message?

Call Flow:

  1. Incoming Call -> Answered
  2. Answeree transfers call to PSTN using a REFER message
  3. Initial Caller hears a sound file before the call is connected.

I can make this work on Invite messages with the following but need some help with the REFER call flow.

extensions_custom.conf
[outbound]
exten => _+1NXXNXXXXXX,1,Playback(SoundFile)
exten => _+1NXXNXXXXXX,2,Dial(SIP/${EXTEN}@gw_out_01)
exten => _+1NXXNXXXXXX,3,Hangup

Do you mean REFER or do you mean REFER/Replaces.

Your example should work for REFER. I’m pretty sure you would have to change the source code for REFER/Replaces.

This call flow is using Refer/Replaces.

Bump…

I believe this involves modifying code in Asterisk that is very difficult. I would suggest not proceeding on this route unless you are or have access to a programmer capable of reverse engineering complex, poorly documented, real time programs, doing some very tricky processing. There will be a masquerade, which is one of the most difficult concepts in the asterisk internals, and you are also dealing with code that has to cope with tracking the state of channels of different technologies and dealing with sending external invite/replaces, in some cases.

Incidentally, your subject is confusing. For REFER/Replaces, the Dial has already been done, at a time when only the phone has any idea that this is part of an attended transfer. The operation you want to prefix with the recording is a re-bridging of the call.

David thank you. I’d like to focus on the last part you mention.

“For REFER/Replaces, the Dial has already been done, at a time when only the phone has any idea that this is part of an attended transfer. The operation you want to prefix with the recording is a re-bridging of the call.”

Can you help me visualize this call flow, and what the differences are in functionality between REFER and Refer/Replaces?

Are you saying that in my instance:

A calls B
B calls C <–This is where the sound is being played
B Refers A to C <-- No sound here b/c the dial happened in the last step

What I want is:
A calls B
B transfers A to C
Prior to being connected to C, A hears a message

With REFER/Replaces:

A calls B
B answers
B’ sets up a completely distinct call to C; Asterisk has no idea this is related to the call from A to B; this is running the Dial() application
A tells B to connect to C and take over the call from B’ to C, which it identifies using the Replaces parameter

In your case, Asterisk is proxying for A, so this is an internal re-arrangement in Asterisk

With a a pure REFER

A calls B
B answers
B tells A to connect to C
A makes a new call to C

In the second scenario where A calls C, this happens through Asterisk yes? So A would hear the recording?

It happens through the dialplan, so playbacks in the dialplan will work.

However, it is possible that some phones implement blind transfers, which this is, by using the attended transfer procedure.

Also, for this case, A should hear ringback tone, so they will know something is happening.