user330739 user330739 - 11 months ago 106
Python Question

Twilio: Wait for call status before executing next command in Python

Hi I am still trying to wrap my head around Twilio's API. Could someone please provide some guidance on this issue? I will be extremely grateful!:

I am attempting to execute the following command in Python Django:

for customerServiceRep in availCustomerServiceReps:
client = TwilioRestClient(account_sid, auth_token)
call = client.calls.create(to="+1" + str(int(customerServiceRep[0])),
from_="+19xxxxxxxxx", url="")


I am basically going through each available customer service rep and dialing them (because a customer was just enqueued moments before). But right now, I am simultaneously calling all the customer service reps (since the for loop is going through all of them and calling). I am trying to figure out how I can "wait" that for loop for a call to come back as ["busy", "not available", "fail", etc] before it goes and calls the next available rep.

This is very similar to the "findme" twimlet ( except I cant wrap my head around how each number's "status" is checked before the next call goes out.


Twilio evangelist here.

I think your question is pretty close to this one.

Basically you're going to need to use the StatusCallback parameter to have Twilio tell your app what the result of the outbound call is. You can either dial everyone at once like you show above, then when someone answers just use the REST API to terminate all of the other outbound calls, or you can make one outbound call at a time, wait for Twilio to call the StatusCallback URL and then decide if you need to call the next agent or not.

Hope that helps.