Later, Asterisk receives a SIP REFER from B instructing it to call 1234567.
The behavior we would like is:
Put call A on hold
Create a new outgoing call to 1234567
Allow B to speak with 1234567
After B hangs up, automatically bridge A with 1234567
In other words, we want to convert an incoming REFER from the trunk into a supervised/attended transfer, where the original call (A) is only released after the new call (to 1234567) is answered and B disconnects.
If the Asterisk dial options for the trunk to B includes ‘t’, party B can dial *2 (attended transfer), hear dial tone from the PBX that received the call from A, dial 1234567 and speak with them. When B hangs up, A will be bridged to 1234567.
If B is using a (different) PBX that intercepts *2 locally, you would need to change the attended transfer code at one end or the other.
If the above is unsuitable, please describe the scenario and constrants (cost, latency, etc.) and maybe we can find an easy solution; changing REFER behavior is not easy, especially if it needs to survive FreePBX and Asterisk version upgrades.
REFER always completes the transfer (if possible); the enquiry stage of an attended transfer is just an outgoing call on a second line, and no REFER has been issued at that stage. That stage needs to be completed before any REFER is issued, and the REFER needs to include a Replaces line, to identify the other phone line (REFER can be issued on either the line from A, in which case Replaces identifies that to 1234567, as seen from the PABX end, or it could be issued to line to 1234567, replacing the line to A;