Check if any of two extensions is busy


#1

hello.

I use two extensions for my own purpose : linphone on my computer (6001) and my smartphone (6002).
I want them both to ring when I get a call on 9000, but the caller to be redirected to the voicemail (busy) when any of 6001 or 6002 is busy.

Here is what I have in extensions.conf :

;call groups
;when 9000 numbers 6001 and 6002 both ring for 25 sec, first one to pick up get the call, otherwise then directed to voicemail
exten => 9000,1,GotoIf($[$["${DEVICE_STATE(SIP/6001)}" = "BUSY"] | $["${DEVICE_STATE(SIP/6001)}" = "INUSE"] | $["${DEVICE_STATE(SIP/6002)}" = "BUSY"] | $["${DEVICE_STATE(SIP/6002)}" = "INUSE"]]?busy:call)
exten => 9000,n(call),Dial(SIP/6001&SIP/6002,25)
exten => 9000,n,GotoIf($["${DIALSTATUS}" = "BUSY"]?busy:unavail)
exten => 9000,n(unavail),Voicemail(6001@work,u)
exten => 9000,n,Hangup()
exten => 9000,n(busy),VoiceMail(6001@work,b)
exten => 9000,n,Hangup()

I think I have two issues : first linphone always rings even when I am already online. It might be a hidden option of some sort for multi calls and I should get some info about it but I doubt it will ever return a “busy” signal from 6001.

The other issue is that the first GotoIf condition (by DEVICE_STATE) returns false no matter what. Maybe that’s because I use remote extensions ?

I am only directed to the busy voicemail when 6002 is busy and 6001 disconnected, but I am directed there by the second GotoIf condition (by DIALSTATUS). I would like this condition to be true also when 6002 is busy and 6001 is connected (just check if 6001 OR 6002 is busy).
Is it possible to check DIALSTATUS on two extensions at the same time ?
Or is there any other solution ?


#2

The chan_sip module has to be configured using the busylevel option on each device to know when it should respond back with busy for the device state.


#3

Thank you jcolp, unfortunately there is no such option in native SIP client on android, neither I could see in Linphone.

I modified my users.conf as such though :

[general]
hasvoicemail = yes
hassip = yes
hasiax = yes
callwaiting = yes
threewaycalling = yes
callwaitingcallerid = yes
transfer = yes
canpark = yes
cancallforward = yes
callreturn = yes
callgroup = 1
pickupgroup = 1
nat = yes
callcounter=yes

[template](!)
type=friend
host=dynamic
dtmfmode=rfc2833
disallow=all
allow=ulaw
context = work
busylevel=2

[6001](template)
fullname = kro computer
username = kroc
secret = ###SECRET###

[6002](template)
fullname = kro smartphone
username = kros
secret = ###SECRET###

but nothing changed.

However when I ring 9000 from my smartphone (and thus to it - 6002) it answers a busy signal to asterisk I can debug :

== Using SIP RTP CoS mark 5
    -- Called SIP/6001
    -- Called SIP/6002
    -- SIP/6002-00000007 connected line has changed. Saving it until answer for SIP/to-ovh-00000005
    -- SIP/6001-00000006 connected line has changed. Saving it until answer for SIP/to-ovh-00000005
    -- SIP/6001-00000006 is ringing
    -- SIP/6002-00000007 is ringing
    -- Got SIP response 486 "Busy here" back from ###.###.###.###:40306
    -- SIP/6002-00000007 is busy

The other device (6001 - my computer) continues ringing. Is there nothing I can do with this SIP response 486 “Busy here” on the asterisk side to stop the call on 6001 and redirect it to the voicemail ?


#4

Ah, so there’s no call up to either endpoint? If so then it’s not possible to know the endpoint is busy or won’t answer until a call is attempted to it. As for the Dial() behavior you ask for, this is the opposite of what most everyone wants/uses so it has not been implemented.


#5

so there’s no call up to either endpoint?

sorry I’m not sure I understand the question but it’s kind of a group that get called :

exten => 9000,n(call),Dial(SIP/6001&SIP/6002,25)

I understand that it might not be a common practice. However I was asking if it’s technically possible (and how), considering I’m brand new to asterisk :
at some point the call is made and asterisk gets a busy signal, and from my understanding of your explanation nothing has been implemented to catch this signal and trigger an action ? Is that so ?
On another hand this does work :

exten => 9000,n,GotoIf($["${DIALSTATUS}" = "BUSY"]?busy:unavail)

The only issue is that this does not seem to be apliable when calling more than one devices at once…


#6

There’s nothing built into the Dial application to do it. The behavior is that other calls continue to ring even if one is busy, until one answers or all respond in some negative fashion. This is the behavior that most individuals want. What you’ve talked about has come up once or twice over the years, but not often at all.

The only things that come to mind is to hack something together externally using AMI that monitors the call and when it sees that one is busy uses a ChannelRedirect to send the caller elsewhere or to modify app_dial and add the functionality.


#7

ok I get it !

Thank you again for your time and explanations :slight_smile:


#8

You could try using the ChanIsAvail application before your dial and check the result.

https://wiki.asterisk.org/wiki/display/AST/Application_ChanIsAvail

Especially with the ‘a’ and ‘s’ options to it.


#9

YES ! :smile:

after a bunch of tweakings it works :

;call groups
;when 9000 numbers 6001 and 6002 both ring for 25 sec, first one to pick up get the call

exten => 9000,1,ChanIsAvail(SIP/6001&SIP/6002,as) ; check if lines are busy
exten => 9000,n,NoOp(${AVAILSTATUS}) ; debug status
exten => 9000,n,GotoIf($["${AVAILSTATUS}" =~ "2"]?busy:call) ; 2 means busy, check and redirect
exten => 9000,n(call),Dial(SIP/6001&SIP/6002,25) ; ring both phones for 25 sec, then voicemail
exten => 9000,n(unavail),Voicemail(6001@work,u)
exten => 9000,n,Hangup()
exten => 9000,n(busy),VoiceMail(6001@work,b)
exten => 9000,n,Hangup()

there are some limits though, but it certainly has nothing to do with Asterisk. (android only sounds busy to SIP when currently calling with SIP)

Otherwise Perfect ! Big thank you !


#10

Hi. It seems that I also stumbled into a similar issue with yours. Thanks though I was able to sort it out. Just have a quick question on the flags you passed on the first line. What are the ‘as’ flags mean on

exten => 9000,1,ChanIsAvail(SIP/6001&SIP/6002,as) ; check if lines are busy


#11

options
a - Check for all available channels, not only the first one
s - Consider the channel unavailable if the channel is in use at all
t - Simply checks if specified channels exist in the channel list