如果用户没有接听,Twilio 在出站呼叫中发送语音消息

编程入门 行业动态 更新时间:2024-10-27 03:36:49
本文介绍了如果用户没有接听,Twilio 在出站呼叫中发送语音消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我是使用 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/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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-29 16:37:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1192059.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语音   消息   用户   Twilio

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!