External Transfer via SIP Refer

Has anyone figured out a way to perform an external transfer utilizing SIP Refer? Twilio requires all external calls to be performed using a verified caller ID. But if I simply want to hand that call off as a transfer, they allow that through their SIP trunks using SIP Refer, but it seems the FreePBX doesn’t include those headers? I usually perform a call forward using a ring group and put the external number in the list of extensions to dial with the “#”. But in order for the call to not get rejected by Twilio, for using an unverified caller ID, I have to force the caller ID to one of the numbers I own through Twilio. I have no need or desire to see that call all the way through, it just needs transferred. It seems SIP Refer is the way to go, but I do not see a method to utilize it in FreePBX. Anyone have any ideas?

Asterisk does have a Transfer command, which will do a Refer if the call has already been answered, or a 302 redirect if not. FreePBX does not have any modules that generate Transfer, though it’s not hard to create custom dial plan to call it. For example, see

However, I hate losing control of the call and would try hard to avoid that if possible. With Asterisk Transfer, you can’t record the call and the CDR won’t show how long it lasted. Asterisk won’t know the busy status of the destination, to determine whether another call should be sent there. The transferred-to party may not know whether this is a business call and won’t be able to transfer it to or conference in another extension.

I no longer forward calls to mobile numbers. 4G and 5G coverage has improved greatly in the past few years and (at least in the places we go) mobile SIP apps work very reliably and with good voice quality. The callee knows the call is coming from the PBX and FreePBX can rewrite the CNAM, e.g. to show the customer’s name instead of Wireless Caller. The app is a regular extension and can transfer, conference, park, etc.

If you must forward as a mobile voice call, consider using a different trunking provider for those calls, e.g. AnveoDirect. Yes, the call will likely get a B attestation, which may be displayed by the mobile carrier as Possible Spam or even as Scam Likely. However, I assume that the callee is an associate who can be forewarned to ignore the alert.

I am aware of this and I am fine with losing this insight. It is not needed as this call is getting transferred to a third party answering service. They require the caller ID of the callee, not my number though. Performing the transfers that I was doing in my post, the caller ID has to reflect one of my numbers. The answering service needs the number of the customer calling in.

So I have done the following:
Created a custom dialing plan in extensions_custom.conf with the following:

[external-transfer-out]
exten => s,1,transfer(PJSIP/[10 digit external number here])

Then I created a custom destination, pointing to that custom dial plan:
Target: external-transfer-out,s,1

I set this as the fail over destination inside of a queue, for my testing purposes, I have the queue timeout after 1 second so it should push quickly to that. The call connects and I see in the asterisk logs:

  -- Executing [5000@ext-queues:59] GotoIf("PJSIP/Twilio-US2-Oregon-00000036", "1?external-transfer-out,s,1:,,") in new stack
    -- Goto (external-transfer-out,s,1)
 -- Executing [s@external-transfer-out:1] Transfer("PJSIP/Twilio-US2-Oregon-00000036", "PJSIP/[10 digit external number here]") in new stack
    -- Auto fallthrough, channel 'PJSIP/Twilio-US2-Oregon-00000036' status is 'UNKNOWN'

My call rings for a second, then is disconnected. I also do not see any logs on Twilios side for the transfer, just the originating call entry for my call going in. What am I missing here?

EDIT: I have also enabled the transfer option on the trunk on Twilio’s side:

You should check the transfer status. For debugging, you should also use “pjsip set logger on” to see the protocol interaction.

Did you mean caller, rather than callee. Callee’s don’t necessarily have caller IDs.

I mean if customer A calls into my PBX and I need to transfer to the answering service, I have to pass along the Caller ID of Customer A to that transfer. They need the number of the customer calling, not my verified caller ID number from my PBX.

Looking over the expanded logs, I do see a problem. Pastebin of result

It seems it is trying to send it as UDP/5060. I don’t even have that port or protocol enabled on my FPBX. I strictly use TLS/5061. So Twilio is returning bnack the 500 Server Error code because they would accept TLS/5061. I’m not sure where I would designate that for the REFER though?

It is expecting a full SIP URI: sip:user@domain.

The only reference to 5060 is from the provider, not from Asterisk.

If I am reading that correctly, it shows this REFER string in a SIP message being sent from my PBX to Twilio. So wouldn’t that be generating from Asterisk in this case? The contact is generated correctly along with route listed further in the message. Is there somewhere in Asterisk where I can specify this? It seems to be reverting to the default settings in this case.

There is a request from Asterisk to Twilio and the response from Twilio to Asterisk. It is the latter that has the 5060.

Addition: The REFER is being sent the URI specified in the Contact header provided by Twilio, which is correct, from the point of view of Asterisk, although questionable for Twilio. It is being sent over the existing TLS connection.

I think you need to specify the parameter of Transfer as PJSIP/sip:[email protected] but there may be subtleties. The documentation suggests that the PJSIP/ is optional

It appears your suggestion worked!

I updated my custom dial plan to reflect this:

[external-transfer-out]
exten => s,1,transfer(PJSIP/sip:+1[External Number Here]@[FQDN].pstn.umatilla.twilio.com:5061)

Call successfully transfers. Thanks for your input @david55!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.