0

I'm currently trying to use the twilio python library to start an outgoing call, wait for user input through the keypad or speech while saying a message and then return it through a callback to a php script I have running elsewhere, however even with seemingly good XML used in my twiml, I seem to get an application error when the user hits a key on their keypad, I've included all the details I can below.

Code:

    call = client.calls.create(
        status_callback='https://endpoint.example/myphpscript.php',
        status_callback_method='POST',
        twiml='<?xml version="1.0" encoding="UTF-8"?><Response><Gather action="https://endpoint.example/myphpscript.php" method="POST"><Say>This is a test message, please work</Say></Gather></Response>',
        to=destnumber,
        from_=twilionumber
    )

When this executes it makes the call as expected, and starts to read off the message as defined by <say>, however when the user hits a key on their keypad it says "We're sorry there was an application error."

Looking in my Twilio call logs I can see the twiml recieved and used by twilio which is below "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response><Gather action=\"https://ws.chainsaw.rip/testwilio.php\" method=\"POST\"><Say>This is a test message, please work</Say></Gather></Response>"

The error information as seen in the twilio console is shown below

Msg ""
parserMessage   "Error on line 2 of document : Premature end of file. "
ErrorCode   "12100"
url "https://endpoint.example/myphpscript.php"
LogLevel    "ERROR"

I am pretty new to twilio so any and all help or suggestions would be greatly appreciated, thanks.

  • The TwiML from the call logs you shared is missing the tag enclosures. For example, valid TwiML would be something like: ``` 415-123-4567 ``` – Alan May 04 '22 at 18:59
  • When the user hits the keypad, Twilio will make a request to the `action` URL on your ``. What does that endpoint respond with? I think that's where the error is. – philnash May 12 '22 at 02:03

1 Answers1

0

What are you using to generate your TWIML? I pasted the twiml in the validator after removing \s and it worked. \ after before the " is making your TWIML invalid.

Maybe try using the TWIML bin as the endpoint for the TWIML and see if it works. You should preferably use helper libraries in your language or twiml generators to generate the twiml instructions.

Parzival
  • 47
  • 4
  • I'm just defining it in a variable manually and passing that to the client.call method as it shows to do within the outbound call page of the Twilio documentation https://www.twilio.com/docs/voice/tutorials/how-to-make-outbound-phone-calls-python. – James Hunt May 06 '22 at 19:25
  • You need to generate your twiml through a twiml generator library or make sure it is a valid twiml. – Parzival May 17 '22 at 07:02