Search code examples
firebasegoogle-apps-scriptgoogle-sheetsdialogflow-es-fulfillment

Output @sys.date_time value to the Sheet


First of all, when I input "Tomorrow noon", the system output "2019-09-21T12:00:00+08:00"(parameter: whattime). When I inputted the word – "Tomorrow noon", the system would convert it into whatime: {"date_time": ""2019-09-21T12:00:00+08:00"}.

Second, there's only time to show it up after inputting a period of data. (you can check this picture I posted). How do I fix my codes?

function saveDataHandler(agent){
    const{
      namelist, howmanypeople, whattime, forhere
    } = agent.parameters;
    const data = [{
      Name:namelist,
      Number:howmanypeople,
      Time:whattime[1],
      Forhere:forhere
    }];
    axios.post('.....it's about API', data);
  }

enter image description here


Solution

  • If whattime value is whatime: {"date_time": "2019-09-21T12:00:00+08:00"}, you should access date_time in whatime before sending it.

    const{
          namelist, howmanypeople, whattime:{"date_time":dt}, forhere
        } = agent.parameters;//modified 
    const data = [{
          Name:namelist,
          Number:howmanypeople,
          Time:dt.toString(),//modified
          Forhere:forhere
        }];
    

    OR

    const{
          namelist, howmanypeople, whattime, forhere
        } = agent.parameters;
    const data = [{
          Name:namelist,
          Number:howmanypeople,
          Time:whattime["date_time"].toString(),//modified
          Forhere:forhere
        }];
    

    To read: