无法处理多个履行回应 [英] Unable to handle multiple fulfillment responses

查看:100
本文介绍了无法处理多个履行回应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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

https://www.npmjs.com/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

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

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

https://i.stack.imgur.com/aRAr6.png ,
 https://i.stack.imgur.com/oMp0d.png
 https://i.stack.imgur.com/T7Jo7.png
 https://i.stack.imgur.com/7U3Rb.png
 https://i.stack.imgur.com/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).  

https://i.stack.imgur.com/rLI2I.png
https://i.stack.imgur.com/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.

这篇关于无法处理多个履行回应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆