将参数发送到dialogflow sdk v2上的webhook

将参数发送到dialogflow sdk v2上的webhook,第1张

将参数发送到dialogflow sdk v2上的webhook

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);  });


欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/zaji/5088046.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-16
下一篇2022-11-16

发表评论

登录后才能评论

评论列表(0条)

    保存