When I call from my local number to twilio number, the webhook makes a POST request /place-call and then ends with fall back error url.
Twilio is unable to process the Content-Type of the provided URL. Please see Twilio's documentation on accepted content types for more information on valid Content-Types. You must return a Content-Type for all requests. Requests without a Content-Type will appear in the Debugger as a 502 Bad Gateway error.
place-call.js file
const callerNumber = '+1XXXXXXXXXX';
const callerId = 'client:alice';
const defaultIdentity = 'alice';
exports.handler = function (context, event, callback) {
var url = 'https://' + context.DOMAIN_NAME + '/incoming';
const client = context.getTwilioClient();
var to = event.to;
if (!to) {
to = event.To;
if (!to) {
console.error("Could not find someone to call");
to = null;
}
}
// console.log("To: " + JSON.stringify(event));
if (!to) {
client.calls.create({
url: url,
to: 'client:' + defaultIdentity,
from: callerId,
}, function (err, result) {
// End our function
if (err) {
callback(err, null);
} else {
callback(null, result);
}
});
} else if (isNumber(to)) {
console.log("Calling number:" + to);
client.calls.create({
url: url,
to: to,
from: callerNumber,
}, function (err, result) {
// End our function
if (err) {
console.log("Error: " + err);
callback(err, null);
} else {
callback(null, result);
}
});
} else {
client.calls.create({
url: url,
to: 'client:' + to,
from: callerId,
}, function (err, result) {
// End our function
if (err) {
callback(err, null);
} else {
callback(null, result);
}
});
}
};
function isNumber(to) {
if (to.length == 1) {
if (!isNaN(to)) {
console.log("It is a 1 digit long number" + to);
return true;
}
} else if (String(to).charAt(0) == '+') {
number = to.substring(1);
if (!isNaN(number)) {
console.log("It is a number " + to);
return true;
};
} else {
if (!isNaN(to)) {
console.log("It is a number " + to);
return true;
}
}
console.log("not a number");
return false;
}
This is the error from the error log:
Twilio is unable to process the Content-Type of the provided URL. Please see Twilio's documentation on accepted content types for more information on valid Content-Types. You must return a Content-Type for all requests. Requests without a Content-Type will appear in the Debugger as a 502 Bad Gateway error.
incoming.js file
//'https://' + context.DOMAIN_NAME + '/incoming'
exports.handler = function(context, event, callback) {
const twiml = new Twilio.twiml.VoiceResponse();
twiml.say("Congratulations! You have received your first inbound call! Good bye.");
callback(null, twiml.toString());
};