MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / main

Function main

dialogflow-cx/detect-intent-text.js:17–72  ·  view source on GitHub ↗
(projectId, location, agentId, query, languageCode)

Source from the content-addressed store, hash-verified

15'use strict';
16
17async function main(projectId, location, agentId, query, languageCode) {
18 // [START dialogflow_cx_detect_intent_text]
19 /**
20 * TODO(developer): Uncomment these variables before running the sample.
21 */
22 // const projectId = 'my-project';
23 // const location = 'global';
24 // const agentId = 'my-agent';
25 // const query = 'Hello';
26 // const languageCode = 'en'
27
28 // Imports the Google Cloud Some API library
29 const {SessionsClient} = require('@google-cloud/dialogflow-cx');
30 /**
31 * Example for regional endpoint:
32 * const location = 'us-central1'
33 * const client = new SessionsClient({apiEndpoint: 'us-central1-dialogflow.googleapis.com'})
34 */
35 const client = new SessionsClient();
36
37 async function detectIntentText() {
38 const sessionId = Math.random().toString(36).substring(7);
39 const sessionPath = client.projectLocationAgentSessionPath(
40 projectId,
41 location,
42 agentId,
43 sessionId
44 );
45 const request = {
46 session: sessionPath,
47 queryInput: {
48 text: {
49 text: query,
50 },
51 languageCode,
52 },
53 };
54 const [response] = await client.detectIntent(request);
55 for (const message of response.queryResult.responseMessages) {
56 if (message.text) {
57 console.log(`Agent Response: ${message.text.text}`);
58 }
59 }
60 if (response.queryResult.match.intent) {
61 console.log(
62 `Matched Intent: ${response.queryResult.match.intent.displayName}`
63 );
64 }
65 console.log(
66 `Current Page: ${response.queryResult.currentPage.displayName}`
67 );
68 }
69
70 detectIntentText();
71 // [END dialogflow_cx_detect_intent_text]
72}
73
74main(...process.argv.slice(2));

Callers 1

Calls 1

detectIntentTextFunction · 0.70

Tested by

no test coverage detected