我有一个应该与911调度员交谈的功能,但在“调度员”挂断之前没有说什么。如何在拨号后立即发生twiml.say?
exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.VoiceResponse();
// Wrap the phone number or client name in the appropriate TwiML verb
// if is a valid phone number
const attr = isAValidPhoneNumber(event.To) ? 'number' : 'client';
var got = require('got');
console.log('from', event.From.slice(7))
got('https://911callbot.com/api/get_incident?date_code_and_code='+event.From.slice(7), {'json': true})
.then(function(response) {
const dial = twiml.dial({
callerId: context.CALLER_ID,
record: 'record-from-ringing-dual'
});
console.log('RESPONSE', response.body)
console.log('test', response.body.code)
response_body = response.body
dial[attr]({}, event.To);
code = response_body[0] + ' ' + response_body[1] + ' ' + response_body[2] + ' ' + response_body[3]
msg = 'This is 911callbot.com again 911callbot.com the incident code is '+response_body['code']+' again the incident code is '+code+' the address is '+response_body['address']+' again the address is '+response_body['address']+' caller is reporting '+response_body['what_reporting'];
console.log(msg)
twiml.say(msg);
callback(null, twiml)
})
};
/**
* Checks if the given value is valid as phone number
* @param {Number|String} number
* @return {Boolean}
*/
function isAValidPhoneNumber(number) {
return /^[\d\+\-\(\) ]+$/.test(number);
}
答案 0 :(得分:0)
Twilio开发者传道者在这里。
要让Twilio立即开始阅读<Say>
,它必须是您添加到VoiceResponse
的第一件事。
这是你现在回调的核心:
const dial = twiml.dial({
callerId: context.CALLER_ID,
record: 'record-from-ringing-dual'
});
console.log('RESPONSE', response.body)
console.log('test', response.body.code)
response_body = response.body
dial[attr]({}, event.To);
code = response_body[0] + ' ' + response_body[1] + ' ' + response_body[2] + ' ' + response_body[3]
msg = 'This is 911callbot.com again 911callbot.com the incident code is '+response_body['code']+' again the incident code is '+code+' the address is '+response_body['address']+' again the address is '+response_body['address']+' caller is reporting '+response_body['what_reporting'];
console.log(msg)
twiml.say(msg);
callback(null, twiml)
您想要切换它,以便调用`twiml.say
code = response_body[0] + ' ' + response_body[1] + ' ' + response_body[2] + ' ' + response_body[3]
msg = 'This is 911callbot.com again 911callbot.com the incident code is '+response_body['code']+' again the incident code is '+code+' the address is '+response_body['address']+' again the address is '+response_body['address']+' caller is reporting '+response_body['what_reporting'];
console.log(msg)
twiml.say(msg);
const dial = twiml.dial({
callerId: context.CALLER_ID,
record: 'record-from-ringing-dual'
});
console.log('RESPONSE', response.body)
console.log('test', response.body.code)
response_body = response.body
dial[attr]({}, event.To);
callback(null, twiml);