【问题标题】:twilio via nodejs to transcribe a call on answer only?twilio 通过 nodejs 仅转录应答呼叫?
【发布时间】:2019-07-08 16:12:18
【问题描述】:

我找到了一个属性 record-on-answer,我正在尝试将其集成到我的 twiml 响应中,但它不起作用。我试图只记录用户回答的时间。 就像我当前的录音有 5 秒的“您的电话无法转接”一样。然后记录了5秒的沉默。然后是实际连接时的呼叫,时间为 26 秒并正确记录。我只想要第三次录音的 26 秒。如果我用普通电话打电话,我永远不会听到“您的电话无法转移”。

我将如何实现这一目标?

这是我的代码:然后是请求正文。如果 twilio 的任何人可以帮助解决这个编码问题,我将非常感激,因为我非常沮丧。我尝试过启用双声道和单声道录制。 敲击键盘

function callUA(twilNum, uaNum){
console.log('in call ua')
client.calls.create({
    url: 'http://www.REMOVED.com/sendT',
    to: '+1'+uaNum,
    from: '+1'+twilNum,
    method: 'POST',
    status_callback_method: 'POST',
    status_callback: 'https://www.REMOVED.com/tS'
})
}//end callua

app.post('/sendT', urlencodedParser, function (req, res) {
console.log(req.body);
  var rt = new VoiceResponse();
    rt.record({
    recordingChannels: 'dual',
    recordOnAnswer: true,
    transcribe: true,
    transcribeCallback: 'http://www.autosecurelogin.com/rT'
});
    rt.hangup();
res.status(200);
res.send(rt.toString());



console.log(' finish sendt')
})//end post


app.post('/rT', urlencodedParser, function (req, res) {
console.log('made to receiveT post');
console.log(req.body);
var ttemp = req['body'].TranscriptionText;
var rightNow = Date.now();
console.log('transcription text ' + ttemp);
var masterFile = __dirname + "/master/transcriptions/"+rightNow+".json";
fs.writeFile(masterFile,  ttemp, function (err) {
})//
res.status(200);
res.send();
console.log('Transcribe Finish');
});



app.post('/tS', urlencodedParser, function (req, res) {


console.log('req');
var ttemp = req['body'];
res.status(200);
res.send();
console.log('in call back tS');
});

in call ua
{ Called: 'REMOVED',
  ToState: 'CO',
  CallerCountry: 'US',
  Direction: 'outbound-api',
  CallerState: 'CO',
  ToZip: '80265',
  CallSid: 'REMOVED',
  To: '+REMOVED',
  CallerZip: '',
  ToCountry: 'US',
  ApiVersion: '2010-04-01',
  CalledZip: '80265',
  CalledCity: 'DENVER',
  CallStatus: 'in-progress',
  From: 'REMOVED',
  AccountSid: 'REMOVED',
  CalledCountry: 'US',
  CallerCity: '',
  Caller: '+17205752321',
  FromCountry: 'US',
  ToCity: 'DENVER',
  FromCity: '',
  CalledState: 'CO',
  FromZip: '',
  FromState: 'CO' }
 finish sendt

in call ua
{ Called: '+REMOVED',
  ToState: 'CO',
  CallerCountry: 'US',
  Direction: 'outbound-api',
  CallerState: 'CO',
  ToZip: '80265',
  CallSid: 'REMOVED',
  To: '+REMOVED',
  CallerZip: '',
  ToCountry: 'US',
  ApiVersion: '2010-04-01',
  CalledZip: '80265',
  CalledCity: 'DENVER',
  CallStatus: 'in-progress',
  From: '+REMOVED',
  AccountSid: 'REMOVED',
  CalledCountry: 'US',
  CallerCity: '',
  Caller: '+REMOVED',
  FromCountry: 'US',
  ToCity: 'DENVER',
  FromCity: '',
  CalledState: 'CO',
  FromZip: '',
  FromState: 'CO' }
 finish sendt

{ Called: '+REMOVED',
  RecordingUrl: 'https://api.twilio.com/2010-04-01/Accounts/REMOVED/Recordings/REMOVED',
  ToState: 'CO',
  CallerCountry: 'US',
  Direction: 'outbound-api',
  CallerState: 'CO',
  ToZip: '80265',
  CallSid: 'REMOVED',
  To: '+REMOVED',
  CallerZip: '',
  ToCountry: 'US',
  ApiVersion: '2010-04-01',
  CalledZip: '80265',
  CalledCity: 'DENVER',
  CallStatus: 'in-progress',
  RecordingSid: 'REMOVED',
  From: '+REMOVED',
  AccountSid: 'REMOVED',
  CalledCountry: 'US',
  CallerCity: '',
  Caller: '+REMOVED',
  FromCountry: 'US',
  ToCity: 'DENVER',
  FromCity: '',
  CalledState: 'CO',
  FromZip: '',
  FromState: 'CO',
  RecordingDuration: '31' }
 finish sendt
{ Called: '+REMOVED',
  RecordingUrl: 'https://api.twilio.com/2010-04-01/Accounts/REMOVED/Recordings/REMOVED',
  ToState: 'CO',
  CallerCountry: 'US',
  Direction: 'outbound-api',
  CallerState: 'CO',
  ToZip: '80265',
  CallSid: 'REMOVED',
  To: '+REMOVED',
  CallerZip: '',
  ToCountry: 'US',
  ApiVersion: '2010-04-01',
  CalledZip: '80265',
  CalledCity: 'DENVER',
  CallStatus: 'in-progress',
  RecordingSid: 'REMOVED',
  From: '+REMOVED',
  AccountSid: 'REMOVED',
  CalledCountry: 'US',
  CallerCity: '',
  Caller: '+REMOVED',
  FromCountry: 'US',
  ToCity: 'DENVER',
  FromCity: '',
  CalledState: 'CO',
  FromZip: '',
  FromState: 'CO',
  RecordingDuration: '5' }
 finish sendt
made to receiveT post
{ ApiVersion: '2010-04-01',
  TranscriptionType: 'fast',
  TranscriptionUrl: 'https://api.twilio.com/2010-04-01/Accounts/REMOVED/Recordings/REMOVED/Transcriptions/REMOVED',
  TranscriptionSid: 'REMOVED',
  Called: '+REMOVED',
  RecordingSid: 'REMOVED',
  CallStatus: 'in-progress',
  RecordingUrl: 'https://api.twilio.com/2010-04-01/Accounts/REMOVED/Recordings/REMOVED',
  From: '+REMOVED',
  Direction: 'outbound-api',
  url: 'http://www.REMOVED.com/rT',
  AccountSid: 'REMOVED',
  TranscriptionText: '',
  Caller: '+REMOVED',
  TranscriptionStatus: 'completed',
  CallSid: 'REMOVED',
  To: '+REMOVED' }
transcription text
Transcribe Finish
{ Called: '+REMOVED',
  Digits: 'hangup',
  RecordingUrl: 'https://api.twilio.com/2010-04-01/Accounts/REMOVED/Recordings/REMOVED',
  ToState: 'CO',
  CallerCountry: 'US',
  Direction: 'outbound-api',
  CallerState: 'CO',
  ToZip: '80265',
  CallSid: 'REMOVED',
  To: '+REMOVED',
  CallerZip: '',
  ToCountry: 'US',
  ApiVersion: '2010-04-01',
  CalledZip: '80265',
  CalledCity: 'DENVER',
  CallStatus: 'completed',
  RecordingSid: 'REMOVED',
  From: '+REMOVED',
  AccountSid: 'REMOVED',
  CalledCountry: 'US',
  CallerCity: '',
  Caller: '+REMOVED',
  FromCountry: 'US',
  ToCity: 'DENVER',
  FromCity: '',
  CalledState: 'CO',
  FromZip: '',
  FromState: 'CO',
  RecordingDuration: '5' }
 finish sendt
made to receiveT post
{ ApiVersion: '2010-04-01',
  TranscriptionType: 'fast',
  TranscriptionUrl: 'https://api.twilio.com/2010-04-01/Accounts/REMOVED/Recordings/REMOVED/Transcriptions/REMOVED',
  TranscriptionSid: 'REMOVED',
  Called: '+17202147065',
  RecordingSid: 'REMOVED',
  CallStatus: 'completed',
  RecordingUrl: 'https://api.twilio.com/2010-04-01/Accounts/REMOVED/Recordings/REMOVED',
  From: '+17205752321',
  Direction: 'outbound-api',
  url: 'http://www.REMOVED.com/rT',
  AccountSid: 'ACcf28aac96af5890681f35809fb0b62eb',
  TranscriptionText: 'Today is Thursday June 27th and the colors of the day are Aqua Baracuda beige and blue confetti the litter Gray Line the melon Onyx are Ange red. And very day thank you.',
  Caller: '+REMOVED',
  TranscriptionStatus: 'completed',
  CallSid: 'REMOVED',
  To: '+REMOVED' }
transcription text Today is Thursday June 27th and the colors of the day are Aqua Baracuda beige and blue confetti the litter Gray Line the melon Onyx are Ange red. And very day thank you.
Transcribe Finish
made to receiveT post
{ ApiVersion: '2010-04-01',
  TranscriptionType: 'fast',
  TranscriptionUrl: 'https://api.twilio.com/2010-04-01/Accounts/REMOVED/Recordings/REMOVED/Transcriptions/REMOVED',
  TranscriptionSid: 'REMOVED',
  Called: '+REMOVED',
  RecordingSid: 'REMOVED',
  CallStatus: 'completed',
  RecordingUrl: 'https://api.twilio.com/2010-04-01/Accounts/REMOVED/Recordings/REMOVED',
  From: '+REMOVED',
  Direction: 'outbound-api',
  url: 'http://www.REMOVED.com/rT',
  AccountSid: 'REMOVED',
  TranscriptionText: 'Your call cannot be transferred please try again later thank you.',
  Caller: '+17205752321',
  TranscriptionStatus: 'completed',
  CallSid: 'REMOVED',
  To: '+REMOVED' }
transcription text Your call cannot be transferred please try again later thank you.
Transcribe Finish

【问题讨论】:

    标签: node.js twilio


    【解决方案1】:

    这里是 Twilio 开发者宣传员。

    我认为您可能需要添加一个action attribute for your <Record>。如果您未在 action 属性中包含 URL,则 Twilio 在完成录制后将不会完成调用,它将再次重定向到相同的操作并再次开始尝试录制。

    我建议将您的 /sendT 方法更新为以下内容:

    app.post('/sendT', urlencodedParser, function (req, res) {
      console.log(req.body);
      var rt = new VoiceResponse();
      rt.record({
        recordingChannels: 'dual',
        recordOnAnswer: true,
        transcribe: true,
        transcribeCallback: 'http://www.REMOVED.com/rT',
        action: 'http://www.REMOVED.com/recorded'
      });
      res.status(200);
      res.send(rt.toString());
      console.log(' finish sendt')
    })//end post
    

    然后再添加一个以<Hangup> 回复的/recorded 端点

    app.post('/recorded', urlencodedParser, function (req, res) {
      var rt = new VoiceResponse();
      rt.hangup();
      res.status(200);
      res.send(rt.toString());
    });
    

    这应该会阻止您收到额外的转录消息。

    【讨论】:

    • 是的,我想通了,忘了删除问题,您之前实际上回答了这个问题,我参考了您的原始答案。哈哈哈。它在文档中,虽然只是一个脚注
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-02-09
    • 2012-01-09
    • 1970-01-01
    • 1970-01-01
    • 2019-11-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多