static async Task MainAsync(string[] args, CancellationToken cancellationToken) { var client = new BlipClientBuilder() .UsingAccessKey("animaisdemo", "V01WNEJtVDBvRVRod1Bycm11Umw=") .Build(); Trace.Listeners.Add(new TextWriterTraceListener(Console.Out)); await client.StartAsync( async m => { Console.WriteLine("Message '{0}' received from '{1}': {2}", m.Id, m.From, m.Content); await client.SendMessageAsync("Pong!", m.From, cancellationToken); return(true); }, n => { Console.WriteLine("Notification '{0}' received from '{1}': {2}", n.Id, n.From, n.Event); return(TaskUtil.TrueCompletedTask); }, c => { Console.WriteLine("Command '{0}' received from '{1}': {2} {3}", c.Id, c.From, c.Method, c.Uri); return(TaskUtil.TrueCompletedTask); }, cancellationToken); Console.WriteLine("Client started. Press enter to stop."); Console.ReadLine(); await client.StopAsync(cancellationToken); Console.WriteLine("Client stopped. Press enter to exit."); Console.ReadLine(); }
static async Task Main(string[] args) { var client = new BlipClientBuilder() .UsingAccessKey("", "") .Build(); Trace.Listeners.Add(new TextWriterTraceListener(Console.Out)); var listener = new BlipChannelListener(client, true, Log.Logger); listener.AddMessageReceiver( new LambdaMessageReceiver(async(message, cancellationToken) => { Console.WriteLine("Message '{0}' received from '{1}': {2}", message.Id, message.From, message.Content); await client.SendMessageAsync($"You said '{message.Content}'.", message.From, cancellationToken); }), m => Task.FromResult(m.Type == MediaType.TextPlain)); listener.AddNotificationReceiver( new LambdaNotificationReceiver((notification, cancellationToken) => { Console.WriteLine("Notification '{0}' received from '{1}': {2}", notification.Id, notification.From, notification.Event); return(Task.CompletedTask); })); listener.AddCommandReceiver( new LambdaCommandReceiver((command, cancellationToken) => { Console.WriteLine("Command '{0}' received from '{1}': {2} {3}", command.Id, command.From, command.Method, command.Uri); return(Task.CompletedTask); })); using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30))) { await client.StartAsync(listener, cts.Token); } Console.WriteLine("Client started. Press enter to stop."); Console.ReadLine(); using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30))) { await client.StopAsync(cts.Token); } Console.WriteLine("Client stopped. Press enter to exit."); Console.ReadLine(); }