如何在Studio中将信息发送到TWiml重定向小部件中以及如何使用液体变量输入法?

时间:2019-09-25 15:24:46

标签: twilio-studio

我有要发送到 TwiML重定向小部件中的Json值。 Json来自HTTP请求。 我看到,除了方法获取和发布之外,还有用于液体变量输入的其他方法,这可以作为我的解决方案吗? 如果是,它将如何工作?我没有运气设置此选项。

来自(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 上,并且永远不会重新进入流。

0 个答案:

没有答案