GCJH
GCJH

Reputation: 113

Twilio inbound SMS using webhooks and Coldfusion

I have setup SMS on Twilio and can receive an SMS via webhooks. I can manipulate the form data to do what I want however every inbound SMS message throws an error on Twilio's dashboard. It's looking for some response. Right now I'm just dumping the form to a text file while testing.

<!doctype html>
<?xml version="1.0" encoding="UTF-8"?>
<html>
<head>
<Response>   
</Response>
    <cfdump
        var="#form#"
        label="HTTP Body" output="C:/webhook-sms.txt"
        />
</head>
</html>

The error is: MESSAGE The markup in the document preceding the root element must be well-formed. Warning - 12200 Schema validation warning The provided XML does not conform to the Twilio Markup XML schema. Please refer to the specific error and correct the problem.

What do I need to respond to Twilio with?

Thanks in advance for any help!

Gary

Upvotes: 2

Views: 360

Answers (2)

GCJH
GCJH

Reputation: 113

Thanks everybody. My final test code looked like this:

    <cfsetting enablecfoutputonly="true" showdebugoutput="false" requesttimeout="30" />
<cfheader name="content-type" value="text/xml" />
<cfoutput><?xml version="1.0" encoding="UTF-8"?>

<Response>
    <Message>Thanks for getting in touch, I'll call you later</Message>
</Response></cfoutput>

Upvotes: 2

Alex Baban
Alex Baban

Reputation: 11702

Twilio expects a content type of text/xml and also expects the first line of the response to be <?xml version="1.0" encoding="UTF-8"?>.

If your response has one or more empty lines before <?xml version="1.0" encoding="UTF-8"?> you're still going to get an error.

What I ended up doing, was with an Application.cfm something like this:

<cfsetting enablecfoutputonly="true" showdebugoutput="false" requesttimeout="30" />
<cfheader name="content-type" value="text/xml" />
<!--- // more code --->

and endpoint files which start with the first line like this:

<cfoutput><?xml version="1.0" encoding="UTF-8"?></cfoutput>
<!--- // more code --->

And make sure you send back valid TwiML (Twilio's XML) (no HTML).

Upvotes: 3

Related Questions