当我的经理拨打美国电话号码时,客户将来电视为"未知姓名"来自twilio app

时间:2018-02-23 11:22:50

标签: twilio twilio-api

我可以解决我的问题以及代码中的错误吗?

问题

  1. 我使用应用程序从twilio号码给我的客户打电话 当我的经理拨打美国电话号码时,客户端将来电视为"未知姓名"
  2. 当我的经理打电话 - 在浏览器中连接到客户端之前保持沉默 然后客户接受电话 - 并且一切正常
  3. 服务器代码

    generateToken: () {
        let clientName = 'twilio_agent';
        let _id = req.body._id;
        let phoneno = req.body.phoneno;
    
        //
        realmsProvider.get({_id: _id})
        .then(data => {
            if (!data) {
                return res.status(404).json({ message: 'Account not found with _id:'+ _id });
            }
    
            var capability = new ClientCapability({
                accountSid: data.sid,
                authToken: data.authToken,
                ttl: config.twilio.ttl
            });
    
            capability.addScope(
              new ClientCapability.OutgoingClientScope({
                    applicationSid: data.application.sid,
                    clientName: data.name,
                    callerId: phoneno
              }));
    
            // incoming call
            if (phoneno != null) {
                capability.addScope(
                    new ClientCapability.IncomingClientScope(phoneno));
            }
            else {
                capability.addScope(
                    new ClientCapability.IncomingClientScope(clientName));
            }
    
            var token = capability.toJwt();
    
            return res.status(200).json({ token: token });
        })
        .catch(err => {
            return utils.handleError(res, err);
        });
    }
    
    voice: () {
        let phoneNumber = req.body.PhoneNumber;
        let callerId = req.body.CallerId;
        let twiml = new VoiceResponse();
    
        let dial = twiml.dial({
            //https://www.twilio.com/docs/api/twiml/dial
            answerOnBridge: true,
            //phone number from
            callerId : callerId,
    
            //record all calls
            record: 'record-from-answer-dual'
        });
    
        if (phoneNumber != null) {
            dial.number(phoneNumber);
        }
    
        dial.client(callerId.replace(/\+/, ''));
    
        res.type('text/xml');
    
        res.send(twiml.toString());
    }
    

    浏览器代码

    Twilio.Device.setup(token, {
        debug: true,
        enableRingingState: true,
        sounds: {
            incoming: 'URL-TO-MP3.mp3',
            outgoing: 'URL-TO-MP3.mp3',
            dtmf8: 'URL-TO-MP3.mp3'
        }
    });
    
    function call(currentPhoneno, phoneTo, companyNameInTwilio) {
        $scope.calling = 1;
    
        if (!validatePhoneno(phoneTo)) {
            growl.error('Bad phone number');
            return;
        }
    
        var connection = Twilio.Device.connect({ // Connect our call.
            CallerId: currentPhoneno, // Your Twilio number (Format: +15556667777).
            PhoneNumber: phoneTo, // Number to call (Format: +15556667777).
            From: companyNameInTwilio
        });
    
        connection.on('ringing', function(hasEarlyMedia) {
            // some code for ringing
        });
    }
    

0 个答案:

没有答案