我有想要发送到TwiML 重定向小部件的 Json 值。Json 来自 HTTP 请求。我看到除了 Method Get 和 Post,还有一个 Method for Liquid Variable Input,这可以是我的解决方案吗?如果是,它是如何工作的?我没有运气设置这个选项。
我来自(GetAccountsByPhoneNumber)的 Json:
{"Accounts": [
{"AccountNumber": "9999999998", "HouseNumber": "3207", "StreetName": "Stokesberry ln"},
{"AccountNumber": "9999999997", "HouseNumber": "1204", "StreetName": "S Hardneir Rd"},
{"AccountNumber": "9999999996", "HouseNumber": "533", "StreetName": "Park Street"},
{"AccountNumber": "9999999995", "HouseNumber": "926", "StreetName": "S CO RD 67"}
]}
Twiml 函数提示选择他们调用的帐户。
exports.handler = function(context, event, callback) {
const twiml = new Twilio.twiml.VoiceResponse();
//This is Where I need to get Access to my JSON Object,
//it works with Function, but does not return to studio flow.
var responseMany = JSON.parse(event.IncomingJson);
var gather = twiml.gather({
input: 'dtmf speech',
timeout: 5,
hints: '1,2,3,4,5,9',
numDigits: 1
});
gather.say("If you are calling about ");
gather.say({voice: 'Polly.Joanna'}).ssmlSayAs({'interpret-as': 'address'}, responseMany.Accounts[0].HouseNumber + " " + responseMany.Accounts[0].StreetName);
gather.say("Press or say one.");
gather.say("If you are calling about ");
gather.say({voice: 'Polly.Joanna'}).ssmlSayAs({'interpret-as': 'address'}, responseMany.Accounts[1].HouseNumber + " " + responseMany.Accounts[1].StreetName);
gather.say("Press or say two.");
if(responseMany.Accounts.length >= 3){
gather.say("If you are calling about ");
gather.say({voice: 'Polly.Joanna'}).ssmlSayAs({'interpret-as': 'address'}, responseMany.Accounts[2].HouseNumber + " " + responseMany.Accounts[2].StreetName);
gather.say("Press or say three.");
}
if(responseMany.Accounts.length >= 4){
gather.say("If you are calling about ");
gather.say({voice: 'Polly.Joanna'}).ssmlSayAs({'interpret-as': 'address'}, responseMany.Accounts[3].HouseNumber + " " + responseMany.Accounts[3].StreetName);
gather.say("Press or say four.");
}
twiml.redirect("https://webhooks.twilio.com/v1/Accounts/.../Flows/...?FlowEvent=return")
callback(null, twiml);
};
作为一个函数,它在twiml.redirect上崩溃并且永远不会重新进入流程。