简体   繁体   English

Dialogflow V2 api 不起作用的示例

[英]Not working example for Dialogflow V2 api

Experienced problems with C# SDK documentation which can be found here: http://googleapis.github.io/google-cloud-dotnet/docs/Google.Cloud.Dialogflow.V2/api/Google.Cloud.Dialogflow.V2.SessionsClient.html#Google_Cloud_Dialogflow_V2_SessionsClient_Create_Google_Api_Gax_Grpc_ServiceEndpoint_Google_Cloud_Dialogflow_V2_SessionsSettings_可在此处找到 C# SDK 文档遇到的问题: http : //googleapis.github.io/google-cloud-dotnet/docs/Google.Cloud.Dialogflow.V2/api/Google.Cloud.Dialogflow.V2.SessionsClient。 html#Google_Cloud_Dialogflow_V2_SessionsClient_Create_Google_Api_Gax_Grpc_ServiceEndpoint_Google_Cloud_Dialogflow_V2_SessionsSettings_

No reference for method ToChannelCredentials(). ToChannelCredentials() 方法没有参考。 We cannot connect the SDK to dialogflow, even with blank project.我们无法将 SDK 连接到 dialogflow,即使是空白项目。 Is this method still existing or deprecated?此方法是否仍然存在或已弃用?

using Google.Cloud.Dialogflow.V2;
using Google.Apis.Auth.OAuth2;
using Grpc.Auth;
using Grpc.Core;
...
GoogleCredential cred = GoogleCredential.FromFile("/path/to/credentials.json");
Channel channel = new Channel(
    SessionsClient.DefaultEndpoint.Host, SessionsClient.DefaultEndpoint.Port, cred.ToChannelCredentials());
SessionsClient client = SessionsClient.Create(channel);
...
// Shutdown the channel when it is no longer required.
channel.ShutdownAsync().Wait();

Have you tried connecting using the service account private key ?您是否尝试过使用服务帐户私钥进行连接? ( Json file ) ( Json 文件)

Follow these steps (working example in C#)按照以下步骤操作(C# 中的工作示例)

  1. After you create a Dialogflow agent go to the agent's settings --> General --> click on the Service Account link创建 Dialogflow 代理后,转到代理的设置 --> 常规 --> 单击服务帐户链接
  2. You will be sent to to google cloud platform where you can create a service account您将被发送到谷歌云平台,您可以在其中创建一个服务帐户
  3. After you create a service account, there will be an option to create a KEY , create it and download the (JSON) format of it创建服务帐户后,将有一个选项来创建KEY ,创建它并下载它的(JSON)格式
  4. This key will be used to connect from your C# project to the Dialogflow agent此密钥将用于从您的 C# 项目连接到 Dialogflow 代理
  5. Install Google.Cloud.Dialogflow.V2 package in your project在您的项目中安装Google.Cloud.Dialogflow.V2
  6. Create for example a Dialogflow manager class (check below for an example)例如创建一个 Dialogflow 管理器类(查看下面的示例)

     public class DialogflowManager { private string _userID; private string _webRootPath; private string _contentRootPath; private string _projectId; private SessionsClient _sessionsClient; private SessionName _sessionName; public DialogflowManager(string userID, string webRootPath, string contentRootPath, string projectId) { _userID = userID; _webRootPath = webRootPath; _contentRootPath = contentRootPath; _projectId = projectId; SetEnvironmentVariable(); } private void SetEnvironmentVariable() { try { Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", _contentRootPath + "\\\\Keys\\\\{THE_DOWNLOADED_JSON_FILE_HERE}.json"); } catch (ArgumentNullException) { throw; } catch (ArgumentException) { throw; } catch (SecurityException) { throw; } } private async Task CreateSession() { // Create client _sessionsClient = await SessionsClient.CreateAsync(); // Initialize request argument(s) _sessionName = new SessionName(_projectId, _userID); } public async Task < QueryResult > CheckIntent(string userInput, string LanguageCode = "en") { await CreateSession(); QueryInput queryInput = new QueryInput(); var queryText = new TextInput(); queryText.Text = userInput; queryText.LanguageCode = LanguageCode; queryInput.Text = queryText; // Make the request DetectIntentResponse response = await _sessionsClient.DetectIntentAsync(_sessionName, queryInput); return response.QueryResult; } }
  7. And then this can be called like this for example to get detect Intents然后可以像这样调用它,例如获取检测意图

     DialogflowManager dialogflow = new DialogflowManager("{INSERT_USER_ID}", _hostingEnvironment.WebRootPath, _hostingEnvironment.ContentRootPath, "{INSERT_AGENT_ID"); var dialogflowQueryResult = await dialogflow.CheckIntent("{INSERT_USER_INPUT}");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用C#在Dialogflow API V2中进行身份验证 - Authentication in Dialogflow API V2 using C# Google Dialogflow V2 webhook 不起作用 - InvalidType 和 Null 异常 - Google Dialogflow V2 webhook not working - InvalidType and Null Exception 无法对 dialogflow v2 和 v2beta1 上的 REST API 请求进行身份验证 - Unable to authenticate REST API request on dialogflow v2 and v2beta1 v2中的Woocommerce REST API POST无法正常工作 - Woocommerce REST API POST in v2 not working Quickbooks API-.NET-QBD-V2-有人在C#中有有效的示例,说明如何删除或还原错误的对象吗? - Quickbooks API - .NET - QBD - V2 - Does anyone have working example in C# of how to delete or revert errored objects? 使用C#的Google Dialogflow v2 - Google Dialogflow v2 using c# 适用于Google Dialogflow V2的C#库 - C# library for Google Dialogflow V2 尝试使用Dialogflow V2 API中的自定义事件更新intent参数,并且不传递给intent - Trying to update intent parameter using custom events in Dialogflow V2 API and its not passing through to the intent ApplySnapshot示例Hyper-V V2 - ApplySnapshot Example Hyper-V V2 LinkedIn V2 API权限似乎不起作用 - LinkedIn V2 API permission's don't seem to be working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM