无法使用Twilio进行出站呼叫:连接被拒绝错误

问题描述 投票:0回答:1

我正在使用Laravel PHP框架和Vue.JS作为前端的应用程序。我已遵循Twilio浏览器的电话指南,并在网上搜索了数小时的问题,但无法拨出电话。

我从我的api中获得了功能令牌,然后我将其用于连接到电话号码...

makeCall(number) {
      number = number.replace(/\D/g, "");
      number = "1" + number;

      // Grab the authusers token
      const authUser = JSON.parse(window.localStorage.getItem("authUser"));

      // Get a capability Token
      this.$http
        .get("calls/capability-token", {
          headers: { Authorization: "Bearer " + authUser.access_token }
        })
        .then(response => {
          const capabilityToken = response.body;
          const self = this;

          // Set up the Twilio Client Device with the token
          Twilio.Device.setup(capabilityToken);

          Twilio.Device.ready(device => {
            self.dialResident(number);
          });
        })
        .catch(response => {
          console.log(response);
          this.$swal({
            title: "Error!",
            text: "There was a server error. Please try again later.",
            type: "error",
            showCancelButton: false,
            confirmButtonText: "Ok"
          });
        });
    },
    dialResident(number) {
      const params = { To: number, debug: true };
      console.log("Calling " + params.To + "...");
      Twilio.Device.connect(params);
    }

然后,我将其传递给PHP的后端:

// Make a call
    public function getCapabilityToken(Request $request)
    {
        // Generate a capability token
        $sid = env('TWILIO_SID');
        $token = env('TWILIO_TOKEN');
        $appSid = env('TWILIO_APP_SID');

        $capability = new ClientToken($sid, $token);
        $capability->allowClientOutgoing($appSid);
        $jwtToken = $capability->generateToken();
        return $jwtToken;
    }

    // Twilio TWIML Voice Hook
    public function voiceHook(Request $request)
    {
        $response = new TwiMl();
        $callerIdNumber = env('TWILIO_FROM');

        $dial = $response->dial(['callerId' => $callerIdNumber]);

        $phoneNumberToDial = $request->input('phoneNumber');

        $dial->number($phoneNumberToDial);

        return $response;
    }

并且每次我从调试器收到以下错误:

Error - 11750
TwiML response body too large
In your response to Twilio's request, the response body is larger than 64 kB.



login.js:1 Received an error from the gateway:
{code: 31002, connection: t, message: "Connection Declined", twilioError: Error
    at new n (https://senior.422clients.com/js/login.js:28:96402)
    at m.i._onHangup (https…}
code: 31002
connection: t {_events: {…}, _eventsCount: 6, _maxListeners: undefined, parameters: {…}, _inputVolumeStreak: 0, …}
message: "Connection Declined"
twilioError: Error at new n (https://senior.422clients.com/js/login.js:28:96402) at m.i._onHangup (https://senior.422clients.com/js/login.js:31:221564) at m.l.emit (https://senior.422clients.com/js/login.js:31:337569) at m._handleTransportMessage (https://senior.422clients.com/js/login.js:28:263330) at t.l.emit (https://senior.422clients.com/js/login.js:31:337569) at WebSocket.a._onSocketMessage (https://senior.422clients.com/js/login.js:1:64040)
causes: []
code: 31005
description: "Connection error"
explanation: "A connection error occurred during the call"
solutions: []
message: ""
stack: "Error↵ at new n (https://senior.422clients.com/js/login.js:28:96402)↵ at m.i._onHangup (https://senior.422clients.com/js/login.js:31:221564)↵ at m.l.emit (https://senior.422clients.com/js/login.js:31:337569)↵ at m._handleTransportMessage (https://senior.422clients.com/js/login.js:28:263330)↵ at t.l.emit (https://senior.422clients.com/js/login.js:31:337569)↵ at WebSocket.a._onSocketMessage (https://senior.422clients.com/js/login.js:1:64040)"
__proto__: Error
__proto__: Object
php twilio twilio-api twilio-php twilio-twiml
1个回答
0
投票

此问题是因为我在TwiML应用程序中的URL设置为http而不是https。请注意,TwiML应用程序不遵循301重定向。

© www.soinside.com 2019 - 2024. All rights reserved.