Reputation: 8369
I'm trying to make outgoing calls from my twilio trial account. I'm referring this link. Based on this link, I have created one page called hello-client-twiml.php with following code:
<?php
header('Content-type: text/xml');
// put a phone number you've verified with Twilio to use as a caller ID number
$callerId = "+xxxxxxxxxx";
// put your default Twilio Client name here, for when a phone number isn't given
$number = "jenny";
// get the phone number from the page request parameters, if given
if (isset($_REQUEST['PhoneNumber'])) {
$number = htmlspecialchars($_REQUEST['PhoneNumber']);
}
// wrap the phone number or client name in the appropriate TwiML verb
// by checking if the number given has only digits and format symbols
if (preg_match("/^[\d\+\-\(\) ]+$/", $number)) {
$numberOrClient = "<Number>" . $number . "</Number>";
} else {
$numberOrClient = "<Client>" . $number . "</Client>";
}
?>
<Response>
<Dial callerId="<?php echo $callerId ?>">
<?php echo $numberOrClient ?>
</Dial>
</Response>
and hello-client-monkey.php page with the code:
<?php
include "vendor/autoload.php";
use Twilio\Jwt\ClientToken;
// put your Twilio API credentials here
$accountSid = 'your_sid_here';
$authToken = 'your_auth_token';
// put your TwiML Application Sid here
$appSid = 'APXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$capability = new ClientToken($accountSid, $authToken);
$capability->allowClientOutgoing($appSid);
$capability->allowClientIncoming('jenny');
$token = $capability->generateToken();
?>
<!DOCTYPE html>
<html>
<head>
<title>Hello Client Monkey 4</title>
<script type="text/javascript"
src="//media.twiliocdn.com/sdk/js/client/v1.3/twilio.min.js"></script>
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
<link href="//static0.twilio.com/resources/quickstart/client.css"
type="text/css" rel="stylesheet" />
<script type="text/javascript">
Twilio.Device.setup("<?php echo $token; ?>");
Twilio.Device.ready(function (device) {
$("#log").text("Ready");
});
Twilio.Device.error(function (error) {
$("#log").text("Error: " + error.message);
});
Twilio.Device.connect(function (conn) {
$("#log").text("Successfully established call");
});
Twilio.Device.disconnect(function (conn) {
$("#log").text("Call ended");
});
Twilio.Device.incoming(function (conn) {
$("#log").text("Incoming connection from " + conn.parameters.From);
// accept the incoming connection and start two-way audio
conn.accept();
});
function call() {
// get the phone number to connect the call to
params = {"PhoneNumber": $("#number").val()};
Twilio.Device.connect(params);
}
function hangup() {
Twilio.Device.disconnectAll();
}
</script>
</head>
<body>
<button class="call" onclick="call();">
Call
</button>
<button class="hangup" onclick="hangup();">
Hangup
</button>
<input type="text" id="number" name="number"
placeholder="Enter a phone number to call"/>
<div id="log">Loading pigeons...</div>
</body>
</html>
In Twilio console, TwiML apps page, I have added http://mywebsite.com/hello-client-monkey.php as Voice->Request URL.
Now, when I run the page hello-client-monkey.php, the call is getting terminated automatically and in twilio console logs I'm getting error log as:
WARNING
12200 Schema validation warning
DESCRIPTION
Cannot find the declaration of element 'html'.
Can anyone help me to fix this issue? Thanks in advance.
Upvotes: 1
Views: 1200
Reputation: 3811
From the docs:
https://www.twilio.com/docs/api/errors/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.
Possible Causes
misspelled verbs, incorrect case for verbs, misspelled or unknown attributes, unknown or unexpected nested elements.
Possible Solutions
check the line and column reported by the warning to see what part of your XML response caused the complaint
As Devin suggests above, your TwiML application expects twiml as you've defined in hello-client-twiml.php.
Upvotes: 0