如何在 dialogflow 中写入或设置参数值

how to write or set parameter value from fulfillment in dialogflow

基本上我需要能够将 fullfillment 的结果写入先前定义的 dialogflow 参数。

我可以收到从dialogflow到fullfillment的变量值,但是当我回信时,我没有得到预期的结果。该函数的示例如下:

function Validate(agent){
    let P1 = agent.parameters.rut1.Rut; //<<----received OK
    let P2 = agent.parameters.rut1.dv;  //<<----received OK
    let P3;

    P3 = some_function(P1,P2); //<<----------For example

    agent.parameters.next_state = P3; //<<---here the result is not written to the parameter.
}

enter image description here

履行响应 (V2) 的输出上下文中存在参数。 您需要在从网络钩子发回响应时在各自的输出上下文中指定要添加/更新的参数

                response.send(JSON.stringify({
                "fulfillmentText": "Hello, welcome to bot service. I need you to sign in first, your Userid?",
                "outputContexts": [
                    {
                        "name": request.body.session + "/contexts/usercontext",
                        "lifespanCount": 5,
                        "parameters": {
                            "token": result.access_token
                        }
                    }
                ]
            }));

您可以在随后的 5 个调用的意图中使用此参数值。