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

Function main

dialogflow-cx/detect-intent-event.js:24–96  ·  view source on GitHub ↗
(projectId, location, agentId, event, languageCode)

Source from the content-addressed store, hash-verified

22'use strict';
23
24function main(projectId, location, agentId, event, languageCode) {
25 // [START dialogflow_cx_v3_detect_intent_event_input_async]
26 /**
27 * TODO(developer): Uncomment these variables before running the sample.
28 */
29 /**
30 * Required. The name of the session this query is sent to.
31 * Format: `projects/<Project ID>/locations/<Location ID>/agents/<Agent
32 * ID>/sessions/<Session ID>` or `projects/<Project ID>/locations/<Location
33 * ID>/agents/<Agent ID>/environments/<Environment ID>/sessions/<Session ID>`.
34 * If `Environment ID` is not specified, we assume default 'draft'
35 * environment.
36 * It's up to the API caller to choose an appropriate `Session ID`. It can be
37 * a random number or some type of session identifiers (preferably hashed).
38 * The length of the `Session ID` must not exceed 36 characters.
39 * For more information, see the sessions
40 * guide (https://cloud.google.com/dialogflow/cx/docs/concept/session).
41 * Note: Always use agent versions for production traffic.
42 * See Versions and
43 * environments (https://cloud.google.com/dialogflow/cx/docs/concept/version).
44 */
45
46 /**
47 * Optional. The parameters of this query.
48 */
49 // const queryParams = {}
50 /**
51 * Required. The input specification. See https://cloud.google.com/dialogflow/cx/docs/reference/rest/v3beta1/ConversationTurn#QueryInput for information about query inputs.
52 */
53 // const event = 'name-of-event-to-trigger';
54
55 // Imports the Cx library
56 const {SessionsClient} = require('@google-cloud/dialogflow-cx');
57 /**
58 * Example for regional endpoint:
59 * const location = 'us-central1'
60 * const client = new SessionsClient({apiEndpoint: 'us-central1-dialogflow.googleapis.com'})
61 */
62 // Instantiates a client
63 const cxClient = new SessionsClient();
64
65 async function detectIntentWithEventInput() {
66 const sessionId = Math.random().toString(36).substring(7);
67 const sessionPath = cxClient.projectLocationAgentSessionPath(
68 projectId,
69 location,
70 agentId,
71 sessionId
72 );
73
74 // Construct detect intent request
75 const request = {
76 session: sessionPath,
77 queryInput: {
78 event: {
79 event: event,
80 },
81 languageCode,

Callers 1

Calls 1

Tested by

no test coverage detected