Возникли проблемы с документацией 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_Assogflow_V2_SessionsClient_Create_Google_Account_Gax_Create_Google_Account_Gaxflow_Create_Google_Account_Gax_Create_Google_Account_Gaxflow_Google_Account_Gax_Create_Google_Acpi_Gax_Gax
Нет ссылки на метод ToChannelCredentials (). Мы не можем подключить SDK к диалогу, даже с пустым проектом. Этот метод все еще существует или устарел?
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();





Вы пробовали подключиться с помощью закрытого ключа учетной записи службы? (Json файл)
Выполните следующие действия (рабочий пример на C#)
Создайте, например, класс диспетчера 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;
}
}
И тогда это можно назвать так, например, чтобы обнаружить намерения
DialogflowManager dialogflow = new DialogflowManager("{INSERT_USER_ID}",
_hostingEnvironment.WebRootPath,
_hostingEnvironment.ContentRootPath,
"{INSERT_AGENT_ID");
var dialogflowQueryResult = await dialogflow.CheckIntent("{INSERT_USER_INPUT}");
@ Shiasu-sama Он вводится в конструктор (DI), где я вызываю DialogflowManager
На что следует установить _contentRootPath?
Они используются для получения фактического местоположения файла ключа json, я только что заметил, что webRoothPath не используется в диспетчере, поэтому вы можете игнорировать его, но _contentRootPath возвращает абсолютный путь к каталогу, содержащему файлы содержимого приложения.
В вашем примере под №7: Как / где мне создать экземпляр
_hostingEnvironment?