簡體   English   中英

Twilio 錄音

[英]Twilio Voice Recording

我正在使用 twilio JS 客戶端從 web 進行調用。 客戶端調用后端獲取令牌。 這里是返回令牌的后端代碼。 如何記錄通話。 表示在哪里設置錄音 url。 通話成功。 但是不知道從哪里傳錄音url。

public function newToken(Request $request)
    {
        $accountSid = config('services.twilio')['accountSid'];
        $applicationSid = config('services.twilio')['applicationSid'];
        $apiKey = config('services.twilio')['apiKey'];
        $apiSecret = config('services.twilio')['apiSecret'];

        $voiceGrant = new VoiceGrant();
        $voiceGrant->setOutgoingApplicationSid($applicationSid);

        $voiceGrant->setIncomingAllow(true);

        $this->accessToken->addGrant($voiceGrant);

        $token = $this->accessToken->toJWT();

        return response()->json(['token' => $token]);
    }

在 JS 端,使用 twillio 客戶端庫的代碼。

const Device = Twilio.Device;

// Store some selectors for elements we'll reuse
var callStatus = $("#call-status");
var answerButton = $(".answer-button");
var callSupportButton = $(".call-support-button");
var hangUpButton = $(".hangup-button");
var callCustomerButtons = $(".call-customer-button");

var device = null;

function updateCallStatus(status) {
    callStatus.attr('placeholder', status);
}

/* Get a Twilio Client token with an AJAX request */
$(document).ready(function() {
    setupClient();
});

function setupHandlers(device) {
    device.on('ready', function(_device) {
        updateCallStatus("Ready");
    });

    /* Report any errors to the call status display */
    device.on('error', function(error) {
        updateCallStatus("ERROR: " + error.message);
    });

    /* Callback for when Twilio Client initiates a new connection */
    device.on('connect', function(connection) {
        // Enable the hang up button and disable the call buttons
        hangUpButton.prop("disabled", false);
        callCustomerButtons.prop("disabled", true);
        callSupportButton.prop("disabled", true);
        answerButton.prop("disabled", true);

        // If phoneNumber is part of the connection, this is a call from a
        // support agent to a customer's phone
        if ("phoneNumber" in connection.message) {
            updateCallStatus("In call with " + connection.message.phoneNumber);
        } else {
            // This is a call from a website user to a support agent
            updateCallStatus("In call with support");
        }
    });

    /* Callback for when a call ends */
    device.on('disconnect', function(connection) {
        // Disable the hangup button and enable the call buttons
        hangUpButton.prop("disabled", true);
        callCustomerButtons.prop("disabled", false);
        callSupportButton.prop("disabled", false);

        updateCallStatus("Ready");
    });

    /* Callback for when Twilio Client receives a new incoming call */
    device.on('incoming', function(connection) {
        updateCallStatus("Incoming support call");

        // Set a callback to be executed when the connection is accepted
        connection.accept(function() {
            updateCallStatus("In call with customer");
        });

        // Set a callback on the answer button and enable it
        answerButton.click(function() {
            connection.accept();
        });
        answerButton.prop("disabled", false);
    });
};

function setupClient() {
    $.post("/token", {
        forPage: window.location.pathname,
        _token: $('meta[name="csrf-token"]').attr('content')
    }).done(function(data) {
        // Set up the Twilio Client device with the token
        device = new Device();
        device.setup(data.token);

        setupHandlers(device);
    }).fail(function() {
        updateCallStatus("Could not get a token from server!");
    });

};

/* Call a customer from a support ticket */
window.callCustomer = function(phoneNumber) {
    updateCallStatus("Calling " + phoneNumber + "...");

    var params = { "phoneNumber": phoneNumber };
    device.connect(params);
};

/* Call the support_agent from the home page */
window.callSupport = function() {
    updateCallStatus("Calling support...");

    // Our backend will assume that no params means a call to support_agent
    device.connect();
};

/* End a call */
window.hangUp = function() {
    device.disconnectAll();
};

我假設您在 TwiML 應用程序上設置的 URL 生成的 TwiML 包含動詞,以便將傳入的客戶端呼叫連接到類似 PSTN 號碼的東西。

如果該假設是正確的,那么您可以在該動詞上包含record屬性:

<Response>
 <Dial record="record-from-ringing-dual"
   recordingStatusCallback="https://myapp.com/recording-events"
   recordingStatusCallbackEvent="in-progress completed absent">
   <Number>+15558675310</Number>
 </Dial>
</Response>

對雙通道錄音使用從應答雙記錄或從振鈴雙記錄記錄值,父子呼叫在不同的立體聲軌道中。

有關更多詳細信息,請參閱支持文章使用 Twilio 錄制電話

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM