
The IVR4Line sample program demonstrates one method of building an application that supports multiple telephone devices simultaneously. It is a simple Interactive Voice Response system that automatically answers incoming calls, plays and records wave files and responds to DTMF tones.
The etLine.Call.Tag property and etLine.OnDigitReceived event are utilized to create a simple "State Machine". See the etLine1.OnDigitReceived Event Handler Routine for more information.
The properties should be set as follows, with the name of the control ending in a digit (‘X’) corresponding to the line it’s associated with:
The following components are used. The controls with names ending with "X" indicate that there are four of these controls. In the code the "X" is a number between "1" and "4".
|
Controls |
Purpose |
|
PageControl1 |
This control has 4 tabs, one for each TAPI line device. |
|
CheckBoxActive(X) |
Used to activate the TAPI Line device. |
|
ComboBoxDevice(X) |
Used to select the TAPI line device. |
|
ButtonTeleScope(X) |
When clicked the TeleScope.Visible property for the etLine, etPlay and etRecord controls are toggled to True or False causing the TeleScopes to be displayed or hidden. |
|
LabelPlay(X) |
Displays "Play" |
|
LabelPlayDevice(X) |
Displays the wave play associated with the TAPI line device. |
|
LabelRecord(X) |
Displays "Record" |
|
LabelRecordDevice(X) |
Displays the wave record associated with the TAPI line device. |
|
LabelStatus(X) |
Displays the current status of the Call, Line, Play and Record |
|
LabelLineStatus(X) |
Displays "Status" |
|
etLine(X) |
The etLine control |
|
etRecord(X) |
The etRecord control |
|
etPlay(X) |
The etPlay control |
The following properties values are different from the default values:
|
Object |
Property |
Setting |
|
ComboBoxDevice(X) |
Style |
csDropDown |
The following subroutines are used (most of which are Event Handlers, some of which are not):
This is not an Event Handler Routine. This routine is used by the Delphi and C++ Builder versions of the IVR4Line sample program to relate the controls. This routine is called by all other Event Handler Routines.
This routine uses the Sender parameter to set the remaining parameters to the related controls. This is one of the two routines used to relate controls to one another in order to make sharing code easy. This is just one example of how to share code. This method was chosen because it is relatively easy for both novice and expert programmers to understand.
Event Handler Routine for: creation of the form
A number of global variables are initialized. For each page in the tab control, SetControls is called to make the local Controls variable point to correct controls and initialize the ComboBoxDevice(X) and etLine(X) control to point to the corresponding device (e.g. On the first page, the first TAPI line device is selected; on the second page, the second TAPI line device is selected, and so forth.) If there are fewer than four available telephony devices, the pages that are not needed are hidden. The play and record status fields The SetPlayRecordDevices routine is called to set the play and record devices associated with the TAPI line device.
Event Handler Routine for: the CheckBoxActive(X).OnClick events of the CheckBoxActive(X) controls
If the control is currently checked, etPlay(X).Device.Active is checked to see if a wave file is currently playing, if it is then it is stopped by setting etPlay(X).Device.Active = False. etRecord(X).Device.Active is also checked and stopped if necessary. If the etLine(X).Call.Active property is True then it is set to False, this will cause the etLine(X).Call.Hangup method to be called. The line device is deactivated by setting the property etLine(X).Device.Active = FALSE.
If the control is currently unchecked, the TAPI line device is activated by setting etLine(X).Device.Active to True. If there error LINEERR_INVALIDMEDIAMODE is returned when activating the line device, the device is probably not 100% TAPI compliant. The etLine(X).Device.MediaModes.Active is set to LINEMEDIAMODE_DATAMODEM and etLine(X).Device.Active is once again set to True. We are assuming that the device is a modem that does not support the voice features so we attempt to activate the modem in data mode. The program will not work properly in this mode.
Once the etLine(X).Device has been dealt with, SetPlayRecordDevices is called to update the etRecord(X) and etPlay(X) devices to work with the current etLine(X) device settings.
If the property etLine(X).TAPI.TSP contains the string "Universal Modem Driver" then the property etPlay(X).Volume.Enabled is set to false because voice modems do not support the volume features.
Event Handler Routine for: the ComboBoxDevice(X).OnChange events of the ComboBoxDevice(X) controls
The etLine(X).Device.Active property is checked to see if the current device is active, if so then CheckBoxActive(X) is set to false causing the device to be deactivated. The etLine(X).Device.ID is set to the index value of the device chosen in the combo box.
Event Handler Routine for: the ButtonTeleScope(X).OnClick events of the ButtonTeleScope(X) controls
This button causes the TeleScope.Visible properties to be toggled for the etLine(X), etPlay(X) and etRecord(X) controls. This causes the TeleScopes to be displayed or hidden.
Event Handler Routine for: the etLine(X).OnConnected events of the etLine(X) controls
The property etLine(X).Call.MonitorDigits.Active property is set to True to begin monitoring for digits. The etPlay(X).Source.FileName property is set to the greeting wave file path and file name. The etPlay(X).Device.Loop property is set to false so that this file will play only once. The wave file is started by setting etPlay(X).Device.Active to True.
See the etPlay1Done to find out what happened when a wave file is finished playing.
Event Handler Routine for: the etLine(X).OnDigitsReceived events of the etLine(X) controls
The etPlay(X).Device.Active property is set to False to stop any wave files from playing. If an error occurs the the call is hung up by calling the method etLine(X).Call.Hangup. The etLine(X).Call.Tag property is then inspected and the correct action is taken.
If the Tag indicates that the line is currently recording (etLine(X).Call.Tag = TAG_RECORDING), then the recoding is stopped by setting etRecord(X).Device.Active = False. The file is then replayed by setting etPlay(X).Source.FileName to the value in etRecord(X).Source.FileName. The etLine(X).Call.Tag property is set to TAG_WAVEPLAY, which tells the application to play the wave file at the end of this routine. If an error occurred when setting etRecord(X).Device.Active = False, then the DisplayRecordError routine is called.
If menu was playing when the user pressed a key (etLine(X).Call.Tag = TAG_MENU), we respond to the pressed key as follows:
If
the Digit parameter is '1', the etLine(X).Call.CallerID
information is played back in the form of wave files. The etLine(X).Call.Tag property is set to TAG_WAVEPLAY
which tells the application to play the wave file at the end of this routine
If
the Digit parameter is '2', '3', '4', or '5', then a corresponding wave file is played back to the caller
using etPlay(X).Source.FileName = WavPath + "MenuOptX". The etLine(X).Call.Tag property is set
to TAG_WAVEPLAY which tells the application to play the wave file at the end of this routine.
If
the Digit parameter is '6', then etRecord(X) will be used to record. The property etRecord(X).Source.FormatID
is set to the correct wave format. (The formats we use are defined in etTTConst file) The property etRecord(X).Source.FileName
is set to a name based on the TAPI line device currently selected. Recording begins by setting etRecord(X).Device.Active
= TRUE. Recall that when another digit is received that recording is stopped and the wave file is played
back. The property etLine(X).Call.Tag is set to TAG_RECORDING.
If
the Digit parameter is '#' key, the etLine(X).Call.Hangup
method is called. First recording or playing of wave files is stopped by setting Device.Active to False
for the etRecord(X) and etPlay(X) controls.
If
the Digit parameter is any other value then the wave file(s) stored in gsMenu will be played.
If the etLine(X).Call.Tag property has the value of TAG_MENU or TAG_WAVEPLAY then the file in the etPlay(X).Source.FileName will be played.
Event Handler Routine for: the etLine(X).OnDisconnected events of the etLine(X) controls
If the etPlay1.Device.Active property is True, then a wave file is currently playing and must be stopped by setting etPlay1.Device.Active = False. The etLine1.Call.Hangup method is called to hang up the call.
Event Handler Routine for: the etLine(X).OnRing events of the etLine(X) controls
If the Count parameter is greater than 2, then the etLine(X).Call.Answer method is called to answer the call.
Event Handler Routine for: the etPlay(X).OnDone events of the etPlay(X) controls
If the property etLine(X).Call.State is equal to LINECALLSTATE_CONNECTED, then the call is still connected, and if the etPlay(X).Device.Loop property is False, then the menu wave files will be played next.
Event Handler Routine for: closing of the form
The etRecord(X).Device.Active and etPlay(X).Device.Active properties are set to False for all lines. This causes all recording and play to stop. The etLine(X).Call.Hangup method is called for each line which, causes all calls to hang up. The etLine(X).Device.Active property are set to False for all line device causing all devices to be deactivated.
This is not an Event Handler Routine. This routine is used to set the etLine(X).Device.ID to a given TAPI line device.
This is not an Event Handler Routine. This function tests to see if the current etLine(X) device supports playing and/or recording files. This is done by evaluating the properties etLine(X).WavePlay.Available and etLine(X).WaveRecord.Available, which will be True if Play or Record is supported and False if they are not. etPlay(X).Device.ID is set to etLine(X).WavePlay.ID and etRecord(X).Device.ID is set to etLine(X).WaveRecord.ID in order to select the wave devices associated to the line device. The LabelPlayDevice(X) control is updated with the etPlay(X).Device.Name and LabelRecordDevice(X) control is updated with the etRecord(X).Device.Name
This is not an Event Handler Routine. The DisplayLineError, DisplayPlayError, and DisplayRecordError are used to test for errors and display them in a dialog box.