I've set up a dialogflow agent and I'm trying to write C# code to integrate with it.
But my problem is; the code just freezes on this method: DetectIntent.
Here's the Google NuGet Packages I've installed on my project:
- Google.Api.CommonProtos (v1.7.0)
- Google.Api.Gax (v2.10.0)
- Google.Api.Gax.Grpc (v2.10.0)
- Google.Api.Gax.Rest (v2.10.0)
- Google.Apis (v1.43.0)
- Google.Apis.Auth (v1.43.0)
- Google.Apis.Core (v1.43.0)
- Google.Apis.Dialogflow.v2 (v1.40.2.1612)
- Google.Apis.Storage.v1 (v1.43.0.1791)
- Google.Cloud.Dialogflow.V2 (v1.2.0)
- Google.Cloud.Language.V1 (v1.4.0)
- Google.Cloud.Storage.V1 (v2.5.0)
- Google.LongRunning (v1.1.0)
- Google.Protobuf (v3.11.2)
- Grpc.Auth (v1.22.1)
- Grpc.Core (v1.22.1)
- Grpc.Core.Api (v2.26.0)
Then I followed this link for authentication: https://cloud.google.com/docs/authentication/production
So I've made this method:
public static Grpc.Core.Channel AuthExplicitForChannel(string theProjectID, string theServiceAccountJSONFilePath)
{
GoogleCredential googleCredential = GoogleCredential.FromFile(theServiceAccountJSONFilePath).CreateScoped(LanguageServiceClient.DefaultScopes);
Grpc.Core.Channel mainChannel = new Grpc.Core.Channel(LanguageServiceClient.DefaultEndpoint.ToString(), googleCredential.ToChannelCredentials());
return mainChannel;
}
With these usings:
using Grpc.Auth;
using Google.Protobuf;
using Google.LongRunning;
using Google.Api.Gax;
using Google.Api.Gax.ResourceNames;
using Google.Cloud.Dialogflow.V2;
using static Google.Cloud.Dialogflow.V2.Intent.Types;
using Google.Cloud.Language.V1;
using Google.Cloud.Storage.V1;
using Google.Apis.Dialogflow.v2.Data;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Storage.v1.Data;
Then I followed this link: https://cloud.google.com/dialogflow/docs/quick/api#detect-intent-text-csharp
Then I made this code:
...
// Session
Grpc.Core.Channel mainChannel = DialogflowManipulation.AuthExplicitForChannel(projectID, serviceAccountKeyJSONFilePath);
SessionsClient mainSessionsClient = SessionsClient.Create(mainChannel);
SessionName mainSessionName = new SessionName(projectID, sessionID);
// Input
TextInput mainTextInput = new TextInput() { Text = text, LanguageCode = languageCode };
QueryInput mainQueryInput = new QueryInput() { Text = mainTextInput };
// Detect Intent
DetectIntentResponse response = mainSessionsClient.DetectIntent(mainSessionName, mainQueryInput);
...
I've found when looking at the Debug - Output while in debugging mode the Output prints this after / while it hangs:
Exception thrown: 'System.MissingMethodException' in Grpc.Core.dll
Execution just hangs on that last line .DetectIntent.
Where am I going wrong?
Any help / advice will be appreciated.
...mainSessionsClient.DetectIntent(...- Shiasu-samaSessionsClient mainSessionsClient = SessionsClient.Create(mainChannel);runs fine. So I assume I'm authenticating successfully. Is there maybe another way I can check / test if I'm authenticating correctly? - Shiasu-sama