Christopher Sparks
Christopher Sparks

Reputation: 75

How do I modify a in-progress call by sending a digit with Twilio-Python?

I have an app that makes a outbound call to user A.

User A answers and either says "foo" or "bar"

If User A says "foo" -> c.calls(callSid).update(status="complete")

If User A says "bar" -> twilio.update('press the number 2')

How can I implement this?

I'm using the Python helper library and have tried this.

call = c.calls(callSid).update(twiml="<Play digits='2'/>")

But the app errors out.

Upvotes: 0

Views: 126

Answers (1)

yvesonline
yvesonline

Reputation: 4837

In your outbound call use TwiML to ask the user to say "foo" or "bar" and then supply a webhook which can be called to process the response, i.e.:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Gather input="speech" timeout="5" action="<your webhook>">
        <Say>Please say foo or bar.</Say>
    </Gather>
</Response>

Twilio will do a POST to the specified webhook in action and the user answer will be stored in SpeechResult along with a confidence score in Confidence. You can then continue with your business logic as you outlined.

For more information on Gather have a look at the TwiML documentation.

Upvotes: 1

Related Questions