Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dialogflow es agent.set.context()不起作用_Dialogflow Es_Dialogflow Es Fulfillment - Fatal编程技术网

Dialogflow es agent.set.context()不起作用

Dialogflow es agent.set.context()不起作用,dialogflow-es,dialogflow-es-fulfillment,Dialogflow Es,Dialogflow Es Fulfillment,我们在Dialogflow中同时管理多个用户交互时面临问题。 我们如何在使用自定义事件时管理用户唯一会话,自定义事件将处理我们的第三方API,然后向特定用户返回响应。 为了管理用户唯一会话,我们尝试Dailogflow Set/Get Context方法,从第一个意图设置具有唯一Id的上下文(使用此Id将存储对Redis服务器的API响应),当用户发出第一个请求时,将通过自定义事件遍历该唯一Id。 将从上下文中获取唯一Id,并从我们存储在first intent中的Redis服务器获取数据。 我

我们在Dialogflow中同时管理多个用户交互时面临问题。 我们如何在使用自定义事件时管理用户唯一会话,自定义事件将处理我们的第三方API,然后向特定用户返回响应。 为了管理用户唯一会话,我们尝试Dailogflow Set/Get Context方法,从第一个意图设置具有唯一Id的上下文(使用此Id将存储对Redis服务器的API响应),当用户发出第一个请求时,将通过自定义事件遍历该唯一Id。 将从上下文中获取唯一Id,并从我们存储在first intent中的Redis服务器获取数据。 我们使用agent.set.context()设置唯一id,但此方法不适用于版本为^0.5.0的“dialogflow fulfillment”,为了完成此工作,我们已将版本更新为“^0.6.1”。但这将提供其他错误,如“UnhandledPromisejectionWarning:error:No responses defined for platform:null”

所需输出:具有唯一id的上下文集,将得到正确的响应。 当前输出:未处理PromisejectionWarning:错误:未为平台定义响应:null

    async function searchFromAPI(agent){

        axios.post('https://testApi.com', searchString.data, {headers: headers})
        .then((resp) => {
                response.data = resp;
                redisClient.set(sessionId, JSON.stringify(response));
            }
        }).catch(error => {
            response.error = true;
            response.message = error.response.statusText;
            redisClient.set(sessionId, JSON.stringify(response));
        });
        await customsleep(2000);
        const sessionId = uuid.v4();
        const contextData = {'name':'userSession','lifespan': 5,'parameters':{'sessionId':sessionId}};
        agent.context.set(contextData);
        console.log(contextData);
        agent.add('We are processing your request, Could you please wait?');
        agent.add(new Suggestion("Yes"));   
        agent.add(new Suggestion("No"));    
    }

    // wait for 4.5sec and call custom event
    async function followOne(agent){    
        await customsleep(4500);
        agent.setFollowupEvent('followUpTwo');
    }
    // wait for 4.7sec then red API response from redis server and return 
    async function followUpTwo(agent){  
        await customsleep(4000);
        sess = session;
        //get context
        const response = agent.context.get('userSession');
        // get the sessionId, Get the data from redis server
        agent.add(response);

    }
    async function PleaseWait(agent){
        await customsleep(3500);
        agent.setFollowupEvent('followUpOne');
    }

查看此资源,了解如何设置新的Dialogflow传出上下文


我希望这对您有所帮助?

我找到了通过context.set(ctx)重新分配新上下文对象的唯一解决方法。然后它成功了

//update context to show full menu
  let context = agent.context.get('user_data');
  if (!context) throw "User_data context ius nod defined in PreferrenceAdd"

  let context2 = new Object();
  context2 = {'name': 'user_data', 'lifespan': 40, 
  'parameters': context.parameters}; 
  console.log("ctx: = " + JSON.stringify(context2));
  context2.parameters.new = false;
  context2.parameters.refresh = true;
  agent.context.set(context2);