1

I have a view function that needs to gather multiple pieces of information in one call (it's a quick outbound call - the user answers and is to be immediately prompted for these data points), based on data pulled from a DB. What I'd like the view function to do is something like the following:

group_id = <get group id>
params = data_element_select_params.DataElementSelectParams(group_id=group_id)
data_elements = worker.select(params) # function I wrote which returns a list of objects, in this case objects called DataElements

vr = VoiceResponse()
say_msg = 'Enter {element}, then press star.'

for element in data_elements:
    say_message = say_msg.format(element=element.name)
    <Gather input with say_message and save it>

Can this be achieved without routing to the same URL over and over? I have not seen any other solution, and I'd rather not continually redirect to the same URL as we'll have to pull the list of elements from the DB again for each element.

Apologies if anything is unclear - please point it out and I'll clarify as quickly as I can.

zbbz
  • 177
  • 1
  • 1
  • 9

1 Answers1

1

Twilio developer evangelist here.

You can only use one <Gather> per TwiML document, so no, you can't ask multiple questions and take multiple inputs within the one webhook.

You will need to route to a URL that receives the input from each <Gather> and then asks the next question.

To avoid pulling all the elements from the DB every time, you could investigate saving the elements to the HTTP session and pulling them back out of there. Twilio is a well behaved HTTP client, so you can use things like cookies to store information about the current call/conversation.

philnash
  • 53,704
  • 10
  • 46
  • 69
  • Thanks Phil! I will take a look at saving the elements to the HTTP session and retrieving them from there. – zbbz Nov 17 '18 at 05:08
  • Thanks, Phil. Can you provide some clarity on the session management on Twilio's side? Do you consider an individual call a single session? Want to make sure that we will not get session contamination if we have multiple inbound calls from the same phone number. – Brian P Nov 19 '18 at 04:01
  • 1
    @BrianP I believe that each individual call is a session so there should not be session contamination. If you needed to ensure that yourself on your server, you can use the Call Sid as a key, as that is unique per call. – philnash Nov 19 '18 at 04:09