GRY
GRY

Reputation: 724

Twilio Response Class not found

I am new to Twilio. To learn the basics, I followed the instructions here: https://www.twilio.com/docs/howto/walkthrough/click-to-call/php/laravel#12

At first, my phone would ring, and I would receive a generic message. Impressed, I upgraded my account. Now I receive a call where a voice says "We're sorry an application error has occurred."

I checked my Alerts in Twilio, and found Error: 12100 - Document parse failure

So I checked the url of my outbound.php and realized that there is a PHP error here. The error is

Fatal error: Class 'Response' not found in /home/......./outbound.php on line 16

After some searching, I can't find anyone else discussing this same problem. Finally, the worst part, I can't even find any reference to a Response class in the Twilio Helper Library.

Here is my entire code block for the page in question.

<?php

error_reporting(E_ALL);
require_once 'twilio-library/Services/Twilio.php';


    // A message for Twilio's TTS engine to repeat
    $sayMessage = 'Thanks for contacting our sales department. If this were a 
        real click to call application, we would redirect your call to our 
        sales team right now using the Dial tag.';

    $twiml = new Services_Twilio_Twiml();
    $twiml->say($sayMessage, array('voice' => 'alice'));
    // $response->dial('+12345675309');

    $response = Response::make($twiml, 200);
    $response->header('Content-Type', 'text/xml');
    return $response;

?>

If I change this file to static, well formatted XML then the error stops.

Upvotes: 1

Views: 954

Answers (1)

philnash
philnash

Reputation: 73029

Twilio developer evangelist here.

The tutorial you were following was based within the Laravel framework, which is where the Response class was expecting to come from.

If you are using the PHP TwiML builder in just a plain PHP file, you should be able to just print the $twiml. I'd probably add a Content-Type of text/xml as well, just to be safe. Like this:

<?php
  error_reporting(E_ALL);
  require_once 'twilio-library/Services/Twilio.php';

  // A message for Twilio's TTS engine to repeat
  $sayMessage = 'Thanks for contacting our sales department. If this were a 
    real click to call application, we would redirect your call to our 
    sales team right now using the Dial tag.';

  $twiml = new Services_Twilio_Twiml();
  $twiml->say($sayMessage, array('voice' => 'alice'));
  // $twiml->dial('+12345675309');

  header('Content-type: application/xml');

  print $twiml;
?>

Let me know if this helps at all!

Upvotes: 1

Related Questions