Alex
Alex

Reputation: 41

Unable to access Dialogflow V2 detect Intent C# Webhook

Getting following error:

System.InvalidOperationException: 'The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials...

public static int DetectIntentFromTexts(string projectId,
                                        string sessionId,
                                        string text,
                                        string languageCode = "en-US")
        {

            var client = SessionsClient.Create();

            var response = client.DetectIntent(
                session: SessionName.FromProjectSession(projectId, sessionId),
                queryInput: new QueryInput()
                {
                    Text = new TextInput()
                    {
                        Text = text,
                        LanguageCode = languageCode
                    }
                });

            var queryResult = response.QueryResult;

            Console.WriteLine($"Query text: {queryResult.QueryText}");
            if (queryResult.Intent != null)
            {
                Console.WriteLine($"Intent detected: {queryResult.Intent.DisplayName}");
            }
            Console.WriteLine($"Intent confidence: {queryResult.IntentDetectionConfidence}");
            Console.WriteLine($"Fulfillment text: {queryResult.FulfillmentText}");
            Console.WriteLine();

            return 0;
        }

Upvotes: 0

Views: 187

Answers (1)

Manoj Venkat
Manoj Venkat

Reputation: 11

You need to place the Credentials.json key generated from Google cloud in your code and set it to the environment variable in the start up of your project.

Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", file);

//In Global.asax.cs in case of .net framework Application //In startup.cs in case of .net core Application //In the above code line file means the local path of your credentails.json key

Upvotes: 1

Related Questions