Walkthrough: Survey/Questionnaire with Concatenated Response Logging

In this walkthrough we will ask several questions, get a verbal answer to each question, concatenate the answers and log the concatenate the answer for future reference.

This Sample Application is available for download.  Use link at the end of this walkthrough to download and install sample application.

Walkthrough Overview

In this walkthrough, you will:

  1. Create Audiotex Records/Modules and Associated Scripts;
  2. Define entry in the IVR Application List for the new custom IVR;
  3. Set Ports.

During this walkthrough, you will learn to do the following:

Prerequisites and Assumptions

SurveyQuestions table has 6 questions.  The QuestionPrompt field contains a 3 digit prompt number.  This number represents a custom prompt and will need to be recorded via the Administrator log in options.

RecID
(int)
QuestionNumber
(int)
QuestionPrompt
(int
Memo
(nvarchar(150))
1 1 701 Please state your name
2 2 702 Please say your address
3 3 703 How many family members in your household
4 4 704 How many credit cards do you have?
5 5 705 What is the total amount owed on your credit card?
6 6 706 Would you like us to call you to consolidate your credit?

Create Audiotex Records/Modules and Associated Scripts

As all calls will be starting in Audiotex mode in this walkthrough, the Audiotex Modules will determine the call flow. 

In the Audiotex set-up, the caller will be played a welcome greeting followed by instructions about the survey process.  We will read the SurveyQuestions table for the first question, play the recording matching the Question Prompt, get answer.  We will then ask the next question, concatenate the answer to the end of the previous answers.  This question/answer process will continue until we process the last question. The concatenated answer will be written to the SurveyAnswersLog table with the date and time of the call.

We will need to create several Audiotex records as shown below.  The Label field provides a brief description of each module.  

Audiotex Records
Module ID Label Write Label
to Log File
Module
Action
Next Module ID Fail Module ID Script File to Run
(Must include full path name)
(c:\Program Files\CALLMaster\Scripts\SampleApp-Survey\)
1000 Start call and Initialize values Yes Next Module 1010 9900 InitializeVal.bas
1010 Play welcome greeting Yes Next Module 1020 9900  
1020 Play instructions Yes Next Module 1100 9900  
1100 Read first question from the SurveyQuestions table. Yes Next Module 1110 9900 ReadFirst-SurveyQuestion.bas
1110 Play current question prompt Yes Next Module 1200 9900 PlayCurrentQuestion.bas
1200 Record single answer Yes Next Module 1210 9900 RecordAnswer.bas
1210 Concatenate Answer Yes Next Module 1500 9900 CopyAppendAnswer.bas
1500 Read next question Yes Next Module 1510 9900 ReadNext-SurveyQuestion.bas
1510 Delete single answer recording Yes Next Module 1520 9900 DeleteAnswerFile.bas
1520 Email concatenated answer recording Yes Next Module 9500 9900 EmailRecording.bas
9110 Questionnaire record not found on SurveyQuestions table Yes Next Module 9500 9900  
9500 Add SurveyAnswersLog record Yes Next Module 9510 9900 Insert-SurveyAnswersLog.bas
9510 Thank you for calling. Goodbye Yes Next Module 9999 9900  
9900 Call Failure Detected Yes Next Module 9999 9999 SetCallFailure.bas
9910 Caller Hang-up Detected Yes Next Module 9999 9999 SetCallerHangup.bas
9999 Last Module - End call Yes Last Module      

Audiotex Module Description

Based on the Audiotex modules shown above, we will need several scripts. 

Create a SampleApp-Survey subfolder in the Program Files\CALLMaster\Scripts folder - we will save the scripts for this sample application in this folder.
Let's create the scripts first.  Open Notepad and create scripts with the following code examples below.  Remember to save them as .bas type files and save them in the Program Files\CALLMaster\Scripts\SampleApp-Survey folder.

CALLBasic Script - InitializeVal.bas Copy to Clipboard
Program
'************************************************************************************************
'     Script:  InitializeVal.bas
'     Function:  This script is used to initialize values
'************************************************************************************************

     strYes = "Yes"
     strNo = "No"
     intYes = 1
     intNo = 0
     strCallFailure = strNo
     strCallerHangup = strNo
     strMaxAttempts = strNo
     intOne = 1
     intZero = 0
     intNegOne = 0 - 1
     strZero = "0"
     GetFloat fltZero strZero 0

     intDecMM = 12
     intJanMM = 1

     strStatus-OK = "OK"
     strStatus-NOK = "NOK"

     ' Set retry counter and maximum attempts allowed
     intTryCount = 1
     intMaxAttemptsAllowed = 3

     ttcutthrough = 1
     intInvalidSelection = intNo
     intCallerHangUp = intNo

     intAnswerTime = 120
     intAnsweredAllQuestions = intNo


     ' Get Date and Time string component for Answer Recording Name and SurveyAnswerLog
     dteCallDateTime = $today
     GetDate dteCallDateTime intcurrmm intcurrday intcurryear intcurrhour intcurrmin intcurrsec

     intcurrmm = $month
     IntegerToString strcurrmm intcurrmm
     If intcurrmm < 10 Then
        strcurrmm = "0" & strcurrmm
     Else
     EndIf

     intcurrday = $day
     IntegerToString strcurrday intcurrday
     If intcurrday < 10 Then
        strcurrday = "0" & strcurrday
     Else
     EndIf

     intcurryear = $year
     IntegerToString strcurryear intcurryear

     intcurrhour = $hour
     IntegerToString strcurrhour intcurrhour

     If intcurrhour < 10 Then
        strcurrhour = "0" & strcurrhour
     Else
     EndIf

     intcurrmin = $minute
     IntegerToString strcurrmin intcurrmin
     If intcurrmin < 10 Then
        strcurrmin = "0" & strcurrmin
     Else
     EndIf

     intcurrsec = $sec
     IntegerToString strcurrsec intcurrsec
     If intcurrsec < 10 Then
       strcurrsec = "0" & strcurrsec
     Else
     EndIf

     ' Create Date and Time string variable for adding to SurveyAnswers record DateTime Data Type in mm/dd/yyyy hh:mm:ss format
     ' Date format = MMDDYYYY
     strCallDate = ""
     strCallDate = strcurrmm & "/"
     strCallDate = strCallDate & strcurrday
     strCallDate = strCallDate & "/"
     strCallDate = strCallDate & strcurryear

     ' Time format HHMM Military Time
     strCallTime = ""
     strCallTime = strCallTime & strcurrhour
     strCallTime = strCallTime & ":"
     strCallTime = strCallTime & strcurrmin & ":"
     strCallTime = strCallTime & strcurrsec

     strCallDateTime = strCallDate & " " & strCallTime


     ' Create Date and Time string variable for Survey Answer recording name in mmddyyyy-hhmmss format
     ' Date format = MMDDYYYY
     strCallDate = ""
     strCallDate = strcurrmm
     strCallDate = strCallDate & strcurrday
     strCallDate = strCallDate & strcurryear

     ' Time format HHMM Military Time
     strCallTime = ""
     strCallTime = strCallTime & strcurrhour
     strCallTime = strCallTime & strcurrmin
     strCallTime = strCallTime & strcurrsec

     strRecDateTimeFormat = strCallDate & "-" & strCallTime

     ' Set up path and name for SurveyAnswer recording
     strAnswerFilePath = "C:\\Program Files\\CALLMaster\\SurveyAnswerRecording\\" & "\\"
     strAnswerFileName = strRecDateTimeFormat & ".wav"
     strAnswerFilePath-n-Name = strAnswerFilePath & strAnswerFileName

     ' Email variables
     strMapiProfile = "CALLMaster"
     strToAddress = "sales@speechsoft.com"
     strFromAddress = "support@speechsoft.com"
     strSubject = "CALLMaster Sample Application - Survey"
     strFileAttach = strAnswerFilePath-n-Name
     strBCCAddress = " "
     strCCAddress = " "
     strBodyText = "Test recording from CALLMaster Sample Application - Survey and Questionnaire"
 
     'SampleApps db
     SADBOpen = intNo

     ' SurveyQuestions values
     SQMatchExists = intNo
     SQ-intQuestionNumber = 0
     SQ-intQuestionPrompt = 0

     ' SurveyAnswer values
     SAMatchExists = intNo
     SA-strCallDateTime = strCallDateTime
     SA-strStatus = strStatus-OK
     SA-strSurveyAnswerRecordingName = ""
     SA-strLastQuestionAnswered = "0"
     intSurveyAnswerLogAdded = intNo

     ' Set connection string to read SampleApps database.
     strSAConnection = "Provider=SQLOLEDB;Server=<servername>;DATABASE=SampleApps;UID=;PWD=;Integrated Security=SSPI;"

     ' Set the module to return to if caller hangs up
     lctrap = 9910

     ' Convert system variable $channel from integer to string to be used in concatenated print statement.
     IntegerToString strchannel $channel

     pline = "***** For channel=" & strchannel
     pline = pline & " Started initialization process "
     PrintNL pline


EndProgram
CALLBasic Script - ReadFirst-SurveyQuestion.bas Copy to Clipboard
Program
'******************************************************************************************************************
'     Script:  ReadFirst-SurveyQuestion.bas
'     Function:  This script reads the SurveyQuestions table for the first question.
'******************************************************************************************************************

     ' Set new command and open connection to SampleApps database.
     Set SQvarCommand = New Command

     SQvarCommand.ActiveConnection strSAConnection

     If $DBError <> intZero Then
        SQvarSet.Close
        Set SQvarSet = Nothing
        SA-strStatus = strStatus-NOK
        pline = "***** For channel=" & strchannel
        pline = pline & " Error Connecting db. "
        PrintNL pline
        Return 9900
     Else
     EndIf


     ' Create a new recordset
     Set SQvarSet = New Recordset

     strSQL = "SELECT QuestionNumber, QuestionPrompt FROM SurveyQuestions WHERE QuestionNumber >= 0 ORDER BY QuestionNumber"

     pline = "For channel " & strchannel
     pline = pline & " Read First for strSQL = " & strSQL
     PrintNL pline

     ' Open SADB database and find record
     Set SQvarSet = SQvarCommand.Execute strSQL

     If $DBError <> intZero Then
        SQvarSet.Close
        Set SQvarSet = Nothing
        SA-strStatus = strStatus-NOK
        pline = "***** For channel=" & strchannel
        pline = pline & " Error Opening db. "
        PrintNL pline
        Return 9900
     Else
     EndIf

     Set SQvarFields = SQvarSet.Fields
     SADBOpen = intYes

     ' If the record exists then move selected field values for processing
     SQvarSet.MoveFirst

     If SQvarSet.EOF = 0 Then
        Set SQvarF1 = SQvarFields.Field 1
        Set SQvarF2 = SQvarFields.Field 2
        SQ-intQuestionNumber = SQvarF1.Value
        SQ-intQuestionPrompt = SQvarF2.Value

        ' Free field variables
        Set SQvarF1 = Nothing
        Set SQvarF2 = Nothing

        ' Set Switches 
        SQMatchExists = intYes

     Else
        SQMatchExists = intNo

        ' Free SQDB varSet, varFields, and close database
        ' Destroy Fields Object
        Set SQvarFields = Nothing

        ' Close recordset
        SQvarSet.Close

        ' Free memory
        Set SQvarSet = Nothing

        ' clear command
        SQvarCommand.CloseConnection
        Set SQvarCommand = Nothing

        ' SQDB database closed
        SQDBOpen = intNo
     EndIf

     ' If record found then return 1110 else return 9110
     If SQMatchExists = intYes Then
        IntegerToString strCurrentQuestionNumber SQ-intQuestionNumber
        IntegerToString strCurrentQuestionPrompt SQ-intQuestionPrompt
        'Print information to log file for reference and debugging
        pline = "***** For channel=" & strchannel
        pline = pline & " SurveyQuestions record found for QuestionNumber = " & strCurrentQuestionNumber
        pline = pline & " with QuestionPrompt = " & strCurrentQuestionPrompt
        PrintNL pline
        Return 1110
     Else
        pline = "***** For channel=" & strchannel
        pline = pline & " SurveyQuestions record NOT found for QuestionNumber >= 0"
        PrintNL pline
        Return 9110
     EndIf

EndProgram

CALLBasic Script - PlayCurrentQuestion.bas Copy to Clipboard
Program
'*************************************************************************************************************************************
'     Script:  PlayCurrentQuestion.bas
'     Function:  This script plays the current question.
'*************************************************************************************************************************************

     playbackposition = 0
     Play SQ-intQuestionPrompt c d
     playbackposition = 0

EndProgram

CALLBasic Script - RecordAnswer.bas Copy to Clipboard
Program
'*************************************************************************************************************
'     Script:  RecordAnswer.bas
'     Function:  This script records answer to current question.
'*************************************************************************************************************

     ' Initialize variables
     Prompt = 100
     RecTime = intAnswerTime
     t = "*"
     a = ""
     recfileid = 0
     fatfilename = ""

     strAnswerFile = "C:\Program Files\CALLMaster\Answer.wav"

     playbackposition = 0

     ' Plays prompt 100 (Press * to stop recording) to instruct caller, Then.
     ' Records file and places speechfile id in integer variable recfileid.

     Record recfileid Prompt RecTime a t e d

     playbackposition = 0

     ' Renames speechfile id from integer to full name with folder path.
     ' This is required if you wish to rename or delete speechfiles

     FileIDToName fatfilename recfileid

     ' The file to be renamed cannot exist.  Use the FileStatus function to check and delete if it exists.
     intStatus = 0
     intSize = 0
     intMdate = 0
     FileStatus strAnswerFile intStatus intSize intMdate
     If intStatus > 0 Then
        FileDelete strAnswerFile
     Else
     EndIf

     ' Renames file to user selected name. 
     FileRename fatfilename strAnswerFile

     playbackposition = 0

     ' Deletes file using full path name.
     FileDelete fatfilename

EndProgram

 
CALLBasic Script - CopyAppendAnswer.bas Copy to Clipboard
Program
'***************************************************************************************************************
'     Script:  CopyAppendAnswer.bas
'     Function:  This script concatenates the current answer to previous answers
'***************************************************************************************************************

     ' If SQ-intQuestionNumber = 1 then copy answer to saved name else append answer

     If SQ-intQuestionNumber = 1 Then
        strOverwrite = "Yes"
        CopyFile strAnswerFile strAnswerFilePath-n-Name strOverwrite
     Else
        rewindbytes = 0
        AppendFile strAnswerFile strAnswerFilePath-n-Name rewindbytes
     EndIf

     IntegerToString SA-strLastQuestionAnswered SQ-intQuestionNumber
     SA-strSurveyAnswerRecordingName = strAnswerFileName

EndProgram

CALLBasic Script - ReadNext-SurveyQuestion.bas Copy to Clipboard
Program
'****************************************************************************************************************
'     Script:  ReadNext-SurveyQuestion.bas
'     Function:  This script reads the SurveyQuestions table for the next question.
'****************************************************************************************************************

     SQMatchExists = intNo

     pline = "For channel " & strchannel
     pline = pline & " Read Next Record "
     PrintNL pline

     SQvarSet.MoveNext

     ' If the record exists then move selected field values for processing
     If SQvarSet.EOF = 0 Then
        Set SQvarF1 = SQvarFields.Field 1
        Set SQvarF2 = SQvarFields.Field 2

        ' Assign field values to variables
        SQ-intQuestionNumber = SQvarF1.Value
        SQ-intQuestionPrompt = SQvarF2.Value

        ' Free field variables
        Set SQvarF1 = Nothing
        Set SQvarF2 = Nothing

        ' Set Switches 
        SQMatchExists = intYes

     Else
        SQMatchExists = intNo

        ' Free SQDB varSet, varFields, and close database
        ' Destroy Fields Object
        Set SQvarFields = Nothing

        ' Close recordset
        SQvarSet.Close

        ' Free memory
        Set SQvarSet = Nothing

        ' clear command
        SQvarCommand.CloseConnection
        Set SQvarCommand = Nothing

        ' SQDB database closed
        SQDBOpen = intNo
     EndIf

     ' If record found then return 1110 else return 1510
     If SQMatchExists = intYes Then
        IntegerToString strCurrentQuestionNumber SQ-intQuestionNumber
        IntegerToString strCurrentQuestionPrompt SQ-intQuestionPrompt
        'Print information to log file for reference and debugging
        pline = "***** For channel=" & strchannel
        pline = pline & " SurveyQuestions record found for QuestionNumber = " & strCurrentQuestionNumber
        pline = pline & " with QuestionPrompt = " & strCurrentQuestionPrompt
        PrintNL pline
        Return 1110
     Else
        intAnsweredAllQuestions = intYes
        pline = "***** For channel=" & strchannel
        pline = pline & " SurveyQuestions record NOT found for QuestionNumber > " & strCurrentQuestionNumber
        PrintNL pline
        Return 1510
     EndIf

EndProgram

CALLBasic Script - DeleteAnswerFile.bas Copy to Clipboard
Program
'*********************************************************************************************************
'     Script:  DeleteAnswerFile.bas
'     Function:  This script deletes the single answer file.
'*********************************************************************************************************

     ' Deletes file using full path name.
     FileDelete strAnswerFile

     'Print information to log file for reference and debugging
     pline = "***** For channel=" & strchannel
     pline = pline & "***** Deleted Answer File = " & strAnswerFile
     PrintNL pline

EndProgram

CALLBasic Script - EmailRecording.bas Copy to Clipboard
Program
'************************************************************************************************************
'     Script:  EmailRecording.bas
'     Function:  This script emails the concatenated recording.
'************************************************************************************************************

     ' send email
     Email strMapiProfile strFromAddress strToAddress strCCAddress strBCCAddress strSubject strBodyText strFileAttach

     'Print information to log file for reference and debugging
     pline = "***** For channel=" & strchannel
     pline = pline & "***** Recording Emailed "
     PrintNL pline

EndProgram

CALLBasic Script - Insert-SurveyAnswersLog.bas Copy to Clipboard
Program
'***************************************************************************************************************
'     Script:  Insert-SurveyAnswersLog.bas
'     Function:  This script inserts the SurveyAnswersLog table for the first question.
'***************************************************************************************************************

     ' Set new command and open connection to SampleApps database.
     Set SAvarCommand = New Command

     SAvarCommand.ActiveConnection strSAConnection

     If $DBError <> intZero Then
        SA-strStatus = strStatus-NOK
        pline = "***** For channel=" & strchannel
        pline = pline & " Error Connecting to SAdb. "
        PrintNL pline
        Return 9900
     Else
     EndIf


     strSQL = "INSERT INTO [SurveyAnswersLog] (CallDateTime, CallStatus, RecordingName,LastQuestionAnswered) VALUES ('"
     strSQL = strSQL & SA-strCallDateTime
     strSQL = strSQL & "', '" & SA-strStatus
     strSQL = strSQL & "', '" & SA-strSurveyAnswerRecordingName
     strSQL = strSQL & "', '" & SA-strLastQuestionAnswered
     strSQL = strSQL & "')"
     pline = "For channel " & strchannel
     pline = pline & strSQL
     PrintNL pline

     ' Execute Insert command
     SAvarCommand.Execute strSQL

     If $DBError <> intZero Then
        SA-strStatus = strStatus-NOK
        pline = "***** For channel=" & strchannel
        pline = pline & " Error inserting. "
        PrintNL pline
        Return 9900
     Else
     EndIf


     ' Close connection and clear command
     SAvarCommand.CloseConnection
     Set SAvarCommand = Nothing

     ' SADB database closed
     SADBOpen = intNo


     intSurveyAnswerLogAdded = intYes
     pline = "For channel " & strchannel
     pline = pline & " SurveyAnswersLog added for recording="
     pline = pline & SA-strSurveyAnswerRecordingName
     PrintNL pline


EndProgram


CALLBasic Script - SetCallFailure.bas Copy to Clipboard
Program
'******************************************************************************************************************
'     Script:  SetCallFailure.bas
'     Function:  This script sets the strCallFailure variable to yes and prints information in the call log file.
'******************************************************************************************************************

     strCallFailure = strYes

     'Print information to log file for reference and debugging
     pline = "***** For channel=" & strchannel
     pline = pline & "***** Call Failure. *****"
     PrintNL pline

EndProgram

CALLBasic Script - SetCallerHangup.bas Copy to Clipboard
Program
'********************************************************************************************************************
'     Script:  SetCallerHangup.bas
'     Function:  This script sets the strCallFailure variable to yes and prints information in the call log file. 
'********************************************************************************************************************

     strCallerHangup = strYes

     'Print information to log file for reference and debugging
     pline = "***** For channel=" & strchannel
     pline = pline & "***** Caller Hangup. *****"
     PrintNL pline

EndProgram

Now you can create the Audiotex modules and reference the scripts above.  Open the CALLMaster Manager, click on Manage, then select Audiotex.  Let's add the Audiotex records shown above.

Define IVR Application List Entry

We need to define the custom IVR in the IVR Application List and set it to Audiotex Start Module 1000.  Open CALLMaster Manager and select Manage | IVR Application List.  Let's add a new record as follows:

IVR Application List
Audiotex Start Module Application Name
1000 Survey Sample

Set Ports

As a last step, we need set the port(s) to the new IVR Application entry created above.  Make sure the Audiotex Start Module field (read only) correctly points to module 1000.

 Set the Port Greeting File IDs to the main greeting for all calls if you have recorded one.  If you do not want a main greeting then set the Greeting File IDs to zero. Leave all other fields to the default values.

If you are working with a demo license or have only one line connected, then make sure the connected port is set as specified below.  All other ports should be set to Application 'Disabled'.

Port Records
Port # Application Audiotex Start Module Port Greeting File IDs
(Morning, Afternoon, Evening, Closed, Holidays)
1 Survey Sample 1000 0, 0, 0, 0, 0
2 Survey Sample 1000 0, 0, 0, 0, 0
3 Survey Sample 1000 0, 0, 0, 0, 0
4 Survey Sample 1000 0, 0, 0, 0, 0

Test the custom application

Make sure you have set the SampleApps database connection string variable strSAConnection in the InitializeVal.bas script for your environment.

Save all your work. 

Stop CALLMaster service.

Make Administrator Audiotex Recordings:

-  Set Port 1 to Application Voice Mail.

-  Start CALLMaster service.

-  Make a call using Port 1.

Log in as the Administrator using the Voice Mail Main Menu and make recordings for the Audiotex modules below.

Audiotex Module ID Proposed Recording
1010 Welcome Greeting - Welcome to the CALLMaster Sample Survey Questionnaire
1020 Survey Instruction - You will be asked a series of questions.  Please speak your answers clearly.
9510 Thank you for participating in the CALLMaster Sample Survey Questionnaire
9900 We are unable to process your call.  Please contact the system administrator for further assistance.
Prompt # Proposed Recording
701 Please state your name
702 Please say your address
703 How many family members in your household?
704 How many credit cards do you have?
705 What is the total amount owed on your credit card?
706 Would you like us to call you to consolidate your credit? 

Reset Port 1 to Application Audiotex.  Set the Port Greeting File IDs to zeros.

Stop and Start CALLMaster service.

Make a phone call to test the application.

Tip: See Walkthrough: Change Application Without Restarting CALLMaster Service to set port to Voice Mail to make recording without stopping and restarting the CALLMaster service.

 

To download and install, see Sample Applications.