Summary:ASTERISK-09779: Application and function to determine existence of extensions but not jump to it yet
Reporter:David Chappell (chappell)Labels:
Date Opened:2007-06-28 12:05:17Date Closed:2007-08-30 10:06:41
Versions:Frequency of
Environment:Attachments:( 0) app_readexten.c
( 1) app_readexten.c
( 2) func_isexten.c
Description:Attached are a new dialplan command (application) and a new dialplan function.

The command ReadExten works much like Read.  However, instead of simply accepting digits until an inter-digit time runs out, it tests the dialed digits against a specified context and returns when it determines that a number valid in that context has been dialed.

The function ISEXTEN determines whether a given context, extension, and priority exist or not.

We use this new features in a calling-card IVR.  It invites the caller to dial a number.  When a valid number is detected, it plays "connecting..." and jumps to the context, like so:

exten => s,1,Answer

; Let the user dial a number in this context.
exten => s,n(repeat),ReadExten(number,custom/system-access-dial-extension,,n)
exten => s,n,GotoIf(${ISNULL(${number})}?i,1)

; Dispatch non-extension menu items.
exten => s,n,GotoIf(${ISEXTEN(phones,${number})}?:phones,${number},1)

; Put thru call to the dialed extension.
exten => s,n,Verbose(2,${CALLERID(all)} (${CDR(accountcode)}) dialed ${number})
exten => s,n,Background(custom/system-access-connecting,noanswer)
exten => s,n,Dial(Local/${number}@ivr-system-access-extensions/n,,Hg)

; Call ended.  Go bad so that the user can dial again.
exten => s,n,Verbose(2,${CALLERID(all)} (${CDR(accountcode)}) ended call to ${number})
exten => s,n,Goto(s,begin)

exten => 1,1,Playback(option-one)
exten => 1,n,Hangup

exten => i,1,Playback(custom/system-access-invalid-extension)
exten => i,n,Goto(s,repeat)

include => phones

Comments:By: David Chappell (chappell) 2007-06-28 13:58:44

I have uploaded both files, but only one of them shows under "Attached Files".  I have tried to uploaded it again, but that does not work since I am required to remove the 'old one' before uploading the new one.

By: Joshua C. Colp (jcolp) 2007-07-02 09:30:52

Your files will become viewable once your license is accepted. Also - you can use ChanIsAvail with the Local channel driver to see whether an extension in a context exists or not.

By: Tilghman Lesher (tilghman) 2007-07-02 23:49:39

What does it do on ambiguous extensions?

For example, if both '2' and '201' are valid extensions, what happens when you press '2'?

By: Tilghman Lesher (tilghman) 2007-07-08 22:18:15

Okay, now that your license has been approved, I have an answer to my question:  it'll continue to wait, but if the user enters no more digits within digit_timeout, it will return a valid result.

One thing I don't think is entirely desireable is your autojump code in the resolution of invalid or timeout extensions.  The suggested method for these exceptions is to set a status channel variable.  I'd suggest a name such as READEXTENSTATUS with possible values of "OK", "TIMEOUT", or "INVALID".

Also, you have a few formatting issues (like spaces in several places where there should be a tab, "if(", and a few others).  See the coding guidelines.

Finally, unless you've intended to assign copyright to Digium, you should probably change the copyright to yourself, as the standard license is not a assignment of copyright.

On the whole, it's a good start, and I'm happy to see this go in once the criticisms are addressed.

By: David Chappell (chappell) 2007-07-19 11:03:03

I think the file upload system may be a little buggy.  One file was visible and the other not.  There was no indication that this was deliberate.

I will correct the problems which you have identified and resubmit.

About the auto-jumping: You are right of course, but I may have a simpler way to do it.  ReadExten() was created by hacking Background().  I intend it to act like Background() in the sense that it collects digits and tests them against a specified extension, but unlike Background() it should leave the jumping to the caller.  I am not sure we need READEXTENSTATUS since we already have a variable for returning the result.  Why not return "i" for invalid and "t" for timeout.  That way the sequence:

exten => s,n,ReadExten(number,dial-extension,target-context)
exten => s,n,Goto(target-context,${number},1)

does exactly the same thing as:

exten => s,n,Background(dial-extension,,,target-context)

In other words, ReadExten() would return the extension to which Background() would have jumped.  This may be a special extension.

By: Tilghman Lesher (tilghman) 2007-07-19 16:52:37

While that sounds very clever, I think we'd prefer if you set a status variable.

If you did go ahead and set the variable to the strings 't' or 'i' anyway (which you're certainly welcome to do, in addition to setting a status variable), you should also set INVALID_EXTEN to the extension entered.

By: Digium Subversion (svnbot) 2007-08-30 10:06:41

Repository: asterisk
Revision: 81378

r81378 | tilghman | 2007-08-30 10:06:40 -0500 (Thu, 30 Aug 2007) | 2 lines

Add ReadExten app and VALID_EXTEN function (closes issue ASTERISK-9779)