public void Shutdown() { if (_channel != null) { _channel.ShutdownAsync(); _requestStream = null; _responseStream = null; _assistant = null; } }
public async Task AssistCommand(CommandContext ctx, [RemainingText] string input) { var secrets = new ClientSecrets { ClientId = ClientId, ClientSecret = ClientSecret }; // check if already authorized, else authorize if (UserCredentials == null) { UserCredentials = await Authorize(secrets); } // create the request var request = new AssistRequest(); request.Config = CreateConfig("en-US"); request.Config.TextQuery = input; var channel = GrpcChannel.ForAddress(Endpoint, new GrpcChannelOptions { Credentials = UserCredentials.ToChannelCredentials() }); var client = new EmbeddedAssistant.EmbeddedAssistantClient(channel); var assist = client.Assist(); // send the gRPC request to google assistant await assist.RequestStream.WriteAsync(request); // first element is the response without audio await assist.ResponseStream.MoveNext(CancellationToken.None); var response = assist.ResponseStream.Current; // read audio stream var audioStream = new MemoryStream(); while (await assist.ResponseStream.MoveNext(CancellationToken.None)) { var current = assist.ResponseStream.Current; current.AudioOut.AudioData.WriteTo(audioStream); } audioStream.Position = 0; await ctx.RespondWithFileAsync(audioStream, file_name : "response.ogg", content : response.DialogStateOut?.SupplementalDisplayText); audioStream.Dispose(); }
public void UpdateCredentials(OAuthCredentials oAuthCredentials) { TokenResponse responseToken = new TokenResponse() { AccessToken = oAuthCredentials.access_token, ExpiresInSeconds = oAuthCredentials.expires_in, RefreshToken = oAuthCredentials.refresh_token, Scope = authenticationConf.scope, TokenType = oAuthCredentials.token_type, }; credential = new UserCredential(googleAuthFlow, "", responseToken); channel = new Channel(assistantConf.assistantApiEndpoint, 443, credential.ToChannelCredentials()); embeddedAssistantClient = new EmbeddedAssistant.EmbeddedAssistantClient(channel); }
public void InitAssistantForUser(ChannelCredentials channelCreds) { _channel = new Channel(Const.AssistantEndpoint, channelCreds); _assistant = new EmbeddedAssistant.EmbeddedAssistantClient(_channel); }