Dialogflow的v2
API使用gRPC并具有一些怪癖,您已经遇到其中之一。如果查看Node.js库的示例,则可以看到解决方法。您需要隐含一种
jsonToStructProto将Javascript对象转换为原型结构的方法,或者仅在此要点中将
structjson.js文件
~~~~复制
中。以下是使用该
structjson.js文件的完整示例:
// imports the Dialogflow libraryconst dialogflow = require('dialogflow');// import the JSON to gRPC struct converterconst structjson = require('./structjson.js');// Instantiates a sessison clientconst sessionClient = new dialogflow.SessionsClient();// The path to identify the agent that owns the created intent.const sessionPath = sessionClient.sessionPath(projectId, sessionId);// The text query request.const request = { session: sessionPath, queryInput: { event: { name: eventName, parameters: structjson.jsonToStructProto({foo: 'bar'}), languageCode: languageCode, }, },};sessionClient .detectIntent(request) .then(responses => { console.log('Detected intent'); logQueryResult(sessionClient, responses[0].queryResult); }) .catch(err => { console.error('ERROR:', err); });


