This sample script connects to a voice modem and uses AT commands to dial a number and play back a series of recorded messages. The script will expect the recipient to dial 1 for yes or 2 for no, and also handles other occurrences such as errors in dialing, no answer, etc.
The voice modems that were used in testing this script defaulted to using an audio format of Unsigned 8-bit PCM at 8000 Hz. Additionally all DLE characters in the encoded audio data have to be doubled, as this is used as an escape character by the modem to escape audio playback.
The script will set the response variable to one of the following
Yes: Call recipient answered phone and pressed one for Yes
No: Call recipient answered phone and pressed two for No
Disconnected: Call recipient answered phone, but hung up without pressing 1 (may be voice mail or answering machine or hang up)
No Answer: Call recipient did not answer phone.
Busy: Busy signal or other similar error calling recipient.
No Dialtone: No dialtone message calling receipient.
Error: Unexpected response from modem.
In the sample script nothing is done with this response, however it could be logged for later use or could be used to process further instructions.
$LANG = "VBScript"
phoneNumber = "5550123" 'Replace with the full number as you would dial it
cr = Chr(13) & Chr(10)
dle = Chr(16)
can = Chr(24)
maxloops = 3 'Number of times to loop message playback
haTypeText "AT" & cr
haWaitForPrompt "OK" & cr
haTypeText "ATE0" & cr
haWaitForPrompt "OK" & cr
haTypeText "AT+FCLASS=8" & cr
haWaitForPrompt "OK" & cr
callTime = Now() 'optional timestamp, not used in sample script
haTypeText "ATDT " & phoneNumber & cr 'Dial
haClearMultiPrompt
haAddMultiPrompt "OK" & cr
haAddMultiPrompt "BUSY" & cr
haAddMultiPrompt "NO DIALTONE" & cr
response = haWaitForMultiPrompt(300,100000)
if response = 0 then 'if OK in response to dial
'start sending audio
haTypeText "AT+VTX" & cr
haWaitForString "CONNECT"
do 'loop confirmation message until confirmed or max loops
if choice = "" then
estimatedLength = 10000
haTextSend "C:\mainmessage.raw"
count = count + 1
end if
choice = ""
choicemade = false
thenTime = now()
choice = haGetInput (0, 2, estimatedLength, 1000)
while choice = dle & "u"
choice = ""
choice = haGetInput (0, 2, estimatedLength - (DateDiff("s",thenTime,now())*1000), 1000)
wend
if choice = dle & "1" then 'Press 1 for Yes
choicemade = true
response = "Yes"
elseif choice = dle & "2" then 'Press 2 for No
choicemade = true
response = "No"
elseif choice = dle & "d" or choice = dle & "b" then
choicemade = true
response = "Disconnected"
end if
loop while choicemade = false and count < maxloops
if choicemade = false then
'no answer
response = "No Answer"
end if
haClearOutputBuffer
haWait 250
if response = "Yes" then
haTextSend("C:\thankyoumessage.raw")
elseif response = "No" then
haTextSend("C:\nothankyoumessage.raw")
end if
haTypeText dle & "!"
haWaitForPrompt "OK" & cr
haTypeText "ATH" & cr
haWaitForPrompt "OK" & cr
elseif response = 1 then 'if busy in response to dial
response = "Busy"
elseif response = 2 then 'if busy in response to dial
response = "No Dialtone"
else 'if other resoponse or no response from modem
response = "Error"
end if
'additional code to log or otherwise handle response goes here
haTerminate