TwiML - Can I record an user AND gather keypad inputs in the same call?

248 views Asked by At

its pretty straight forward to either record and transcribe an user's call, or gather input from the user's keypad after prompting them with a recording. It is not clear to me however, what steps I should take to record the users 'description' of the problem (in this case) AND gather user input that will help me route their 'request' in the same call, so that TwiML can POST this data in one request.

Has anyone encountered this scenario, and can you point me in the right direction if you have? Thanks.

1

There are 1 answers

0
rafaCode On BEST ANSWER

I'm answering my own question in case anyone needs help in the future.

In my particular scenario, I needed to prompt the user to press a key in order to route the "request" being placed. I also needed the request to include a description, hence the need to also record the users voice.

This is not as complicated as it sounded (I know that now), what you need is to respond to the TwiML action when gathering key presses, with another XML document that handles the voice recording. This XML, in theory, would use the "digits" received from TwiML to construct a new action src in the second XML (routing).

The first XML would look something like this to gather the user input:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Gather action="hxxp://example.com/pick_dish" timeout="10" finishOnKey="*">
        <Say>Please press 1 for tacos, 2 for pancakes, 3 for pizza, etc.</Say>
    </Gather>
</Response>

Then when we receive the $_REQUEST (PHP) at hxxp://example.com/pick_dish, we would use the Digits parameter sent to replace "dish_id" in our response XML like so:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Say>
        Please describe the dish you selected after the beep. 
        Press the star key when finished. 
    </Say>
    <Record
        action="hxxp://example.com/save_dish/<dish_id>/description"
        method="GET"
        maxLength="20"
        transcribe="true"
        finishOnKey="*"
        />
    <Say>I did not receive a recording</Say>

The /Description path would then save the description for the dish_id provided.