Recording multiple user answers in Twilio call

Deadly 提交于 2019-12-11 06:27:13

问题


I am building an Interactive Voice Assistant using Twilio. My goal is to record parts of the conversation, process the recorded audio and

This is the answer to the /voice webhook (the one will receive Twilio's call)

<Response>
    <Play>./welcome</Play>
    <Record maxLength="10" action="/processing" recordingStatusCallback="/getRecording"></Record>
</Response>

Processing the audio and providing an answer may take a long time, so I added a Pause at the end of /processing:

<Response>
    <Play>./ok</Play>
    <Pause length="10"></Pause>
</Response>

This is the answer when finished with /getRecording

<Response>
    <Play>./answer</Play>
    <Record maxLength="10" action="/processing" recordingStatusCallback="/getRecording "></Record>
</Response>

/welcome, /ok and /answer lead to corresponding audio files.

So I was able to execute all steps, I can check in my logs that /getRecording is actually executed to the end and the twiml sent back again, but the /answer after /getRecording is never executed by Twilio (and the call just ends).

Do you have any guidance for it? Does Twilio accept multiple recordings on the same call?

Note: For some reason, if instead of using the 'recordingStatusCallback' I use /getrecording as 'action' it does work... but then we wouldn't be sure the recording we are using is really generated, right?

Thank you for your help!


回答1:


Twilio developer evangelist here.

Your /getRecording endpoint is called, however that is an asynchronous webhook in the context of the call. Returning TwiML to the recordingStatusCallback will not affect the current call.

Instead, you should use the REST API to modify the call by redirecting it to the next TwiML you want to execute based on the response to the recording file.

Hopefully the recording does take less than the 10 second pause that you are using, but you may want to add a loop into your /processing endpoint so that the call won't hang up on your caller. You can do this by redirecting the caller back to the start again:

<Response>
    <Play>./ok</Play>
    <Pause length="10"></Pause>
    <Redirect>./processing</Redirect>
</Response>

Then, when you get the recording callback you redirect your caller out of this loop.

Let me know if that helps at all.



来源:https://stackoverflow.com/questions/43599336/recording-multiple-user-answers-in-twilio-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!