Asterisk as phone number verification system

RobertChanphakeo
RobertChanphakeo used Ask the Experts™
on
Customising asterisk/Elastix as a IVR phone number verification system: I would like to know which modules should be installed and which files to modify to perform 1 of or all 3 of the following scenarios)

Scenario 1:
1) User enters phone number and submits form via web application (ex 61401234567)
2) Web application sends user's phone number and a random generated 3 digit code to [asterisk] PBX system
3) Web application displays random generated 3 digit code on screen - (created in step 2).
4) System dails-out user's phone number
5) System prompts user for 3 digit phone number verification code via  IVR (Interactive Voice Response).
6) User enters the phone number verification code via phone keypad as it shown on screen (in step 3).
7) System CheckVerifactionCode match original random code that was generated by the web application.
8) System returns response "success" or "failed" via  IVR (Interactive Voice Response) and notify's the web application.
9) System hangs up the call.
10) Web application displays "success" or "failed" response on user's screen.

Scenario 2:
1) User enters phone number and submits form via web application (ex 61401234567)
2) Web application sends user's phone number to [asterisk] PBX system
3) System dails-out user's phone number
4) System generates 3 digit random code and repeats digit over phone speaker 5 times before hanging up.
5) User enters 3 digit random code into web application page
6) Web application CheckVerifactionCode match original random code that was generated by the system.
7) Web application displays "success" or "failed" response on user's screen.

Scenario 3:
1) User enters phone number and submits form via web application (ex 61401234567)
2) Web application displays PBX phone number for user to call
3) User calls PBX phone number as displayed on screen
4) System checks user's caller ID and hangs up the call
5) System notify's the web application match the original user's inputted phone number
6) Web application displays "success" or "failed" response on user's screen.
(Does not work for private numbers).
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Information Services Manager
Commented:
Yes of course Asterisk can do this.

Programming your web page (I use ASP.net), to submit a packet to Asterisk Manager API, you can call Originate().  To turn the manager interface on edit "manager.conf".

You can use the Asterisk AMI to dial the number, when answered...send the call to an ivr to ask the user to enter the code, ....then write to a database, or raise an AMI event, or write a file, or whatever... if it the code they entered was a success.  If it wasn't a success, then you could do something else...

I would suggest using MySQL as well as having the MySQL Asterisk-addon loaded for Asterisk.


Example manager packet...(this packet logs in and uses originate)
To test, you can open notepad, paste this code, save the text file on your C drive, then use NetCat to test it from command line. (commandline: nc.exe 192.168.6.1 5038 < testManager.txt)
--------------------begin,
action: login
username: admin
secret: secrets
events: off

Action: Originate
Channel: Zap/g2/2123234340
Context: ivr-1
Exten: s
Priority: 1
Callerid: 2123234340
Timeout: 10000
Variable: funcUserRegNum=2123234340|funcUserNameEmail=newuser1@yourdomain.com|funcUserCode=123

-------end packet...(the last two CrLF are needed)

--------------------------------------------------------------------------------
I form this packet in asp.net with the following function.
This function would be called during the
--------------------------------------------------------------------------------
Public Function funcOriginate(funcUserRegPhoneNumber as string, byval funcUserNameEmail as string,byval funcUserCode as string)

Dim success as boolean = false

Dim astmLoginAction as string = "action: login" & vbCrlf
Dim astmUser as string = "username: " & MyAstmUsername & vbCrlf
Dim astmSecret as string = "secret: " & MyAstmSecret & vbCrlf
Dim astmEventOption as string = "events: off" & vbCrlf & vbCrlf

Dim astmAction as string = "Action: Originate" & vbCrlf
Dim astmChannel as string = "Channel: Zap/g2/" & funcUserRegPhoneNumber & vbCrlf
Dim astmContext as string = "Context: " & funcIVRname & vbCrlf
Dim astmExten as string = "Exten: s" & vbCrlf
Dim astmPriority as string = "Priority: 1" & vbCrlf
Dim astmTimeout as string = "Timeout: 10000" & vbCrlf
Dim astmVariables as string = "Variable: funcUserRegNum=" & funcUserRegPhoneNumber & "|funcUserNameEmail=" & funcUserNameEmail & "|funcUserCode=" & funcUserCode & vbCrlf & vbCrlf

Dim myAstmPacket as string = astmLoginAction & astmUser & astmSecret & astmEventOption & astmAction & astmChannel & astmContext & astmExten & astmPriority & astmTimeout & astmVariables

success = true
Try
'{code to open a tcpclient connection and send the packet as data.
Catch ex as exception
Log(ex.message)
End Try

Return success

End Function

--------------------------------------------------------------------------------
Below example context extensions.conf
--------------------------------------------------------------------------------
[ivr-1]

exten => s,1,Answer()
exten => s,n(start),Playback(greetingmessage.gsm)
exten => s,n,Read(EnteredCode,,4)
exten => s,n,GosubIf($[${EnteredCode} <> ${funcUserCode}]?start)
exten => s,n,NoOp(Code passed for ${funcUserNameEmail})
exten => s,n,MySQL(;------------------------------------------sql stuff

Author

Commented:
solution: untested.

Author

Commented:
I used Asterisk Manager

If I do this...

Action: Originate
Channel: SIP/100
Callerid: Unknown
Exten: 101
Priority: 1
Timeout: 60000
Context: default

Extension will ring and then call extension 101!

----
However If i replace SIP with a phone number it would not call the phone number

(this does not work)
Action: Originate
Channel: SIP/61401234567
Callerid: Unknown
Exten: 101
Priority: 1
Timeout: 60000
Context: default

Extension will ring and then call extension 101.

RESPONSE:


Response: Error

Message: Originate failed

Event: Newchannel
Privilege: call,all
Channel:
State: Down
CallerIDNum: <unknown>
CallerIDName: <unknown>
Uniqueid: 1279865004.67


Whats wrong?
Ron MalmsteadInformation Services Manager

Commented:
What technology are you using for outbound calls...
For example a zap/Dhadi channel, or is it in fact a sip trunk outgoing ?

Try it like this for zap/dhadi...make sure the trunk group is correct (g0)

Action: Originate
Channel: zap/g0/61401234567
Callerid: Unknown
Exten: 101
Priority: 1
Timeout: 60000
Context: default

Ron MalmsteadInformation Services Manager

Commented:
Remember you can also use a LOCAL channel to originate the call...

Action: Originate
Channel: local/61401234567@default
Callerid: Unknown
Exten: 101
Priority: 1
Timeout: 60000
Context: default

Author

Commented:
@xuserx2000

"What technology are you using for outbound calls...
For example a zap/Dhadi channel, or is it in fact a sip trunk outgoing ?"

using SIP , just a standard SIP trunk.


"Remember you can also use a LOCAL channel to originate the call..."

no luck with local either.


------------
Asterisk-Cli Log
------------

[Jul 24 02:12:44] VERBOSE[15632] logger.c: == Manager 'asteriskhub' logged on from 10.1.2.22
[Jul 24 02:12:44] WARNING[15632] chan_sip.c: No such host: 61401234567
[Jul 24 02:12:44] NOTICE[15632] channel.c: Unable to request channel SIP/61401234567
[Jul 24 02:12:50] VERBOSE[15633] logger.c: == Parsing '/etc/asterisk/manager.conf': [Jul 24 02:12:50] VERBOSE[15633] logger.c: Found
[Jul 24 02:12:50] VERBOSE[15633] logger.c: == Parsing '/etc/asterisk/manager_additional.conf': [Jul 24 02:12:50] VERBOSE[15633] logger.c: Found
[Jul 24 02:12:50] VERBOSE[15633] logger.c: == Parsing '/etc/asterisk/manager_custom.conf': [Jul 24 02:12:50] VERBOSE[15633] logger.c: Found
[Jul 24 02:12:50] WARNING[15633] config.c: Unknown directive '#permit=192.168.1.0/255.255.255.0' at line 18 of /etc/asterisk/manager_custom.conf
Ron MalmsteadInformation Services Manager

Commented:
Try like this..

Channel: SIP/5555555555@tosipprovidertrunk

Ron MalmsteadInformation Services Manager

Commented:
I'm guessing this is trixbox ?..yes/no ?

Author

Commented:
[Jul 24 02:12:44] WARNING[15632] chan_sip.c: No such host: 61401234567 <-- I believe this is the main problem.


Then I tried Channel: SIP/5555555555@tosipprovidertrunk as suggested

Now it says
[Jul 24 02:30:00] NOTICE[2876] chan_sip.c: -- Registration for '5555555555@sip.theprovidervoip.com' timed out, trying again (Attempt #160)

Ron MalmsteadInformation Services Manager

Commented:
Can you test to make sure the trunk is registered by placing a regular phone call ?

btw- that is my cellphone I accidentally posted..lol...please don't copy/paste that i'm having it removed from this thread.

Author

Commented:
Actually it produces the same message

[Jul 24 02:12:44] NOTICE[15632] channel.c: Unable to request channel SIP/55555555555@tosipprovidertrunk
Ron MalmsteadInformation Services Manager

Commented:
Unable to request channel } not the same as {no such host

It seems your registration to the trunk is lost.
Can you test that to make sure we have working outbound before we mess with the originate any further.

Unable to request channel/registration timeout... indicates the trunk is down, rather than improper format of the channel string.
Ron MalmsteadInformation Services Manager

Commented:
Btw - this is tested as working on my end... using channel: SIP/{my number}@mysiptrunk
Ron MalmsteadInformation Services Manager

Commented:
...You didn't answer my question though... Is this trixbox/freepbx ?

Author

Commented:
its elastix
Ron MalmsteadInformation Services Manager

Commented:
With elastix, I wonder if it might be more appropriate to execute the built-in dial macro using Manager, with the proper var's set....

I'll look into it.
Not sure why this isn't working, other than this is elastix rather than osource asterisk.

Author

Commented:
could it be this? [Jul 24 02:12:50] WARNING[15633] config.c: Unknown directive '#permit=192.168.1.0/255.255.255.0' at line 18 of /etc/asterisk/manager_custom.conf
Ron MalmsteadInformation Services Manager

Commented:
I believe that deals with the subnet that is allowed to send to asterisk manager.
I don't think you would be able to connect unless you had permit=%yoursubnet%

That being said there are alos permissions for the manager "Username" you are using to connect...
So make sure Originate is included in what is allowed...

read = system,call,log,verbose,command,agent,user,originate
write = system,call,log,verbose,command,agent,user,originate
Ron MalmsteadInformation Services Manager

Commented:
Although I believe we would be getting different error messages than what we are recieving...
It seems at face value that the manager packet we are sending is correct but it's not being routed correctly for whatever reason...

Elastix is very canned in it's design, so customizing functionality can sometimes be challenging.  You will most likely have to play with this a bit more to get the desired results..

Author

Commented:
@xuserx2000

Your suggested solution works! (problem was that the provider was down while testing solution)

How do you playback the pvscode?

---------------
Action: Originate
Channel: SIP/61401234567@trunksip
Context: pvsr-1
Exten: pvs
Priority: 1
Callerid: Unknown
Timeout: 10000
Variable: pvsCode=123


[pvs-1]
exten => pvs,1,Answer()
exten => pvs,2,Playback(greetingmessage.gsm)
;---------------------------------------------------------------playback 3 digit pvscode 3 times.
exten => pvs,3,Playback(goodbye.gsm)
exten => pvs,4,Hangup
Ron MalmsteadInformation Services Manager

Commented:
First change Context: pvsr-1
To match [pvs-1]


Now you need a SayDigits()

[pvs-1]
exten => pvs,1,Answer()
exten => pvs,2,Playback(greetingmessage.gsm)
;---------------------------------------------------------------playback 3 digit pvscode 3 times.
exten => pvs,n,SayDigits(${pvscode})
exten => pvs,n,SayDigits(${pvscode})
exten => pvs,n,SayDigits(${pvscode})
exten => pvs,n,Playback(goodbye.gsm)
exten => pvs,n,Hangup

Author

Commented:
SayDigits() <-- this does not work in elastix!

SayNumber and SayText also are non functional.

Author

Commented:
Having too many issues with customizing Elastix version of Asterisk, somethings work, somethings do not.

Due to this issue AsteriskNow seems to be a better choice for custom Asterisk development http://www.asterisk.org/asterisknow
"AsteriskNOW was built for application developers, systems integrators, students, hackers and others who want to create custom solutions with Asterisk."
Ron MalmsteadInformation Services Manager

Commented:
Do you have access to the CLI in Elastix ?..
Can you do a "core show applications" from the CLI ?
Ron MalmsteadInformation Services Manager

Commented:
For custom Asterisk development, plain old open source is better.
Asterisk now is yet another version of a GUI, that controls the conf files, and it has it's own canned dialplan as well.

I think we can still get this working.
Try SayAlpha(${pvscode})
Ron MalmsteadInformation Services Manager

Commented:
Oh...forgot...
I think the variables are also case sensitive.

SayAlpha(${pvsCode}) ...instead of, SayAlpha(${pvscode})

Author

Commented:
Do you have access to the CLI in Elastix ?..
Can you do a "core show applications" from the CLI ?

Yes this is the output when you use "SayDigits"

...pvs-1,pvs,1 failed so falling back to exten 's'
...pvs-1,s,1 still failed so falling back to context 'default'

--------------
Action: Originate
Channel: SIP/61401234567@trunksip
Callerid: Unknown
Exten: pvs
Priority: 1
Timeout: 60000
Context: pvs-1
Variable: pvscode=123

[pvs-1]
exten => pvs,1,Answer()
exten => pvs,n,SayDigits(${pvscode})
exten => pvs,n,SayDigits(${pvscode})
exten => pvs,n,SayDigits(${pvscode})
exten => pvs,n,Hangup

Author

Commented:
Oh...forgot...
I think the variables are also case sensitive.

SayAlpha(${pvsCode}) ...instead of, SayAlpha(${pvscode})


---
I picked up that mistake and corrected it, yet it does not work. Even when using SayAlpha.
Ron MalmsteadInformation Services Manager

Commented:
"...pvs-1,pvs,1 failed so falling back to exten 's'"
It seems it's not connecting the call to the context when the callee is answering.

When you weren't using SayDigits,... were you testing this and actually hearing the greeting and goodbye messages you had programmed ?  Can you confirm that it was previously connecting the call to the "pvs-1, pvs,1" ?

Author

Commented:
"When you weren't using SayDigits,... were you testing this and actually hearing the greeting and goodbye messages you had programmed ?  Can you confirm that it was previously connecting the call to the "pvs-1, pvs,1" ?"


Confirm, it rings out but  it fails to reach "context" (name is correct).
Ron MalmsteadInformation Services Manager

Commented:
How are you adding your custom context ?
Are you using the custom context module or are you simply editing the files ?  extensions_custom.conf ?

check you extensions_custom.conf file...
Look for [from-pstn-custom]

You may need to add this....
[from-pstn-custom]
include => pvs-1

Author

Commented:
That is correct

using: extensions_custom.conf rather than extensions.conf


"You may need to add this....
[from-pstn-custom]
include => pvs-1"

That means the context will be "from-pstn-custom" ?

Author

Commented:
@xuserx2000

In Elastix

You need to put


[from-internal-custom]      
include => pvs-1


Now it works!

(always having to reboot, after each change, to take affect).
Ron MalmsteadInformation Services Manager

Commented:
If you can get to the Command Line interface for Elastix, you can issue a "dialplan reload"...so you don't have to reboot after you make changes.

Author

Commented:
Hello

Tuanks alot for your help!

If I need additional assistance , or want to hire you,
How do I contact you?


Thank you!
Ron MalmsteadInformation Services Manager

Commented:
Email:      oncall   '@'   embarqmail.com

fyi- I'm in Eastern standard time

Author

Commented:
Is there a document about error handling?

Would like to know how to handle errors, such as Server down/Server not responding, Invalid login credentials, Trunk is unavailable etc

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial