我正在使用dialogflow企业版bot,问题在于如何从rest api(node.js sdk)接收响应。最近我们已从dialogflow标准版转到Enterprise版。我们在此链接中引用并使用了以下代码
https://www.npmjs.com/package/dialogflow
我们使用rest Api创建了自己的云功能,该功能将用户答案作为请求并向用户发送实现文本(特定意图中的问题)作为对用户的响应。当发生多个请求调用时,云功能为没有显示适当的响应,这意味着
当用户(Android / IOS)“ A”开始回答机器人时,云功能触发就开始了,并且它向用户发送了问题作为响应,但是当多个用户开始回答机器人时,由于多次调用在云功能中,显示给一个用户的问题不会显示给另一用户说“ B”。请帮助我们处理对node.js sdk的多次调用
https://i.stack.imgur.com/BVAci.png 这是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");
}
}
});
答案 0 :(得分:0)
您似乎对所有客户都使用相同的会话ID。我不确定,但我可以肯定地理解,如果Dialogflow同时收到同一会话的两个请求,那么它会混淆答复。
您应该为每个客户端生成一个新会话-可能是在客户端首次连接时将其放入HTTP会话(aha!)cookie中,并在会话期间继续使用它。