(projectId, sessionId, queries, languageCode)
| 15 | 'use strict'; |
| 16 | |
| 17 | function detectTextIntent(projectId, sessionId, queries, languageCode) { |
| 18 | // [START dialogflow_detect_intent_text] |
| 19 | |
| 20 | /** |
| 21 | * TODO(developer): UPDATE these variables before running the sample. |
| 22 | */ |
| 23 | // projectId: ID of the GCP project where Dialogflow agent is deployed |
| 24 | // const projectId = 'PROJECT_ID'; |
| 25 | // sessionId: String representing a random number or hashed user identifier |
| 26 | // const sessionId = '123456'; |
| 27 | // queries: A set of sequential queries to be send to Dialogflow agent for Intent Detection |
| 28 | // const queries = [ |
| 29 | // 'Reserve a meeting room in Toronto office, there will be 5 of us', |
| 30 | // 'Next monday at 3pm for 1 hour, please', // Tell the bot when the meeting is taking place |
| 31 | // 'B' // Rooms are defined on the Dialogflow agent, default options are A, B, or C |
| 32 | // ] |
| 33 | // languageCode: Indicates the language Dialogflow agent should use to detect intents |
| 34 | // const languageCode = 'en'; |
| 35 | |
| 36 | // Imports the Dialogflow library |
| 37 | const dialogflow = require('@google-cloud/dialogflow'); |
| 38 | |
| 39 | // Instantiates a session client |
| 40 | const sessionClient = new dialogflow.SessionsClient(); |
| 41 | |
| 42 | async function detectIntent( |
| 43 | projectId, |
| 44 | sessionId, |
| 45 | query, |
| 46 | contexts, |
| 47 | languageCode |
| 48 | ) { |
| 49 | // The path to identify the agent that owns the created intent. |
| 50 | const sessionPath = sessionClient.projectAgentSessionPath( |
| 51 | projectId, |
| 52 | sessionId |
| 53 | ); |
| 54 | |
| 55 | // The text query request. |
| 56 | const request = { |
| 57 | session: sessionPath, |
| 58 | queryInput: { |
| 59 | text: { |
| 60 | text: query, |
| 61 | languageCode: languageCode, |
| 62 | }, |
| 63 | }, |
| 64 | }; |
| 65 | |
| 66 | if (contexts && contexts.length > 0) { |
| 67 | request.queryParams = { |
| 68 | contexts: contexts, |
| 69 | }; |
| 70 | } |
| 71 | |
| 72 | const responses = await sessionClient.detectIntent(request); |
| 73 | return responses[0]; |
| 74 | } |
no test coverage detected