Javascript 如果用户没有';在出站呼叫中,我没有应答
我不熟悉使用twilio。我正在使用twilio从浏览器打电话到手机。在浏览器端,我使用twiml设备连接到呼叫Javascript 如果用户没有';在出站呼叫中,我没有应答,javascript,node.js,twilio,twilio-twiml,Javascript,Node.js,Twilio,Twilio Twiml,我不熟悉使用twilio。我正在使用twilio从浏览器打电话到手机。在浏览器端,我使用twiml设备连接到呼叫 Twilio.Device.connect({ phoneNumber: phoneNumber, userId: id }); 在nodejs服务器端,我正在使用这段代码 import twilio from 'twilio'; const VoiceResponse = twilio.twiml.VoiceResponse; let phoneNumber = req.b
Twilio.Device.connect({ phoneNumber: phoneNumber, userId: id });
在nodejs服务器端,我正在使用这段代码
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());
如果另一端的用户没有接听电话,我需要通过按下按钮将录音作为语音邮件发送给该用户
<button>Send Voicemail</button>
发送语音邮件
如何实现这一点?这应该可以通过结合使用Twilio的应答机检测服务和TwiML动词来实现 使用应答机检测进行出站呼叫的方法
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\u start
或machine\u end\u beep
的事件
接收webhook的控制器应该通过使用TwiML动词“按下”正确的按钮来响应。这可能看起来像什么(此代码未经测试):
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());