Twilio Studio-使用Liquid选择并解析JSON

Twilio Studio-使用Liquid选择并解析JSON,twilio,liquid,Twilio,Liquid,在Twilio Studio中,我发出一个GET请求,并尝试解析JSON,然后根据解析的JSON分配变量。我在处理返回的JSON时遇到了困难 本质上,我试图从与返回的JSON匹配的“行”中设置变量(用户拨入,输入他们的PIN{{widgets.PIN_Entry.Digits}),PIN将与GET请求返回的JSON中的“行”匹配,我们为匹配行的userID、userEmail、userName、userPin设置变量) 我可以使用JSON Path(Twilio studio不支持)轻松地选择要

在Twilio Studio中,我发出一个GET请求,并尝试解析JSON,然后根据解析的JSON分配变量。我在处理返回的JSON时遇到了困难

本质上,我试图从与返回的JSON匹配的“行”中设置变量(用户拨入,输入他们的PIN{{widgets.PIN_Entry.Digits}),PIN将与GET请求返回的JSON中的“行”匹配,我们为匹配行的userID、userEmail、userName、userPin设置变量)

我可以使用JSON Path(Twilio studio不支持)轻松地选择要设置为变量的值,但我不知道如何使用Liquid来实现这一点

userID=$.DataSource.Rows[?(@.includes('00012345'))]。[0]

(将返回“EMP-0267”)

userEmail==$.DataSource.Rows[?(@.includes('00012345'))]。[1]

(将返回)leslie@pawneeil.com))

用户名==$.DataSource.Rows[?(@.includes('00012345'))]。[2]

(将返回“莱斯利·诺普”)

userPin==$.DataSource.Rows[?(@.includes('00012345'))]。[3]

(将返回“00012345”)

任何人都可以分享一些关于如何使用Liquid解析JSON和设置变量的想法吗?以下是我如何完成这一任务的想法:

  • 将变量{widgets.PIN_Entry.Digits}与返回的JSON中的一行匹配
  • 解析所选行并为userID、userEmail、userName和userPin设置变量
  • 在这些情况下,我发现处理流畅语法的细微差别要容易得多

    // Description
    // Make a read request to an external API
    
    // Add axios 0.20.0 as a dependency under Functions Settings, Dependencies
    const axios = require('axios');
    
    exports.handler = function (context, event, callback) {
      
      let twiml = new Twilio.twiml.VoiceResponse();
      
      // Arrays start at 0
      let selectedDigit = 0;
    
      axios
        .get(`https://x.x.x.x/myAPI`)
        .then((response) => {
          
          let { Rows } = response.data.DataSource;
    
          let result = Rows.filter((record, index) => index === selectedDigit);
          
          twiml.say(`The result is ${result}`);
          
          return callback(null, twiml);
        })
        .catch((error) => {
          console.log(error);
          return callback(error);
        });
    };
    
    在这些情况下,我发现处理流畅语法的细微差别要容易得多

    // Description
    // Make a read request to an external API
    
    // Add axios 0.20.0 as a dependency under Functions Settings, Dependencies
    const axios = require('axios');
    
    exports.handler = function (context, event, callback) {
      
      let twiml = new Twilio.twiml.VoiceResponse();
      
      // Arrays start at 0
      let selectedDigit = 0;
    
      axios
        .get(`https://x.x.x.x/myAPI`)
        .then((response) => {
          
          let { Rows } = response.data.DataSource;
    
          let result = Rows.filter((record, index) => index === selectedDigit);
          
          twiml.say(`The result is ${result}`);
          
          return callback(null, twiml);
        })
        .catch((error) => {
          console.log(error);
          return callback(error);
        });
    };