无法处理多个履行回应

编程入门 行业动态 更新时间:2024-10-06 20:32:29
本文介绍了无法处理多个履行回应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用dialogflow企业版bot,问题是关于从rest api(node.js sdk)接收响应。最近我们已从dialogflow标准版转到Enterprise版。我们在此链接中引用并使用了以下代码

I am using the dialogflow enterprise edition bot,the issue is about receiving responses from rest api(node.js sdk).Recently we have shifted from dialogflow standard edition to Enterprise edition. We have referred and used the following code in this link

www.npmjs/package/dialogflow

我们使用rest Api创建了自己的云函数,该函数将用户答案作为请求并发送执行文本(特定意图中的问题)作为响应给用户。当发生多个请求调用时,云功能未显示正确的响应,这意味着

We have created our own cloud function using rest Api which takes the user answer as the request and send the fulfillment text(questions in that particular intent) as the response to the user.When multiple request calls happen the the cloud function is not showing proper response which means

当用户(Android / IOS) A开始回答机器人时,云功能触发就开始启动,并且它将问题作为响应发送给用户,但是当多个用户开始回答机器人时,由于多次调用机器人云功能,显示给一个用户的问题不会显示给另一用户说 B。请帮助我们处理对node.js sdk的多次调用

When user(Android/IOS) "A" started answering the bot then the cloud function triggering gets started and it send the questions as the response to the user but when the multiple users started answering the bot, due to multiple calls for the cloud function, the questions which are displayed to the one user are not going to be displayed to the other user say "B". Please help us in handling the multiple calls for node.js sdk

i.stack.imgur/BVAci.png 这是dialogflow中意图的视图。

i.stack.imgur/BVAci.png This is the view of an intent in dialogflow.

i.stack.imgur/aRAr6.png , i.stack.imgur/oMp0d.png i.stack.imgur/T7Jo7.png i.stack.imgur/7U3Rb.png i.stack.imgur/EwWSo.png Above five screenshots represent the first time when the user triggers the cloud function, and the 1st question is displayed. When we answer the first question and submit the answer, next question is not displayed.(I am getting the empty response).

i.stack.imgur/rLI2I.png , i.stack.imgur/T5wZL.png

这些屏幕截图表示

const functions = require('firebase-functions'); const dialogflow = require('dialogflow'); const Firestore = require('@google-cloud/firestore'); const firestore = new Firestore(); admin.initializeApp(); var db = admin.firestore(); const {WebhookClient} = require('dialogflow-fulfillment'); exports.fulfillmenttext = functions.https.onRequest((req,res) =>{ runSample(); async function runSample() { const projectId = 'bodha-192606'; const sessionId = uuid.v4(); const answer = req.body.Text; console.log("Text said by the user",answer); const languageCode = 'en-US'; const credentials = { client_email: 'xxxx ', Private_key:'xxxx ', }; // Instantiate a DialogFlow client. const dialogflow = require('dialogflow'); const sessionClient = new dialogflow.SessionsClient({ projectId, credentials, }); // Define session path const sessionPath = sessionClient.sessionPath(projectId, sessionId); // The text query request. const request = { session: sessionPath, queryInput: { text: { text: answer, languageCode, }, }, }; const responses = await sessionClient.detectIntent(request); console.log('Detected intent'); const result = responses[0].queryResult; let action = result.action; console.log("action is"+action); console.log(` Query: ${result.queryText}`); console.log(` Response: ${result.fulfillmentText}`); if (result.intent) { console.log(` Intent: ${result.intent.displayName}`); res.status(200).send({"question":result.fulfillmentText}); } else { console.log(` No intent matched.`); res.status(400).send("No Intent matched"); } } });

推荐答案

您似乎在使用相同的会话ID您所有的客户。我不确定,但我可以肯定地理解,如果Dialogflow同时收到同一会话的两个请求,那么它可能会混淆答复。

It looks like you are using the same session ID for all of your clients. I'm not certain, but I can certainly understand that if Dialogflow gets two requests for the same session at the same time, that it can mix up the replies.

您应该为您的每个客户端生成一个新会话-可能是在客户端首次连接时将其放入HTTP会话(aha!)cookie中,并在会话期间继续使用它。

You should be generating a new session for each of your clients - possibly by putting something into an HTTP session (aha!) cookie when they first connect and continuing to use that during the session.

更多推荐

无法处理多个履行回应

本文发布于:2023-11-28 03:12:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1640740.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!