本文介绍了将参数发送到dialogflow sdk v2上的webhook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向dialogflow(api.ai)发送一些参数,例如用户名,电子邮件等,但我无法弄清楚.问题是我无法使用Dialogflow v2 Nodejs SDK获取/设置任何特定的数据(例如用户名,电子邮件等).我尝试使用在此要点中.以下是使用structjson.js文件的完整示例:

Dialogflow's v2 API uses gRPC and has a few quirks, one of which you've run into. If you look at the samples for the Node.js library you can see how to workaround this. You'll need to impliment a jsonToStructProto method to convert your JavaScript object to a proto struct or just copy the structjson.js file in this gist. Below is a fully working example using the structjson.js file:

// Imports the Dialogflow library
const dialogflow = require('dialogflow');

// Import the JSON to gRPC struct converter
const structjson = require('./structjson.js');

// Instantiates a sessison client
const 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);
  });

这篇关于将参数发送到dialogflow sdk v2上的webhook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 01:59