Skip to content

Instantly share code, notes, and snippets.

@callemall
Last active December 20, 2015 11:19
Show Gist options
  • Save callemall/6123031 to your computer and use it in GitHub Desktop.
Save callemall/6123031 to your computer and use it in GitHub Desktop.
This example creates and launches a simple text-to-speech broadcast using the ExtCreateBroadcast function.
Private Sub TestXMLHTTP()
Dim username As String
Dim pin As String
Dim broadcastType As String
Dim phoneNumberSource As String
Dim broadcastName As String
Dim checkCallingWindow As String
Dim commaDelimitedPhoneNumbers As String
Dim TTSText As String
Rem ===================================
Rem Use your account credentials here
Rem ===================================
username = "999111999"
pin = "9991"
Rem ================================
Rem BroadcastType = Announcement
Rem ================================
broadcastType = "1"
Rem ================================
Rem Source is comma delimited string
Rem ================================
phoneNumberSource = "3"
Rem ================================
Rem The broadcast name
Rem ================================
broadcastName = "Test from Visual Basic"
Rem ================================
Rem Bypass calling window
Rem ================================
checkCallingWindow = "0"
Rem ====================================
Rem The numbers to call comma delimited
Rem ====================================
commaDelimitedPhoneNumbers = "9725551313"
Rem ================================
Rem Use text to speech for the msg
Rem ================================
TTSText = "Hello, This is a text to speech call testing integration with Microsoft Access 2010. Have a nice day."
Rem ===================================
Rem The endpoint (staging/Production)
Rem ===================================
Dim strURL As String
strURL = "http://staging-api.call-em-all.com/webservices/ceaapi_v2.asmx"
Rem For Production use the following
Rem ================================
Rem strURL = "http://api.call-em-all.com/webservices/ceaapi_v2.asmx"
Rem ================================
Dim FunctionName As String
FunctionName = "ExtCreateBroadcast"
Dim SoapPost As String
SoapPost = "<?xml version=""1.0"" encoding=""utf-8""?>" _
& "<soap12:envelope
xmlns:xsi="&quot;http://www.w3.org/2001/XMLSchema-instance&quot;"
xmlns:xsd="&quot;http://www.w3.org/2001/XMLSchema&quot;"
xmlns:soap12="&amp;quot;http://www.w3.org/2003/05/soap-envelope&amp;quot;">&quot; _
& "<soap12:body>" _
& "<" & FunctionName & " xmlns="&quot;http://call-em-all.com/&quot;">" _
& " <myRequest>" _
& " <username>" & username & "</username>" _
& " <pin>" & pin & "</pin>" _
& " <phoneNumberSource>" & phoneNumberSource & "</phoneNumberSource>" _
& " <broadcastName>" & broadcastName & "</broadcastName>" _
& " <broadcastType>" & broadcastType & "</broadcastType>" _
& " <checkCallingWindow>" & checkCallingWindow & "</checkCallingWindow>" _
& " <commaDelimitedPhoneNumbers>" & commaDelimitedPhoneNumbers & "</commaDelimitedPhoneNumbers>" _
& " <TTSText>" & TTSText & "</TTSText>" _
& " </myRequest>" _
& "</" & FunctionName & ">" _
& "</soap12:Body>" _
& "</soap12:Envelope>"
Rem ================================
Rem Debugging use
Rem ================================
Rem MsgBox (SoapPost)
Rem ================================
Dim xmldoc As Object
Set xmldoc = CreateObject("MSXML2.DOMDocument")
xmldoc.async = False
xmldoc.loadXML (SoapPost)
Dim oReq As Object
Set oReq = CreateObject("MSXML2.XMLHTTP")
Dim oDOM As Object
Set oDOM = CreateObject("MSXML2.DOMDocument.3.0")
oDOM.async = "false"
Dim oNodeList As IXMLDOMNodeList
On Error GoTo ErrRoutine
oReq.Open "POST", strURL, False
oReq.setRequestHeader "Host", "api.call-em-all.com"
oReq.setRequestHeader "Content-Type", "application/soap+xml; charset=""utf-8"""
oReq.setRequestHeader "Content-Length", Len(SoapPost)
oReq.send xmldoc.XML
Rem ================================
Rem Debugging use
Rem ================================
Rem MsgBox (xmldoc.XML)
Rem ================================
oDOM.loadXML (oReq.responseText)
Rem ================================
Rem Debugging use
Rem ================================
Rem MsgBox (oReq.responseText)
Rem ================================
Rem ================================
Rem Destroy the request object
Rem ================================
Set oReq = Nothing
Dim errorCode As String
Dim errorMessage As String
Rem ================================
Rem Get the result codes
Rem ================================
Set oNodeList = oDOM.getElementsByTagName(FunctionName & "Result/errorCode")
If oNodeList.length = 0 Then
MsgBox ("FAILURE Proper response not returned")
GoTo EndRoutine
Else
errorCode = oNodeList.Item(0).Text
End If
Set oNodeList = oDOM.getElementsByTagName(FunctionName & "Result/errorMessage")
errorMessage = oNodeList.Item(0).Text
MsgBox ("ErrorCode: " & errorCode & vbCrLf & "ErrorMessage: " & errorMessage)
Rem ================================
Rem Use the XML Dom to get any other
Rem data passed back
Rem ================================
Rem ======================
Rem To be completed soon
Rem ======================
EndRoutine:
Exit Sub
ErrRoutine:
MsgBox Err.Number & " - " & Err.Description, _
vbOKOnly Or vbCritical, _
"TestXMLHTTP"
GoTo EndRoutine
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment