0

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

squirrel
  • 1
  • 2

1 Answers1

1

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.

  • Hallo Johannes, thanks for the reply. I don't really understand what you mean, though. The code snippet looks to me like it is something other than VBA, maybe PHP? – squirrel Nov 27 '15 at 20:23
  • If you read my answer you will see that I actually gave you two possible ways to solve your problem - one using PHP. As I wrote. I put half an hour of work into the answer. Please have the curtesy to at least try to read it. –  Nov 27 '15 at 20:29
  • Hallo again, I just re-read what you said and you actually mentioned that the bottom was PHP, I wasn't paying attention, my apology. My point with this was to do it without a public web server. We have solution that includes one, but if we could get this working without then it would be way more powerful in terms of different people using it. Reminder calls have been elusive for a lot of organizations I work with, and an Access program that could do it without need for a server would be hugely useful. I will look into the coding you mention, thanks for the pointer. – squirrel Nov 27 '15 at 21:28
  • I tried the echo twimlet you gave (and a few variations) but I keep getting an error like this: 21402Url is not a valid URL: http://twimlets.com/echo?Twiml=<Response><Say voice="woman" language="fr">Bonjour Monsieur!</Say></Response>https://www.twilio.com/docs/errors/21402400. I think some characters are getting mixed up during the send. – squirrel Nov 27 '15 at 21:47
  • The example I mentioned in the question had an earlier version that gave same problem. In later version they use a function to encode the text to fix it. I don't understand what it does, though. – squirrel Nov 27 '15 at 21:51
  • What exactly did you send to the wimlet? –  Nov 27 '15 at 22:07
  • If you use the SendSms function of the tutorial, you have to modify it so it has as 3rd parameter "url" (instead of body) and as value of that url you need the string I discussed above. I will amend my answer. –  Nov 27 '15 at 22:29