You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Plivo Browser SDK呼叫转接至音频录音功能实现咨询

How to Transfer a Plivo Browser SDK Call to Audio Recording

Got it, let's walk through how to add call transfer to recording with the Plivo Browser SDK since you already have the basics (endpoint login, outbound calls) working. Here's a step-by-step breakdown:

1. First, Track Your Active Call (Identify the Target)

Before you can transfer a call, you need to grab the unique identifier for the active call—this is the callUuid property from the call object Plivo returns when you initiate or receive a call. Save this somewhere accessible (like a global variable or component state) so you can reference it later.

Example code to capture the call:

// Initialize your Plivo client first (you probably already have this)
const plivoClient = new Plivo.Client();
let activeCall;

// Capture outgoing calls
plivoClient.on('call:outgoing', (call) => {
  activeCall = call;
  console.log('Active call UUID:', activeCall.callUuid);
});

// Capture incoming calls (don't forget to answer first!)
plivoClient.on('call:incoming', (call) => {
  call.answer();
  activeCall = call;
  console.log('Incoming call UUID:', activeCall.callUuid);
});

2. Use the Browser SDK's transfer Method to Initiate the Transfer

Once you have the active call object, you can use its built-in transfer method to send the call to your recording endpoint. The key parameter here is legUrl—this is the public URL that returns Plivo XML to trigger the recording.

Example transfer function:

function transferToRecording() {
  if (!activeCall) {
    console.error('No active call found to transfer!');
    return;
  }

  // Trigger the transfer
  activeCall.transfer({
    legUrl: 'https://your-public-server.com/plivo-recording-xml' // Replace with your endpoint
  })
  .then(() => {
    console.log('Call transfer to recording initiated successfully');
  })
  .catch((err) => {
    console.error('Transfer failed:', err);
  });
}

3. Configure Your legUrl to Return Recording XML

Your legUrl endpoint needs to return valid Plivo XML that tells Plivo to start recording the call. This XML should include the <Record> element, which handles the recording logic. You can also add a prompt message using <Speak> to let the caller know they're being recorded.

Example XML Response (Node.js/Express):

// On your server, create an endpoint that returns this XML
app.get('/plivo-recording-xml', (req, res) => {
  const recordingXml = `
    <Response>
      <Speak>Please leave your message after the tone. Press the pound key when finished.</Speak>
      <Record 
        action="https://your-public-server.com/recording-completed" 
        maxLength="3600" 
        finishOnKey="#"
        recordSession="true"
      />
      <Hangup/>
    </Response>
  `;
  res.set('Content-Type', 'text/xml');
  res.send(recordingXml);
});

Key <Record> Attributes:

  • action: The URL Plivo sends a POST request to when the recording finishes (contains details like the recording URL, duration, etc.)
  • maxLength: Maximum recording time in seconds (default is 3600, or 1 hour)
  • finishOnKey: A key the caller can press to end the recording early
  • recordSession: Ensures the entire call segment is recorded

4. Handle the Recording Completion Callback

When the recording ends, Plivo will send data to your action URL. You can use this to save the recording URL to your database, notify users, or process the recording further.

Example callback handler (Node.js/Express):

app.post('/recording-completed', (req, res) => {
  const recordingData = req.body;
  // Extract key details: recording_url, duration, call_uuid, etc.
  console.log('Recording finished:', recordingData);
  
  // Save the recording URL to your system here
  // saveToDatabase(recordingData.recording_url);

  res.sendStatus(200); // Let Plivo know you received the data
});

Important Notes:

  • Make sure your legUrl and action URLs are publicly accessible—Plivo needs to reach them to fetch the XML and send the callback.
  • If you're testing locally, use a tool like ngrok to expose your server to the internet.
  • You can customize the XML to add more logic (like redirecting after recording, playing a confirmation message, etc.)

内容的提问来源于stack exchange,提问作者Matt Price

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 07:36:31