Discussion:
[asterisk-users] Prevent Dial if any extension is busy
Magnus Benngård
2009-11-22 13:15:35 UTC
Permalink
Hi!

Part of extensions.conf:

exten => 985,1,Dial(SIP/0317998985&H323/***@Avaya,20)
exten => 985,2,Goto(985-${DIALSTATUS},1)
exten => 985-BUSY,1,VoiceMail(***@inputinterior.se,b)
exten => 985-BUSY,2,PlayBack(vm-goodbye)
exten => 985-BUSY,3,HangUp()
exten => 985-NOANSWER,1,VoiceMail(***@inputinterior.se,u)
exten => 985-NOANSWER,2,PlayBack(vm-goodbye)
exten => 985-NOANSWER,3,HangUp()

0317998985 is a direct connected SIP phone
0702221448 is a celluar phone.

When dialing 985 both phones rings, perfect
If none answer within 20 seconds,
VoiceMail(***@inputinterior.se,u), perfect

But my problem comes when I speak on 0317998985 and someone calls on 985,
the call
get to my celluar phone and ofc the other way around.

Is there a way to check if any extension is busy and in that case jump to
VoiceMail(***@inputinterior.se,b)?

Med vÀnliga hÀlsningar
MAGNUS BENNGRD

Direktnr 031-799 89 75

FÀltspatsgatan 2
421 30 VÀstra Frölunda

Tel. 031-799 89
00
Fax 031-799 89 01

www.inputinterior.se [1]

Links:
------
[1] http://www.inputinterior.se
Leif Neland
2009-11-22 14:38:00 UTC
Permalink
Post by Magnus Benngård
Hi!
exten => 985,2,Goto(985-${DIALSTATUS},1)
exten => 985-BUSY,2,PlayBack(vm-goodbye)
exten => 985-BUSY,3,HangUp()
exten => 985-NOANSWER,2,PlayBack(vm-goodbye)
exten => 985-NOANSWER,3,HangUp()
0317998985 is a direct connected SIP phone
0702221448 is a celluar phone.
When dialing 985 both phones rings, perfect
If none answer within 20 seconds,
But my problem comes when I speak on 0317998985 and someone calls on
985, the call
get to my celluar phone and ofc the other way around.
Is there a way to check if any extension is busy and in that case jump
If both phones were directly connected sip, it could be done.
The problem is that you can't determine if the cellular is busy before
you call it.

If the cell was only called via asterisk, you could set a flag, when
asterisk called extension 985, and clear it, when hanging up, but I
guess the phone is used for call out via regular cell service, and also
called directly on its own number.


You don't own the cell-company, and can setup an API to get the status
of the cell, right? I didn't think so :-)

You could do this:
check if sip is busy, using ChanIsAvail

If so, go to voicemail.
Else, dial cell, timeout 20 sec
if busy go to voicemail
else dial sip, timeout 20 sec
if not answered. go to voicemail.

But this will give 20 seconds delay before sip rings, and 40 seconds
timeout for the caller before voicemail.

The other option is to modify the source, and add an option to the
dial-command, to exit if any extension dialled is busy.
After all, this is open source :-)

Leif
Magnus Benngård
2009-11-22 15:13:36 UTC
Permalink
On Sun, 22 Nov 2009 15:38:00 +0100, Leif Neland wrote: Magnus Benngård
skrev: Hi!

Part of extensions.conf:

exten => 985,1,Dial(SIP/0317998985&H323/***@Avaya,20)
exten => 985,2,Goto(985-${DIALSTATUS},1)
exten => 985-BUSY,1,VoiceMail(***@inputinterior.se,b [1])
exten => 985-BUSY,2,PlayBack(vm-goodbye)
exten => 985-BUSY,3,HangUp()
exten => 985-NOANSWER,1,VoiceMail(***@inputinterior.se,u [2])
exten => 985-NOANSWER,2,PlayBack(vm-goodbye)
exten => 985-NOANSWER,3,HangUp()

0317998985 is a direct connected SIP phone
0702221448 is a celluar phone.

When dialing 985 both phones rings, perfect
If none answer within 20 seconds, VoiceMail(***@inputinterior.se,u
[3]), perfect

But my problem comes when I speak on 0317998985 and someone calls on 985,
the call
get to my celluar phone and ofc the other way around.

Is there a way to check if any extension is busy and in that case jump to
VoiceMail(***@inputinterior.se,b [4])?
If both
phones were directly connected sip, it could be done.
The problem is that you can't determine if the cellular is busy before
you call it.

If the cell was only called via asterisk, you could set a flag, when
asterisk called extension 985, and clear it, when hanging up, but I guess
the phone is used for call out via regular cell service, and also called
directly on its own number.

You don't own the cell-company, and can setup an API to get the status of
the cell, right? I didn't think so :-)

No i dont own the cell-company but they route the cell-call to my main
Avaya pbx and the Avaya route it back (with a new b-number) so I have
pretty much control over the cell-call.
Just have to route it to my Asterisk and set the flag there, will do some
reading and figure out how.

You could do this:
check if sip is busy, using ChanIsAvail

I am running Asterisk SVN-branch-1.6.2-r230384 so I thougt i can do
something like:
(For checking if I am talking on the SIP phone)

exten =>
985,1,GotoIf($["${DEVICE_STATE(SIP/0317998985)}"="BUSY"]?11)
exten => 985,2,Dial(SIP/0317998985&H323/***@Avaya,20)
exten => 985,3,Goto(985-${DIALSTATUS},21)
exten => 985,4,HangUp()
exten => 985-BUSY,11,VoiceMail(***@inputinterior.se,b)
exten => 985-BUSY,12,PlayBack(vm-goodbye)
exten => 985-BUSY,13,HangUp()
exten => 985-NOANSWER,21,VoiceMail(***@inputinterior.se,u)
exten => 985-NOANSWER,22,PlayBack(vm-goodbye)
exten => 985-NOANSWER,23,HangUp()

But there is something wrong with the first line, tried "INUSE" aswell.
When I place a call from 0317998985 and some1 call 985, the call goes to
the cell phone. :(
Can any1 se what I am doing wrong?

If so, go to voicemail.
Else, dial cell, timeout 20 sec
if busy go to voicemail
else dial sip, timeout 20 sec
if not answered. go to voicemail.

But this will give 20 seconds delay before sip rings, and 40 seconds
timeout for the caller before voicemail.

The other option is to modify the source, and add an option to
the
dial-command, to exit if any extension dialled is busy.
After all, this is open source :-)

Leif



Links:
------
[1] mailto:***@inputinterior.se,b
[2] mailto:***@inputinterior.se,u
[3] mailto:***@inputinterior.se,u
[4] mailto:***@inputinterior.se,b
Leif Neland
2009-11-30 08:51:53 UTC
Permalink
Post by Leif Neland
Post by Magnus Benngård
But my problem comes when I speak on 0317998985 and someone calls on
985, the call
get to my celluar phone and ofc the other way around.
Is there a way to check if any extension is busy and in that case
If both phones were directly connected sip, it could be done.
The problem is that you can't determine if the cellular is busy before
you call it.
...
The other option is to modify the source, and add an option to the
dial-command, to exit if any extension dialled is busy.
After all, this is open source :-)
Leif
I think a modification should be done around here to return busy if just
one channel was busy (only enabled if an option on dial is set)
in asterisk-1.6.0.15/apps/app_dial.c, line 610

Is somebody willing to try?

while (*to && !peer) {
struct chanlist *o;
int pos = 0; /* how many channels do we handle */
int numlines = prestart;
struct ast_channel *winner;
struct ast_channel *watchers[AST_MAX_WATCHERS];

watchers[pos++] = in;
for (o = outgoing; o; o = o->next) {
/* Keep track of important channels */
if (ast_test_flag64(o, DIAL_STILLGOING) && o->chan)
watchers[pos++] = o->chan;
numlines++;
}
if (pos == 1) { /* only the input channel is available */
if (numlines == (num.busy + num.congestion + num.nochan)) {
ast_verb(2, "Everyone is busy/congested at this time
(%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
if (num.busy)
strcpy(pa->status, "BUSY");
else if (num.congestion)
strcpy(pa->status, "CONGESTION");
else if (num.nochan)
strcpy(pa->status, "CHANUNAVAIL");
} else {
ast_verb(3, "No one is available to answer at this time
(%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
}
*to = 0;
return NULL;
}

Preferably, either the dialcommand should be preceeded with a
ChanIsAvail on the sip first, as there is no need to place a toll-call
to the cell if the sip is busy. Or the dialcommand itself should have an
option to delay one or more of the calls in the dialstring
(Dial(Technology/resource[&Tech2/resource2...]). But this would probably
be too messy...


Leif
Benny Amorsen
2009-11-30 09:25:37 UTC
Permalink
Post by Leif Neland
I think a modification should be done around here to return busy if just
one channel was busy (only enabled if an option on dial is set)
in asterisk-1.6.0.15/apps/app_dial.c, line 610
That is doable, but it can result in a bad experience for the caller.
The Dial() is likely to indicate progress to the caller, which means
that the caller will hear the familiar "dialing" tone (By the way, is
there a dictionary of the names for the various telecoms tunes?). Right
afterwards they will hear the busy tone, as if the callee rejected the
call.

It is best not to send a busy tone once you have indicated that the call
is on the way to being connected -- unless you're trying to get rid of a
telemarketer.


/Benny
Leif Neland
2009-11-30 13:58:18 UTC
Permalink
Post by Leif Neland
I think a modification should be done around here to return busy if
just one channel was busy (only enabled if an option on dial is set)
in asterisk-1.6.0.15/apps/app_dial.c, line 610
Is somebody willing to try?
while (*to && !peer) {
struct chanlist *o;
int pos = 0; /* how many channels do we handle */
int numlines = prestart;
struct ast_channel *winner;
struct ast_channel *watchers[AST_MAX_WATCHERS];
watchers[pos++] = in;
for (o = outgoing; o; o = o->next) {
/* Keep track of important channels */
if (ast_test_flag64(o, DIAL_STILLGOING) && o->chan)
watchers[pos++] = o->chan;
numlines++;
}
Adding this here
if (num.busy) {
strcpy(pa->status, "BUSY");
*to = 0;
return NULL;
}
Seems to work
Post by Leif Neland
if (pos == 1) { /* only the input channel is available */
if (numlines == (num.busy + num.congestion + num.nochan)) {
ast_verb(2, "Everyone is busy/congested at this time
(%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
if (num.busy)
strcpy(pa->status, "BUSY");
However, I tried adding an option OPT_SINGLE_BUSY after these:

#define DIAL_STILLGOING (1 << 31)
#define DIAL_NOFORWARDHTML ((uint64_t)1 << 32) /* flags are now 64
bits, so keep it up! */
#define OPT_CANCEL_ELSEWHERE ((uint64_t)1 << 33)
#define OPT_PEER_H ((uint64_t)1 << 34)
#define OPT_SINGLE_BUSY ((uint64_t)1 << 35)

but all these constants have the value zero!

I'm compiling on FreeBSD, asterisk seems to work anyway...

Whats going on?

Leif
Leif Neland
2009-11-30 14:33:53 UTC
Permalink
Post by Leif Neland
#define OPT_PEER_H ((uint64_t)1 << 34)
#define OPT_SINGLE_BUSY ((uint64_t)1 << 35)
but all these constants have the value zero!
I'm compiling on FreeBSD, asterisk seems to work anyway...
Whats going on?
doh... 64 bits doesn't fit in %d
%llu works better.

Leif

Loading...