How to save data between conversation in Dialogflow?

前端 未结 2 1957
[愿得一人]
[愿得一人] 2020-11-27 23:55

I don\'t understand how you\'re supposed to save data. I tried using

let conv = agent.conv()
conv.data.data1=mydata //to save
mydata = conv.data.data1 //to          


        
相关标签:
2条回答
  • 2020-11-28 00:22

    Also if you want to mark those parameters as required and use slot filling, that will automatically generate your output contexts during fulfillment. You can see this through a basic sample here: https://github.com/dialogflow/fulfillment-slot-filling-nodejs

    0 讨论(0)
  • 2020-11-28 00:42

    Use the output context to save parameters

    {  
      "fulfillmentText":"This is a text response",
      "fulfillmentMessages":[  ],
      "source":"example.com",
      "payload":{  
        "google":{  },
        "facebook":{  },
        "slack":{  }
      },
      "outputContexts":[  
        {  
          "name":"<Context Name>",
          "lifespanCount":5,
          "parameters":{  
            "<param name>":"<param value>"
          }
        }
      ],
      "followupEventInput":{  }
    }
    

    If you are using NodeJS client

    You can save context with parameters like

    let param1 = [];
    let param2 = {};
    let ctx = {'name': '<context name>', 'lifespan': 5, 'parameters': {'param1':param1, 'param2': param2}};
    agent.setContext(ctx);
    

    and get it like

    let params = agent.getContext("<context name>").parameters;
    let param1 = params.param1;
    let param2 = params.param2; 
    

    You can store arrays, JSON obj but there is a limit to the total payload the response can save. check for more details here. For large data, use DB.

    Also, if you are using standalone actions-on-google, then you can simply add key-value pair to the data object. See the link where they are storing a count

    0 讨论(0)
提交回复
热议问题