Created
July 10, 2018 19:50
-
-
Save rickcrawford/3f6ca96680645b16a9934dc5f6ba506a to your computer and use it in GitHub Desktop.
Agent Client using credentials json file in .NET for Dialogflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Xunit; | |
using System.IO; | |
using Google.Cloud.Dialogflow.V2; | |
using Grpc.Core; | |
using Google.Apis.Auth.OAuth2; | |
using Grpc.Auth; | |
namespace dialogflowtest | |
{ | |
public class UnitTest1 | |
{ | |
[Fact] | |
public void Test1() | |
{ | |
Console.WriteLine("Starting test..."); | |
// Configure gRCP for a proxy server: | |
//Environment.SetEnvironmentVariable("http_proxy", "http://username:password@proxy_address:80"); | |
//Environment.SetEnvironmentVariable("https_proxy", "https://username:password@proxy_address:443"); | |
// Example when loading credentials from file programatically | |
// You can also set the path in an environment variable - GOOGLE_APPLICATION_CREDENTIALS, | |
// then this step would not be necessary and you could just call AgentsClient client = AgentsClient.Create(); | |
GoogleCredential cred = GoogleCredential.FromFile("client_credentials.json"); | |
Channel channel = new Channel(AgentsClient.DefaultEndpoint.Host, cred.ToChannelCredentials()); | |
AgentsClient client = AgentsClient.Create(channel); | |
// IAM Permission Dialogflow API Admin needed for Agent | |
// IAM Permission Dialogflow API Client needed for Session (intent query) | |
Agent agent = client.GetAgent(new ProjectName("rjc-sandbox")); | |
Console.WriteLine(agent.ToString()); | |
Console.WriteLine("Done."); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment