2
votes

I have a usecase where in voice from a twilio call need to be passed to amazon lex and lex should respond back and twilio should respond with the response. My primary reason for using lex is because of limited amount of hints provided by twilio's <gather>

I see the <Gather> verb from twilio and it does do speech to text, but that has not been useful as the hints take only 50 options and I am looking at more than a thousand. Lex seems too complex but

  1. Is it possible to somehow send the audio to amazon lex ?
  2. If So, how can this be accomplished?

Sorry new to the Voice world :)

1
I have been working on similar use case but with text and wit.ai. To answer your question: yes, it can be achieved, all you have to do is create a server which will receive data from twilio and send it to Lex >> get response from lex >> use twilio api to send response to user.Sheshnath
Here is a link to how I solved this exact problem: stackoverflow.com/questions/51898951/…rocketlobster

1 Answers

2
votes

Twilio developer evangelist here.

You can achieve this, but the experience is not likely to be as quick as using <Gather>. To send audio to Lex you'd need to do the following things:

  1. Record the user using the <Record> TwiML verb.
  2. Set an action attribute on the <Record> that points to some holding TwiML (just something, perhaps silence, for the call to do while we get the results from Lex)
  3. Set a recordingStatusCallback attribute on the <Record>. Twilio will make a webhook request to this URL when the recording is available.
  4. Store the call Sid from the parameter send to the URL above.
  5. Use the RecordingUrl parameter sent to the URL above to download the recording.
  6. Send the recording to Lex to get the result you want.
  7. When you receive the result and want to continue the call for your user, you will need to use the call Sid you saved earlier to redirect the call out of the waiting pattern using the REST API and onwards with the call.

It's not the most straightforward approach (which is why we built this into <Gather>) but this is how people were doing so before.

Let me know if this helps.