Transfer channel from one asterisk to another without hang up

Hi all,

I am trying to transfer a live channel from Asterisk 1 to Asterisk 2 using SIP REFER, so that the customer stays connected while the call moves to Asterisk 2.

Setup:

  • Asterisk 1: Incoming call from customer (PJSIP).

  • Asterisk 2: Agent endpoint where the call should be transferred.

  • Channel control: Using ARI (Node.js).

What I tried:
await ari.channels.redirect({
channelId: ‘customerChannelId’,
endpoint: ‘PJSIP/asterisk2-trunk’
});

asterisk2-trunk is defined in pjsip.conf on Asterisk 1 with an AOR pointing to Asterisk 2’s IP.

Problem:

  • REFER logs show:
REFER sip:+91XXXXXXXXXX@192.168.24.16:49868 SIP/2.0
  • .16 is not Asterisk 2’s IP (.106) — it’s the contact of the customer channel.

  • The REFER fails with 503 Service Unavailable.

pjsip.conf is having this:

[asterisk2-trunk]
type=endpoint
transport=transport-udp
context=customer_call
disallow=all
allow=ulaw
auth=asterisk2-trunk
aors=asterisk2-trunk
;direct_media-=no
allow_transfer=yes

[asterisk2-trunk]
type=aor
contact=sip:192.168.24.106:5060

customer_call => is defined in pjsip.conf of asterisk 2 as well

You need to show an actual full SIP trace to be certain but:

That’s how it works. A blind transfer REFER is sent to the endpoint, with the request URI being the endpoint. The target they are supposed to go to is in the “Refer-To” header. It’s up to the endpoint whether they can/will do that.

Are you sure you actually want to use REFER? I’m not sure, from you full description, whether what you really want to do is what Asterisk would do if it received a REFER from the first agent’s phone.

If one really wanted to follow the spirit of ARI, you would allocate and dial the new channel, and reconfigure the bridging, but I think you could also “continue” to dial plan that called through the tie line.

(There seems to be a poor choice of naming in ARI, in that it uses channels.redirect for what is called transfer iin older APIs, and the older APIs use redirect for the operation I think you are trying to do.)

what i want to do exactly is that:
I have two asterisk servers one channel on each asterisk (a customer and an agent).Now i want to transfer the agent channel to customer channel asterisk without hanging up the agent channel.

I am currently creating a new channel from customer channel asterisk to agent channel asterisk being a mediator channel which will be on both the asterisk (2 channels one on each asterisk), adding this mediator channel to both the customer and agent bridges to have RTP flow. But this is using two extra channels and 1 extra bridge as if both the customer and agent should have been on a single asterisk they would be using a single bridge and a total of 2 channels.
And i want to have only 2 channels and 1 bridge.

Note: I am having multiple asterisk server need the above to balance the load but still patch customer and agent without adding any extra resources (double being used while dialing a new channel).

the refer is being sent to the wrong endpoint here 192.168.24.16, the correct endpoint is 192.168.24.106 which i have mentioned in the pjsip.conf contact.
how and where to set that “Refer-To” header ?

This sounds like an attended transfer, in which case there is no support for doing this.

The nearest you might get to it is to use direct media on the agent phone and tie line, but you are almost certainly making the call in a way that conflicts with direct media. (Note I’m not an ARI expert, and don’t know how ARI interacts with direct media. You will still have the same number of channels, but if it work, the high volume media will go direct from the agent phone to the customer facing Asterisk.

(Whilst I think initiating attended transfers has been added to Asterisk, any API will be in terms of a reference to the channel, which only has local meaning. It is possible that the API that does exist is dialplan only, but the first point means it won’t help to move to dialplan.)

Okay, there are two terms here — the session (the phone call on the agent’s phone) and the channel (the Asterisk channel). Is there a way to keep the session (phone call) active even if the Asterisk channel hangs up and a new one is originated on another Asterisk server?

The only capability is redirect, which is a SIP REFER as a blind transfer that tells the phone itself to go elsewhere (place a new call to the given target) and if you want any further comment on that, you’d need to actually provide a SIP trace as well as what the channel redirect is invoked on is.

It hasn’t been added for this purpose. The ARI functionality is for handling INCOMING blind and attended transfers from endpoints, not for arbitrarily initiating them outbound.

I am doing this to be precise:
added this endpoint in my pjsip.conf

[asterisk2-trunk]
type=endpoint
transport=transport-udp
context=transfer_from_ast_1
disallow=all
allow=ulaw
auth=asterisk2-trunk
aors=asterisk2-trunk
;direct_media-=no
allow_transfer=yes

[asterisk2-trunk]
type=aor
contact=sip:192.168.24.106:50369

using this in my ari nodeJs app to redirect the channel:
await ari.channels.redirect({channelId: agentChannelId, endpoint: ‘PJSIP/asterisk2-trunk’}, function (err) {});

This is what i have received in logs:

<— Transmitting SIP request (749 bytes) to UDP:192.168.24.16:49868 —>
REFER sip:+919988990000@192.168.24.16:49868;did=5da.bb6f93d7 SIP/2.0
Via: SIP/2.0/UDP 192.168.24.44:49868;rport;branch=z9hG4bKPjff4fc23d-e543-4c18-96bc-9171cf4a49e1
From: sip:+911246561141@192.168.24.16;tag=f32d51a9-62c7-42e7-9b67-3dcccad2dfe7
To: sip:+919988990000<@192.168.24.16>;tag=uc3245F680
Contact: sip:asterisk@192.168.24.44:49868
Call-ID: 5c90b551-e553-4f8a-b543-2f1c784adeb0
CSeq: 19388 REFER
Event: refer
Expires: 600
Supported: 100rel, timer, replaces, norefersub
Accept: message/sipfrag;version=2.0
Allow-Events: presence, dialog, message-summary, refer
Refer-To: sip:192.168.24.106:50369
Referred-By: sip:asterisk@192.168.24.16
Max-Forwards: 70
User-Agent: Asterisk PBX certified/16.8-cert3
Content-Length: 0

<— Received SIP response (446 bytes) from UDP:192.168.24.16:49868 —>
SIP/2.0 500 Service Unavailable
Via: SIP/2.0/UDP 192.168.24.44:49868;received=192.168.24.44;rport=49868;branch=z9hG4bKPjff4fc23d-e543-4c18-96bc-9171cf4a49e1
Call-ID: 5c90b551-e553-4f8a-b543-2f1c784adeb0
CSeq: 19388 REFER
From: sip:0091124656<1141><@10.60.65.26>;tag=f32d51a9-62c7-42e7-9b67-3dcccad2dfe7
To: sip:+919988990000<@10.60.65.26>;tag=uc3245F680
Contact: sip:+919988990000<@192.168.24.16:49868;did=5da.bb6f93d7>
Content-Length: 0

What can be the reason for this 500 service unavailable ?

Asterisk sent a SIP REFER to 192.168.24.16

It was told that it should transfer the call to “sip:192.168.24.106:50369”

It responded 500 Service Unavailable as you see

It gives no indication as to why so I can’t say why

Asterisk did exactly as you told it to and what it is written to do, a blind transfer was attempted and then rejected by the remote side

what can be the possible reasons for the rejection ? what can i check on opensip or my second asterisk ? “.16” is my opensip server and “.106” is my second asterisk server.

I don’t have any experience with OpenSIPS so I don’t have anything extra to add in that regard. I can say, though, that you didn’t specify an extension in the transfer.

Where is OpenSIPS mentioned?

I don’t see anything, other than that the request is coming from a private network address, to suggest that the call is arriving other than through an ITSP, in which case they may well have a policy of not supporting REFER, and if they do support it, they will almost certainly charge you for a call between your two systems.

However, to meet your requirement for retaining the original call, you are going to need to do an attended transfer. At the time that I was actively involved with the Asterisk code, there was no API that would allow the initiation of an attended transfer. I thought I’d seed references to support subsequently being added, but checking the code now, I can’t find any relevant changes to the transfer application.

Where I was working at the time, we did implement extensions to the Transfer application, and chan_sip, to allow attended transfers, but we were already locked into an old version of Asterisk, and In any case I no longer have the code, so it is not possible to contribute that now. That code used the channel name to identify the replaced channel.

However, as your upstream system is refusing even a blind transfer, it is not going to accept an attended one. If you do the transfer on the agent Asterisk, you have even more problems: the provider is even less likely to accept INVITE/Replaces, than it is to accept the REFER/Replaces, that would be needed to do it from the customer facing Asterisk side (and it isn’t even accepting a simple REFER); and you would need to communicate the call ID and tags, from the customer Asterisk, to agent Asterisk, as the replaced channel name would have no meaning to it. There has never been an API for requesting Asterisk to generate an INVITE/Replaces,

As such, you need to analyse what the real problem you are trying to solve is, and see if you can go part way to solving that. In an earlier response, I suggested your main concern might be the processor load and network load, in which case direct media may help. However, there is no guarantee that the upstream system will accept direct media re-INVITEs, and direct media means that there are various Asteirsk features that you cannot use, because they require Asterisk to see the media stream.

I interpreted that to mean OpenSIPS.

OK. I did the text search including the final “s”.