如果用户没有接听,Twilio 在出站呼叫中发送语音消息 [英] Twilio send a voice message if user doesn't answer, in an outbound call

查看:34
本文介绍了如果用户没有接听,Twilio 在出站呼叫中发送语音消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是使用 twilio 的新手.我正在使用 twilio 从浏览器到电话拨打电话.在浏览器端,我使用 twiml 设备连接到呼叫.

I am new to using twilio. I am using twilio to make calls from browser to phone. In the browser side I am using twiml Device to connect to the call.

Twilio.Device.connect({ phoneNumber: phoneNumber, userId: id });

在 nodejs 服务器端,我使用了这段代码.

In the nodejs server side I am using this code.

import twilio from 'twilio';

const VoiceResponse = twilio.twiml.VoiceResponse; 

let phoneNumber = req.body.phoneNumber;
let callerId = user.phoneNumber;
let twiml = new VoiceResponse();

let dial = twiml.dial({ callerId: callerId });
dial.number(phoneNumber);

res.send(twiml.toString());

如果另一端的用户没有接听电话,我需要通过按下按钮将录音作为语音邮件发送给该用户.

If the user in the other end hasn't answered the call, I need to send a recording by pressing a button as a voicemail to that user.

<button>Send Voicemail</button>

我怎样才能做到这一点?

How can I achieve this?

推荐答案

这应该可以通过结合使用 Twilio 的应答机检测服务和 TwiML 动词来实现.

This should be possible using a combination of Twilio's Answering Machine Detection service and the <Play> TwiML verb.

这是一个代码示例,使用应答机检测进行外呼.

Here is a code sample of making an outbound call with answering machine detection.

const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.calls
  .create({
     machineDetection: 'Enable',
     url: 'https://handler.twilio.com/twiml/EHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
     to: '+1562300000',
     from: '+18180000000'
   })
 .then(call => console.log(call.sid))
 .done();

在您的通话中启用 AMD 后,Twilio 会将通话结果发布到您指定的 webhook.该 webhook 将接收一个 AnsweredBy 参数,该参数将指示诸如 machine_startmachine_end_beep 之类的事件.

With AMD enabled on your call, Twilio will post the result of the call to the webhook you specify. That webhook will receive an AnsweredBy parameter that will indicate events like machine_start or machine_end_beep.

接收 webhook 的控制器应该使用 TwiML 动词按下"正确的按钮来响应.这是一个代码示例,它可能看起来像(此代码未经测试):

The controller that receives the webhook should respond by using the <Play> TwiML verb to "press" the correct button. Here is a code sample of what that might look like (this code is untested):

const VoiceResponse = require('twilio').twiml.VoiceResponse;

app.post('/answering-machine-handler', function (req, res) {
  const response = new VoiceResponse();

  if (req.params.AnsweredBy === 'machine_start') {
    response.play({
        digits: 'wwww3'
    });
  } else {
    // Handle other cases here.
  }

  res.send(response);
})

console.log(response.toString());

这篇关于如果用户没有接听,Twilio 在出站呼叫中发送语音消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆