How to verify pin code for IVR authentication in Yeastar P-Series PBX


This article provides solution to verify pin code in IVR stage. We take Yeastar P-Series for demo and achieve such situation:

When caller is reaching IVR, he will hear IVR message first and asked to enter given pin code.

If pin code is correct, it will go to different queues according to the time defined in the script.

If pin code is incorrect, he will be asked to enter it again, if pin code incorrect for 3 times he will hear defined message and call will be hangup.

Applicable Devices

Model: P-Series PBX, S-Series PBX

Firmware: Not Required


1. Add an IVR in web interface and set up proper prompt to ask callers to input pin code, do not set any config in key press event.

2. Create 3 queues for destinations according to different time conditions, add more or less queues accordingly.

3. Access ssh of pbx and go to file by vi command.

support@IPPBX:~# vi /etc/asterisk/extensions.conf

4. Search context “[ivr_6200]” and copy all dialplan within context “[ivr_6200]”, replace 6200 accordingly.

5. Paste what you copied to the file in this path /ysdisk/support/customcfg/extensions_custom.conf and add two 2 paragraphs of script below to extensions_custom.conf.

Paragraph one below in italics and red:

Notice: change time condition and queue number accordingly, if don't need time condition in queue, replace GotoIfTime(08:00-18:00,mon&tue&wed&thu&fri,*,*?queues,6403,1) with Goto(queues,6403,1), if want to route calls to other destination like queue 6406 when pin code is wrong, replace GotoIf($[${COUNT}>=3]?wrongpin,1:ivr_6200,6200,check_count) with Goto(queues,6406,1).


exten = _X.,1,Set(pincode=${EXTEN})

exten = _X.,2,Set(result=${SHELL(awk '$1~/^${pincode}$/{print $1}' /ysdisk/etc/autoprovision/template/custom/ivr-pin/ivr-pin.xml)})

exten = _X.,3,Set(res=${result:0:-1})

exten = _X.,4,GotoIf($[${res}>=1}]?valid,1:invalid,1)

exten = valid,1,GotoIfTime(08:00-18:00,mon&tue&wed&thu&fri,*,*?queues,6403,1)

exten = valid,2,GotoIfTime(18:01-23:59,mon&tue&wed&thu&fri,*,*?queues,6404,1)

exten = valid,3,GotoIfTime(02:00-07:59,mon&tue&wed&thu&fri,*,*?queues,6405,1)

exten = invalid,1,GotoIf($[${COUNT}>=3]?wrongpin,1:ivr_6200,6200,check_count)


Paragraph two below in italics and red:

Notice: change audio message filename to play for callers after incorrect pin code for 3 times, in the demo filename is PinErrato_ENG_Ita.wav which has been uploaded to custom prompt in pbx, do not add file type to the script ).

exten = wrongpin,1,Background(record/PinErrato_ENG_Ita)

exten = wrongpin,2,Hangup()


After added to extensions_custom file, complete script should be similar to those in picture below.

6. Create any extension in web interface and delete it again, click on 'Apply' to make above change take effect.

7. In Auto Provisioning – Resource Repository – Custom Templates, add one and choose a phone model that might hardly use it in future in ‘Source Default Template’, and do set Template Name to ‘ivr-pin’ which is mandatory, in fact have to be the same as defined in script.

Scroll down mouse and remove all original contents in both fileds, add required pin code in first filed, one code one line, save it, later always modify or add new pin code here.

8. All done, test calls now.

Have more questions? Submit a request


Please sign in to leave a comment.