2

I have a very simple question about gathering DTMF inputs from users via an outbound call made to them. I am describing the requirement below.

Main Requirement I have a python script that makes outbound calls to a particular number. The person accepts the call. I say the information to them via the twiml configured. The person hears the info and presses a key on their phone. I want to capture that key input and just print it as an output using my script.

The problem I am able to make the outbound call using the client.calls.create method described here. https://www.twilio.com/docs/voice/tutorials/how-to-make-outbound-phone-calls-python But I am unable to gather the digits. The examples I have seen online are describing how to achieve gathering inputs with a running web application. I am NOT using this method. I am looking to get this done via a simple script. I initiate the outgoing call from the Twilio number via the script. I don't intend to use any web applications or webhooks here.

I am putting the code below that works until making the call and reciting the options to the user.

How can I get this done? Is this possible? Many thanks.

import os
from twilio.rest import Client
from twilio.twiml.voice_response import Gather, VoiceResponse, Say

account_sid = os.environ['TWILIO_ACCOUNT_SID']='XXXXX'
auth_token = os.environ['TWILIO_AUTH_TOKEN']='YYYYY'
client = Client(account_sid, auth_token)

call = client.calls.create(
                        twiml='<?xml version="1.0" encoding="UTF-8"?><Response><Gather input="dtmf" timeout="5" numDigits="1"><Say>Please press 1 for sales</Say></Gather></Response>',
                        to='Destination_Number',
                        from_='My_Twilio_Number'
                    )




#TODO - How to Gather Digits from the user????
ronkings
  • 21
  • 1

1 Answers1

0

Twilio developer evangelist here.

There are many ways to interact with a phone call through Twilio, but when you are trying to take user input through <Gather> all of them require Twilio to be able to notify you of the digits that the user pressed. Since this is an asynchronous action, the basic method of doing so is via a webhook, an HTTP request, sent to a web application that you control.

If you do not want to host an application that responds to webhooks yourself, you could achieve this flow using Twilio Studio, which is a drag and drop editor for communications flows, or using Twilio Functions, which is a serverless environment where you can respond to incoming HTTP requests with JavaScript functions.

philnash
  • 70,667
  • 10
  • 60
  • 88