0

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)

philnash
  • 70,667
  • 10
  • 60
  • 88
A_Rush
  • 368
  • 3
  • 14

1 Answers1

0

You will have to use either a Verified CallerID in the account you are calling From or a Twilio number in the account you are calling From as the CallerID.

This article covers how to bulk add Verified CallerID's across sub-accounts. This will work when you know the CallerID, it won't work for spoofing inbound PSTN numbers toward you sub-account.

Verifying Caller Ids at Scale

Alan
  • 10,465
  • 2
  • 8
  • 9
  • I've verified a number on that sub account. And i changed my [placeCall](https://pastebin.com/YTd8aTit) endpoint. Is this approach is okay now? – A_Rush May 10 '20 at 14:06
  • when i make a call to my sub account's twilio number i hear a ringing beep, then it start reading some parameters. – A_Rush May 11 '20 at 06:26
  • i get " 52131 - Invalid APNs credentials" this error on sub account's debugger. – A_Rush May 11 '20 at 07:53
  • it is also charging me around 0.01$ per call. can you tell me what i am missing here? – A_Rush May 11 '20 at 09:53
  • Invalid APN is related to Push and not making calls, that error is not related to this issue. Specific to show calls are charged, that should be covered in this article - How Much am I Charged for Call Forwarding with Twilio? - https://support.twilio.com/hc/en-us/articles/223132367-How-Much-am-I-Charged-for-Call-Forwarding-with-Twilio- – Alan May 11 '20 at 10:37
  • well can you tell me how can i solve this error? right now i am not getting any error but there is no call i am receiving either. what i am missing? you got my endpoint. can you tell me how to fix this? – A_Rush May 11 '20 at 10:47
  • I recommend contacting Twilio support, either via the Twilio Console upper right corner via the ? icon or help@twilio.com, they will have to get much more detail from you to troubleshoot these issues. – Alan May 11 '20 at 12:08