Call redirection with ARI

Hello,

I am trying to use ARI to redirect a call from the stasis application into an IVR created by FreePBX on the same asterisk server. When trying to use “Local/3000@from-internal” (which works fine for channel creation https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+Channels+REST+API#Asterisk13ChannelsRESTAPI-originateWithId I get “Endpoint technology ‘Local’ does not match channel technology ‘SIP’”. Calling “SIP/3000@serverip” I get a NULL return, with nothing on the asterisk log, but the call is not redirected.
What is the proper way to do that?

Thanks,
Eyal.

If you are wanting to send the channel back into the dialplan at a specific point you can use the continue[1] operation.

[1] https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+Channels+REST+API#Asterisk13ChannelsRESTAPI-continueInDialplan

Yes, I know that. But I would like to simply redirect the channel. Is this supported?

Define “redirect”. It can mean different things to different people.

If you mean a protocol level redirect then there is a redirect[1] operation which in the case of SIP can send a 302 or a REFER. (But you can only redirect to something SIP using a URI obviously)
If you mean you want to create an outgoing call and have both legs talk to eachother then you would need to use originate[2] and bridge them.

[1] https://wiki.asterisk.org/wiki/display/AST/Asterisk+14+Channels+REST+API#Asterisk14ChannelsRESTAPI-redirect
[2] https://wiki.asterisk.org/wiki/display/AST/Asterisk+14+Channels+REST+API#Asterisk14ChannelsRESTAPI-originate

I am currently using originate and bridging the call, and it works. But I would better like to use redirect. I probably do not write the URI correctly. How should I format a URI to redirect a call coming from an external trunk? Should I use the external DID of the extension? Should I put the external server IP after the @ sign?

You still haven’t defined what you mean by redirect. Do you want to send a 302 or SIP REFER?

I am not sure what is the difference between REFER and a 302 message. As far as I know REFER seems to be what I need.

Then calling the redirect operation with SIP/@<host / IP address> should work. That will send a REFER back to the SIP device. However if you are using a Local channel in the mix (as was indicated by your initial comment) you can not use this. You have to have the SIP channel directly in ARI.

My scenario is this: A call comes from an external SIP trunk and is passed to a stasis application by the dial plan. After some operation with it (playing prompts, getting DTMF etc), the stasis application needs to redirect the call to an IVR created by FreePBX, which has a local extension number. Is this possible?

Then you will need to use the ‘continue’ operation as I mentioned. This sends it out of ARI and into the dialplan at a specific position. If you want to keep it inside of ARI then you have to do what you’ve done, which is originate a Local channel into the dialplan and bridge them.

OK, thanks a lot for the advise. I’ll try the continue operation and update here.

Trying the “continue” operation, I get a very strange behavior Using this dial plan piece works. But when I uncomment the stasis call, although I exit the stasis, and receive the “Out of stasis” log line, the goto doesn’t work. Any idea?
exten => 0732951998,1,Log(“ERROR”,“Before stasis”)
; same => n,Stasis(KhlSystemBackupApp)
same => n,Log(“ERROR”,“Out of stasis”)
same => n,Goto(from-internal,3000,1)
same => n,Log(“ERROR”,“After goto”)
.

How doesn’t it work? What does it do? Are you not specifying an extension/priority/context to continue? What does the console show?

That’s what is so frustrating - no error, just the call is hung up. On the console all I get is (the CDR warning appear in any case - not because of the stasis) :
[2016-10-13 15:40:05] WARNING[3380]: func_cdr.c:377 cdr_write_callback: CDR requires a value (CDR(variable)=value)
[2016-10-13 15:40:05] ERROR[114904][C-00026035]: Ext. 0732951998:1 @ from-Cellcom: “Before stasis”
[2016-10-13 15:40:05] ERROR[114904][C-00026035]: Ext. 0732951998:3 @ from-Cellcom: “Out of stasis”

Well, there is some info in the “full” log file. Bellow is the end of it. Seems it fails playback, but I have no idea why:

[2016-10-13 15:40:05] VERBOSE[114904][C-00026035] pbx.c: Executing [s@ivr-4:11] ExecIf(“SIP/CellcomSIP2-00027bfa”, “1?Background(custom/mainofficeivr_il)”) in new stack
[2016-10-13 15:40:05] VERBOSE[114904][C-00026035] file.c: <SIP/CellcomSIP2-00027bfa> Playing ‘custom/mainofficeivr_il.slin’ (language ‘he’)
[2016-10-13 15:40:05] VERBOSE[114904][C-00026035] pbx.c: Spawn extension (ivr-4, s, 11) exited non-zero on ‘SIP/CellcomSIP2-00027bfa’
[2016-10-13 15:40:05] VERBOSE[114904][C-00026035] pbx.c: Executing [h@ivr-4:1] Hangup(“SIP/CellcomSIP2-00027bfa”, “”) in new stack
[2016-10-13 15:40:05] VERBOSE[114904][C-00026035] pbx.c: Spawn extension (ivr-4, h, 1) exited non-zero on ‘SIP/CellcomSIP2-00027bfa’

Wow, I found the problem. When I issue a hangup operation from my stasis application on the channel after exiting, it causes the call to disconnect. This seems like non-logical. The call is not own anymore by the stasis application.

Certain operations do not currently have a restriction on them for being out of Stasis as it is safe to do the operation on them. Hangup is one of those, just like it’s safe to do a hangup from the CLI it’s safe to do it using ARI. If you feel strongly you can file an issue[1] and we can look at it.

[1] https://issues.asterisk.org/jira

Well, it seems illogical that I can perform an operation on a channel I do not own, but once I know that, it’s not a big deal to handle. Thanks again for the support - the exit and continue in dialplan works fine.

Hi,
I’m also having a problem with redirecting a channel with ARI. I read the discussion but I’m not sure what to do in my case- I have a channel in a stasis application and I want to use the ARI command (using ari4java library): “ari.channels().redirect(channelId, endpoint, new ARICallback{})” while the endpoint is: “SIP/conference@remote.server” for example, but I don’t see 302 and the stasis application continue running like nothing happen. I want the channel to redirect to this sip entity so we run another stasis application. What I’m doing wrong? Maybe I need to add something to extensions.conf?

Thanks for any help!