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

Can't Place Outbound Call With Twilio: Connection Declined Error

我正在使用 Laravel PHP 框架和 Vue.JS 为我的前端编写应用程序。我已按照 Twilio 浏览器的 phone 指南进行操作,并且在网络上搜索了数小时的问题,但无法接到 place 的出站呼叫。

我从我的 api 中获得了一个功能令牌,然后我用它连接到一个 phone 号码...

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

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