Vocal server scripts
Here we will show and comment different IVR scripts.
Incoming call sample: speaking clock
This script uses the text to speech engine.
First we display the whole script. It will be explained later.
Dim _nKey As Integer
Dim _sToPlay As String
_nKey = 0
PLAYTEXT("Hello, welcome on the Alert speaking clock." , "en-us")
_nKey = TTSMENU("Press, 1, to listen to the current time. Press, 2, to listen to the date. Press, 3, for date and time. Press, 4, to hang up.", "1234", 3, 15, "I have not understood.", TRUE, "en-us")
If _nKey = 1 Then
_sToPlay = FORMAT(NOW(), "hh:nn:ss")
PLAYTEXT("It is " + _sToPlay, "en-us", TRUE)
ElseIf _nKey = 2 Then
_sToPlay = FORMAT(NOW(), "mm/dd/yyyy")
PLAYTEXT("We are " + _sToPlay, "en-us", TRUE)
ElseIf _nKey = 3 Then
_sToPlay = FORMAT(NOW(), "fl at hh:nn:ss")
PLAYTEXT(_sToPlay, "en-us", TRUE)
Else
PLAYTEXT("Good bye.", "en-us", TRUE)
EndIf
WAITENDOFPLAY(500)
DISCONNECT()
The script plays first a welcome message with the PLAYTEXT function.
PLAYTEXT("Hello, welcome on the Alert speaking clock." , "en-us")
Then a voice menu is played. The caller can make a choice by pressing a key on his phone. The TTSMENU function offers this menu feature.
TTSMENU("Press, 1, to listen to the current time. Press, 2, to listen to the date. Press, 3, for date and time. Press, 4, to hang up.", "1234", 3, 15, "I have not understood.", TRUE, "en-us")
Depending on the key pressed, an action is done. Here 1 plays the current time, 2 gives the date, 3 plays date and time and 4 hangs up the call.
With the DISCONNECT, the script stops the call when all the messages have been played, it is checked with the WAITENDOFPLAY function.
Outgoing call sample: play alarm and user messages
This second sample uses the text to speech too.
This is the script. It will be described later.
Dim sIdCode As String
Dim nCount As Integer
Dim nCalledUserId As Integer
Dim nFoundId As Integer
Dim nLang As Integer
nFoundId = 0
nCalledUserId = -1
nLang = 0
GETREMOTEPARTYUSERID(nCalledUserId, nLang)
For nCount = 1 To 3
PLAYTEXT("Hello, here is Alert. Please enter your ID.", "en-us")
If GETDTMFSTRING(3, 15, sIdCode) Then
GETUSERIDFROMCODE(sIdCode, nFoundId, nLang)
If nFoundId = nCalledUserId Then
PLAYTEXT("Call acknowledged.", "en-us", TRUE)
ACKCALL()
nCount = 3
Else
PLAYTEXT("Invalid ID.", "en-us")
EndIf
EndIf
Next
' Call acked : play messages
If nFoundId = nCalledUserId Then
PlayUserMessages()
EndIf
WAITENDOFPLAY(1000)
DISCONNECT()
SUB PlayUserMessages()
Dim nAlarmId As Integer
Dim sMessage As String
Dim nAlarmLang As Integer
Dim nAlarmTime As Time
Dim sAudioFile As String
Dim sInstructionFile as String
Dim sShortMessage As String
Dim nFromId As Integer
nAlarmId = 0
DO WHILE GETNEXTALARMMESSAGE(0, 0, nAlarmId, sMessage , nAlarmLang , nAlarmTime , sAudioFile , sInstructionFile , sShortMessage)
PLAY(sAudioFile)
LOOP
DO WHILE GETNEXTUSERMESSAGE(0, 0, nFromId, sMessage , nAlarmLang , sAudioFile , sInstructionFile , sShortMessage)
PLAY(sAudioFile)
LOOP
END SUB
After the different initializations, the script searches for the ALERT user who is connected to the vocal server. The remote party phone number is used for the search. For the outgoing calls the number is the called one.
GETREMOTEPARTYUSERID(nCalledUserId, nLang)
The function GETREMOTEPARTYUSERID does the search.
The next sequence is done in a loop (3 times max.) until the user gives the right code.
The script plays a welcome message with the PLAYTEXT function.
PLAYTEXT("Hello, here is Alert. Please enter your ID.", "en-us")
The script waits for the 3 digits code with the GETDTMFSTRING instruction.
GETDTMFSTRING(3, 15, sIdCode)
If the code is the correct one, the call is acknowledged by ACKCALL and a message is played to the user to confirm the call acknowledgement.
Else an error message is played and the sequence is restarted.
When the call is acknowledged, the script plays all the messages for the connected user.
First the alarm messages with GETNEXTALARMMESSAGE.
DO WHILE GETNEXTALARMMESSAGE(0, 0, nAlarmId, sMessage , nAlarmLang , nAlarmTime , sAudioFile , sInstructionFile , sShortMessage)
PLAY(sAudioFile)
LOOP
Finally, the service messages with GETNEXTUSERMESSAGE.
DO WHILE GETNEXTUSERMESSAGE(0, 0, nFromId, sMessage , nAlarmLang , sAudioFile , sInstructionFile , sShortMessage)
PLAY(sAudioFile)
LOOP