因此,我让Dialogflow Chatbot在前端使用意图和实体时都能正常工作。我可以在VS Code中使用node.js提出问题,并从漫游器获取响应,但是要提出另一个问题,我必须修改代码并再次运行应用程序。
如何允许用户在终端中输入?
我已经尝试过使用readline函数,但是在尝试从聊天机器人请求问题时似乎无法使它工作
这是我当前的不带readline的代码:
const dialogflow = require('dialogflow');
const uuid = require('uuid');
/**
* Send a query to the dialogflow agent, and return the query result.
* @param {string} projectId The project to be used
*/
async function runSample(projectId = 'gateway-bde11') {
const sessionId = '#firstattempt1';
// Create a new session
const sessionClient = new dialogflow.SessionsClient({
projectId,
keyFilename: 'C:/Users/adtell/Desktop/Rhajeem/node.js/gateway-bde11-f1310865c80b.json'
});
const sessionPath = sessionClient.sessionPath(projectId, sessionId);
// The text query request.
const request = {
session: sessionPath,
queryInput: {
text: {
// The query to send to the dialogflow agent
text: "Tell me about mortgage loans",
// The language used by the client (en-US)
languageCode: 'en-US',
},
},
};
// Send request and log result
const responses = await sessionClient.detectIntent(request);
console.log('Detected intent');
console.log("TRUE ALL: ");
console.log(JSON.stringify(responses));
const result = responses[0].queryResult;
console.log(` Query: ${result.queryText}`);
console.log(` Response: ${result.fulfillmentText}`);
if (result.intent) {
console.log(` Intent: ${result.intent.displayName}`);
} else {
console.log(` No intent matched.`);
}
let response;
response = {
"text": result.fulfillmentMessages[0].text.text[0],
}
console.log(response);
}
runSample('gateway-bde11');
这是终端的输出:
Query: Tell me about mortgage loans
Response: We do have mortgages! Is there anything you would like to know about them for example the requirements and interest rate?
Intent: MORTGAGES
{ question:
'We do have mortgages! Is there anything you would like to know about them for example the requirements and interest rate?' }
我有const请求的地方是用户通常会问的问题,问另一个问题时必须修改该问题。