I am trying to implement a automated calling in MS Access using Twilio. There is a Twilio example on how to get started, and I was able to get it to work for our setup. However, it uses a twimlet in the http request to launch the call. From what I can see, the twimlet will only accept the number to call and the text to speak. Is there a way to access the other parameters of a twilio call from MSA/VBA, e.g. the voice, pauses, machine detection etc? I could imagine a twimlet that accepts TWIML, or a direct way to send twiml without needing a return-to URL. Thoughts
1 Answers
You can use the Echo Twimlet. In the Configurator place all the infos that you want twilio to process (Look in TwilioML-API Reference for the right verbs).
Your Question could look something like:
<Response>
<Say voice="woman" language="fr">Bonjour Monsieur!</Say>
</Response>
The Configurator gives you back an URL that looks like this:
http://twimlets.com/echo?Twiml=%3CResponse%3E%0A%3CSay%20voice%3D%22woman%22%20language%3D%22fr%22%3EBonjour%20Monsieur!%3C%2FSay%3E%0A%3C%2FResponse%3E%0A&
Now you would need to replace the Text Bonjour%20Monsieur!
with your automatically generated text.
UPDATE: The prepareTwimletAdr creates the same string as the Configurator. So now your VisualBasic-send-routine could look something like this:
Function VoiceCall(fromNumber As String, toNumber As String, twimletAdr As String)
Dim CallUrl As String
CallUrl = BASEURL & "/2010-04-01/Accounts/" & ACCOUNTSID & "/Calls"
' setup the request and authorization
Dim http As MSXML2.XMLHTTP60
Set http = New MSXML2.XMLHTTP60
http.Open "POST", CallUrl, False, ACCOUNTSID, AUTHTOKEN
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
Dim postData As String
postData = "From=" & fromNumber _
& "&To=" & toNumber _
& "&Url=" & twimletAdr
' send the POST data
http.send postData
.....
End Function
Function prepareTwimletAdr(msg as String, voice as String="woman", lang as String="en")
dim adr as string
adr="http://twimlets.com/echo?Twiml=%3CResponse%3E%0A%3CSay%20"
adr=adr & "voice%3D%22" & voice & "%22%20"
adr=adr & "language%3D%22" & lang & "%22"
adr=adr & "%3E"
adr=adr & Replace(msg," ","%20"
adr=adr & "%3C%2FSay%3E%0A%3C%2FResponse%3E%0A&"
prepareTwimletAdr=adr
End Function
And you'd call it with
VoiceCall myNumber, callingTo, prepareTwimletAdr("Hello, this is my message","alice","en-gb")
An alternative to this is if you have a public webserver with PHP that Twilio can reach, you could process the messages there. The URL then would be your server with the Parameters you need (http://yourCompany.com/TwilioApp?say=hello&voice=woman
) and the PHP-code on your webserver should give back the appropriate XML. There is a PHP TwiML Library you could use that helps you put together XML responses:
/* Put this in the response function of your /TwilioApp-route */
$response = new Services_Twilio_Twiml();
$message = $_GET['say'];
$voice = $_GET['voice'];
$response->say($message);
$response->voice($voice);
echo $response;
If you go this way it should be possible to generate the XML on your own and use the full potential of the TwiML library.
21402