@@ -20,7 +20,7 @@ const util = require('util');
2020async function createKnowledgeBase ( projectId , displayName ) {
2121 // [START dialogflow_create_knowledge_base]
2222 // Imports the Dialogflow client library
23- const dialogflow = require ( 'dialogflow' ) . v2beta1 ;
23+ const dialogflow = require ( '@google-cloud/ dialogflow' ) . v2beta1 ;
2424
2525 // Instantiate a DialogFlow client.
2626 const client = new dialogflow . KnowledgeBasesClient ( ) ;
@@ -31,7 +31,7 @@ async function createKnowledgeBase(projectId, displayName) {
3131 // const projectId = 'ID of GCP project associated with your Dialogflow agent';
3232 // const displayName = `your knowledge base display name, e.g. myKnowledgeBase`;
3333
34- const formattedParent = client . projectPath ( projectId ) ;
34+ const formattedParent = 'projects/' + projectId ;
3535 const knowledgeBase = {
3636 displayName : displayName ,
3737 } ;
@@ -47,55 +47,59 @@ async function createKnowledgeBase(projectId, displayName) {
4747 // [END dialogflow_create_knowledge_base]
4848}
4949
50- async function createDocument (
51- projectId ,
52- knowledgeBaseFullName ,
53- documentPath ,
54- documentName ,
55- knowledgeTypes ,
56- mimeType
57- ) {
58- // [START dialogflow_create_document]
59- // Imports the Dialogflow client library
60- const dialogflow = require ( 'dialogflow' ) . v2beta1 ;
61-
62- // Instantiate a DialogFlow Documents client.
63- const client = new dialogflow . DocumentsClient ( {
64- projectId : projectId ,
65- } ) ;
66-
67- /**
68- * TODO(developer): Uncomment the following lines before running the sample.
69- */
70- // const projectId = 'ID of GCP project associated with your Dialogflow agent';
71- // const knowledgeBaseFullName = `the full path of your knowledge base, e.g my-Gcloud-project/myKnowledgeBase`;
72- // const documentPath = `path of the document you'd like to add, e.g. https://dialogflow.com/docs/knowledge-connectors`;
73- // const documentName = `displayed name of your document in knowledge base, e.g. myDoc`;
74- // const knowledgeTypes = `The Knowledge type of the Document. e.g. FAQ`;
75- // const mimeType = `The mime_type of the Document. e.g. text/csv, text/html,text/plain, text/pdf etc.`;
76-
77- const request = {
78- parent : knowledgeBaseFullName ,
79- document : {
80- knowledgeTypes : [ knowledgeTypes ] ,
81- displayName : documentName ,
82- contentUri : documentPath ,
83- source : 'contentUri' ,
84- mimeType : mimeType ,
85- } ,
86- } ;
87-
88- const [ operation ] = await client . createDocument ( request ) ;
89- const [ response ] = await operation . promise ( ) ;
90- console . log ( 'Document created' ) ;
91- console . log ( `Content URI...${ response . contentUri } ` ) ;
92- console . log ( `displayName...${ response . displayName } ` ) ;
93- console . log ( `mimeType...${ response . mimeType } ` ) ;
94- console . log ( `name...${ response . name } ` ) ;
95- console . log ( `source...${ response . source } ` ) ;
96-
97- // [END dialogflow_create_document]
98- }
50+ /*
51+ *This test is commented until the proto change for dialogflow/v2beta1 is finished.
52+ */
53+ // async function createDocument(
54+ // projectId,
55+ // knowledgeBaseFullName,
56+ // documentPath,
57+ // documentName,
58+ // knowledgeTypes,
59+ // mimeType
60+ // ) {
61+ // // [START dialogflow_create_document]
62+ // // Imports the Dialogflow client library
63+ // const dialogflow = require('@google-cloud/dialogflow').v2beta1;
64+
65+ // // Instantiate a DialogFlow Documents client.
66+ // const client = new dialogflow.DocumentsClient({
67+ // projectId: projectId,
68+ // });
69+
70+ // /**
71+ // * TODO(developer): Uncomment the following lines before running the sample.
72+ // */
73+ // // const projectId = 'ID of GCP project associated with your Dialogflow agent';
74+ // // const knowledgeBaseFullName = `the full path of your knowledge base, e.g my-Gcloud-project/myKnowledgeBase`;
75+ // // const documentPath = `path of the document you'd like to add, e.g. https://dialogflow.com/docs/knowledge-connectors`;
76+ // // const documentName = `displayed name of your document in knowledge base, e.g. myDoc`;
77+ // // const knowledgeTypes = `The Knowledge type of the Document. e.g. FAQ`;
78+ // // const mimeType = `The mime_type of the Document. e.g. text/csv, text/html,text/plain, text/pdf etc.`;
79+
80+ // const request = {
81+ // parent: knowledgeBaseFullName,
82+ // document: {
83+ // knowledgeTypes: [knowledgeTypes],
84+ // displayName: documentName,
85+ // contentUri: documentPath,
86+ // source: 'contentUri',
87+ // mimeType: mimeType,
88+ // },
89+ // };
90+
91+ // const [operation] = await client.createDocument(request);
92+ // const [response] = await operation.promise();
93+
94+ // console.log('Document created');
95+ // console.log(`Content URI...${response.contentUri}`);
96+ // console.log(`displayName...${response.displayName}`);
97+ // console.log(`mimeType...${response.mimeType}`);
98+ // console.log(`name...${response.name}`);
99+ // console.log(`source...${response.source}`);
100+
101+ // // [END dialogflow_create_document]
102+ // }
99103
100104async function detectIntentandSentiment (
101105 projectId ,
@@ -105,8 +109,7 @@ async function detectIntentandSentiment(
105109) {
106110 // [START dialogflow_detect_intent_with_sentiment_analysis]
107111 // Imports the Dialogflow client library
108- const dialogflow = require ( 'dialogflow' ) . v2beta1 ;
109-
112+ const dialogflow = require ( '@google-cloud/dialogflow' ) . v2beta1 ;
110113 // Instantiate a DialogFlow client.
111114 const sessionClient = new dialogflow . SessionsClient ( ) ;
112115
@@ -119,7 +122,10 @@ async function detectIntentandSentiment(
119122 // const languageCode = 'BCP-47 language code, e.g. en-US';
120123
121124 // Define session path
122- const sessionPath = sessionClient . sessionPath ( projectId , sessionId ) ;
125+ const sessionPath = sessionClient . projectAgentSessionPath (
126+ projectId ,
127+ sessionId
128+ ) ;
123129
124130 // The text query request.
125131 const request = {
@@ -171,8 +177,7 @@ async function detectIntentwithTexttoSpeechResponse(
171177) {
172178 // [START dialogflow_detect_intent_with_texttospeech_response]
173179 // Imports the Dialogflow client library
174- const dialogflow = require ( 'dialogflow' ) . v2beta1 ;
175-
180+ const dialogflow = require ( '@google-cloud/dialogflow' ) . v2beta1 ;
176181 // Instantiate a DialogFlow client.
177182 const sessionClient = new dialogflow . SessionsClient ( ) ;
178183
@@ -186,7 +191,10 @@ async function detectIntentwithTexttoSpeechResponse(
186191 // const outputFile = `path for audio output file, e.g. ./resources/myOutput.wav`;
187192
188193 // Define session path
189- const sessionPath = sessionClient . sessionPath ( projectId , sessionId ) ;
194+ const sessionPath = sessionClient . projectAgentSessionPath (
195+ projectId ,
196+ sessionId
197+ ) ;
190198 const fs = require ( 'fs' ) ;
191199
192200 // The audio query request
@@ -220,8 +228,7 @@ async function detectIntentKnowledge(
220228) {
221229 // [START dialogflow_detect_intent_knowledge]
222230 // Imports the Dialogflow client library
223- const dialogflow = require ( 'dialogflow' ) . v2beta1 ;
224-
231+ const dialogflow = require ( '@google-cloud/dialogflow' ) . v2beta1 ;
225232 // Instantiate a DialogFlow client.
226233 const sessionClient = new dialogflow . SessionsClient ( ) ;
227234
@@ -235,12 +242,12 @@ async function detectIntentKnowledge(
235242 // const query = `phrase(s) to pass to detect, e.g. I'd like to reserve a room for six people`;
236243
237244 // Define session path
238- const sessionPath = sessionClient . sessionPath ( projectId , sessionId ) ;
239- const knowbase = new dialogflow . KnowledgeBasesClient ( ) ;
240- const knowledgeBasePath = knowbase . knowledgeBasePath (
245+ const sessionPath = sessionClient . projectAgentSessionPath (
241246 projectId ,
242- knowledgeBaseId
247+ sessionId
243248 ) ;
249+ const knowledgeBasePath =
250+ 'projects/' + projectId + '/knowledgeBases/' + knowledgeBaseId + '' ;
244251
245252 // The audio query request
246253 const request = {
@@ -367,20 +374,25 @@ const cli = require('yargs')
367374 . command ( 'createKnowledgeBase' , 'Creates a new knowledge base' , { } , opts =>
368375 createKnowledgeBase ( opts . projectId , opts . knowledgeBaseName )
369376 )
370- . command (
371- 'createDocument' ,
372- 'Creates a new document for this knowledge base' ,
373- { } ,
374- opts =>
375- createDocument (
376- opts . projectId ,
377- opts . knowledgeBaseFullName ,
378- opts . documentPath ,
379- opts . documentName ,
380- opts . knowledgeTypes ,
381- opts . mimeType
382- )
383- )
377+ /**
378+ * TODO(developer): Uncomment the following lines until proto updates for dialogflow/v2beta1 is complete.
379+ * This method should be annotated with (google.longrunning.operationInfo) to generate LRO methods.
380+ * Now it's a simple method, without proper LRO response, so it fails because `promise() is not a function`.
381+ */
382+ // .command(
383+ // 'createDocument',
384+ // 'Creates a new document for this knowledge base',
385+ // {},
386+ // opts =>
387+ // createDocument(
388+ // opts.projectId,
389+ // opts.knowledgeBaseFullName,
390+ // opts.documentPath,
391+ // opts.documentName,
392+ // opts.knowledgeTypes,
393+ // opts.mimeType
394+ // )
395+ // )
384396 . command (
385397 'detectIntentwithTexttoSpeechResponse' ,
386398 'Detects the intent of text input, outputs .wav file to target location' ,
0 commit comments