-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestDialog.js
41 lines (37 loc) · 1.11 KB
/
testDialog.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// You can find your project ID in your Dialogflow agent settings
const projectId = "react-chatbot-6d094"; //https://dialogflow.com/docs/agents#settings
const sessionId = "quickstart-session-id";
const query = "hello";
const languageCode = "en-US";
// Instantiate a DialogFlow client.
const dialogflow = require("dialogflow");
const sessionClient = new dialogflow.SessionsClient();
// Define session path
const sessionPath = sessionClient.sessionPath(projectId, sessionId);
// The text query request.
const request = {
session: sessionPath,
queryInput: {
text: {
text: query,
languageCode: languageCode
}
}
};
// Send request and log result
sessionClient
.detectIntent(request)
.then(responses => {
console.log("Detected intent");
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.`);
}
})
.catch(err => {
console.error("ERROR:", err);
});