Не удается выполнить исходящий вызов с помощью Twilio: ошибка соединения отклонена - PullRequest
0 голосов
/ 17 октября 2019

Я программирую приложение с помощью фреймворка 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

1 Ответ

0 голосов
/ 18 октября 2019

Эта проблема связана с тем, что мой URL в приложении TwiML был настроен на http, а не на https. Обратите внимание, что приложения TwiML не выполняют переадресацию 301.

...