( projectId = 'YOUR_PROJECT_ID', sessionId = 'YOUR_SESSION_ID', query = 'YOUR_QUERY', languageCode = 'YOUR_LANGUAGE_CODE' )
| 14 | |
| 15 | 'use strict'; |
| 16 | async function main( |
| 17 | projectId = 'YOUR_PROJECT_ID', |
| 18 | sessionId = 'YOUR_SESSION_ID', |
| 19 | query = 'YOUR_QUERY', |
| 20 | languageCode = 'YOUR_LANGUAGE_CODE' |
| 21 | ) { |
| 22 | // [START dialogflow_detect_intent_with_sentiment_analysis] |
| 23 | // Imports the Dialogflow client library |
| 24 | const dialogflow = require('@google-cloud/dialogflow').v2; |
| 25 | |
| 26 | // Instantiate a DialogFlow client. |
| 27 | const sessionClient = new dialogflow.SessionsClient(); |
| 28 | |
| 29 | /** |
| 30 | * TODO(developer): Uncomment the following lines before running the sample. |
| 31 | */ |
| 32 | // const projectId = 'ID of GCP project associated with your Dialogflow agent'; |
| 33 | // const sessionId = `user specific ID of session, e.g. 12345`; |
| 34 | // const query = `phrase(s) to pass to detect, e.g. I'd like to reserve a room for six people`; |
| 35 | // const languageCode = 'BCP-47 language code, e.g. en-US'; |
| 36 | |
| 37 | // Define session path |
| 38 | const sessionPath = sessionClient.projectAgentSessionPath( |
| 39 | projectId, |
| 40 | sessionId |
| 41 | ); |
| 42 | |
| 43 | async function detectIntentandSentiment() { |
| 44 | // The text query request. |
| 45 | const request = { |
| 46 | session: sessionPath, |
| 47 | queryInput: { |
| 48 | text: { |
| 49 | text: query, |
| 50 | languageCode: languageCode, |
| 51 | }, |
| 52 | }, |
| 53 | queryParams: { |
| 54 | sentimentAnalysisRequestConfig: { |
| 55 | analyzeQueryTextSentiment: true, |
| 56 | }, |
| 57 | }, |
| 58 | }; |
| 59 | |
| 60 | // Send request and log result |
| 61 | const responses = await sessionClient.detectIntent(request); |
| 62 | console.log('Detected intent'); |
| 63 | const result = responses[0].queryResult; |
| 64 | console.log(` Query: ${result.queryText}`); |
| 65 | console.log(` Response: ${result.fulfillmentText}`); |
| 66 | if (result.intent) { |
| 67 | console.log(` Intent: ${result.intent.displayName}`); |
| 68 | } else { |
| 69 | console.log(' No intent matched.'); |
| 70 | } |
| 71 | if (result.sentimentAnalysisResult) { |
| 72 | console.log('Detected sentiment'); |
| 73 | console.log( |
no test coverage detected