What is the correct way to call a sub account's twilio number? This is my current approach bellow.
async function placeCall(context, event, callback) {
var to = event.Called;
var from = event.From;
var toClient = "";
var blockListArr = [];
let blocked = true;
let donotDist = false;
var apiKeyDb = "calles's api key";
var apiSecretDb = "callee's api key secret";
console.log("event : " + JSON.stringify(event));
var url = "https://demo.twilio.com/docs/voice.xml";
console.log(url);
const accountSid = context.ACCOUNT_SID;
const client = require('twilio')(apiKeyDb, apiSecretDb, {
accountSid: event.AccountSid
});
if (isNumber(to)) {
call = await client.api.calls.create({
url: url,
to: to,
from: from,
});
console.log(call.sid)
return callback(null, JSON.stringify(call));
}
}
exports.handler = function(context, event, callback) {
var p1 = new Promise(function(resolve, reject) {
resolve(placeCall(context, event, callback));
});
p1.then(function(value) {
console.log("val : " + value); // "Success!"
throw new Error('error');
}).catch(function(e) {
console.error("error : " + e.message);
console.error("error : " + e.status);
});
};
function isNumber(to) {
if (to.length == 1) {
if (!isNaN(to)) {
return true;
}
} else if (String(to).charAt(0) == '+') {
number = to.substring(1);
if (!isNaN(number)) {
return true;
}
} else {
if (!isNaN(to)) {
return true;
}
}
return false;
}
But i am receiving
error : The source phone number provided, +88016855548.., is not yet verified for your account. You may only make calls from phone numbers that you've verified or purchased from Twilio.
How can anyone be able to call sub account's twilio number where verification is not required? It can be from another sub account's twilio number or out side twilio number (Real Phone number)