private async Task SendMessageToHandlerAsync(Channel channel, User user, string text, bool botIsMentioned, Handler handler) { try { await handler.OnMessage(channel, user, text, botIsMentioned, _cancellationSource.Token); } catch (Exception ex) { await SendMessage(channel, ex.ToString()); } }
protected void HandleRecievedMessage(Channel channel, User user, string text, bool botIsMentioned) { // If the text is cancellation, then send a cancellation message instead. if (_cancellationTerms.Contains(text, StringComparer.OrdinalIgnoreCase)) { _cancellationSource.Cancel(); _cancellationSource = new CancellationTokenSource(); return; } foreach (var handler in _handlers) { _handlerTasks.Add(SendMessageToHandlerAsync(channel, user, text, botIsMentioned, handler)); } }
internal override Task SendMessage(Channel channel, string text, Attachment[] attachments = null) { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine(text); if (attachments != null && attachments.Any()) { foreach (var attachment in attachments) { if (!string.IsNullOrEmpty(attachment.Pretext)) Console.WriteLine(attachment.Pretext); if (!string.IsNullOrEmpty(attachment.AuthorName)) Console.WriteLine(attachment.AuthorName); Console.WriteLine($"{attachment.Title} <{attachment.TitleLink}>"); if (!string.IsNullOrEmpty(attachment.Text)) Console.WriteLine(attachment.Text); foreach (var field in attachment.Fields) Console.WriteLine($"{field.Title}: {field.Value}"); Console.WriteLine(); } } Console.ResetColor(); return Task.FromResult(true); }
internal override Task SendTypingIndicator(Channel channel) { return Task.FromResult(true); }
protected override async Task OnMessage(Channel channel, User user, string text, bool botIsMentioned) { _channels[channel.ID] = channel; _events.OnNext(new SlackMessageReceived { ChannelId = channel.ID, ChannelName = channel.Name, IsPrivate = channel.IsPrivate, IsMember = channel.IsMember, Text = text, IsBotMentioned = botIsMentioned, UserName = user.Name, UserId = user.ID }); await Task.FromResult(true); }
protected async Task SayGoodbye(Channel channel) { await SendMessage(channel, RandomMessages.Goodbye()); }
protected async Task SayHello(Channel channel) { await SendMessage(channel, RandomMessages.Hello()); }
internal abstract Task SendTypingIndicator(Channel channel);
internal abstract Task SendMessage(Channel channel, string text, Attachment[] attachments = null);
protected async Task SendTypingIndicator(Channel channel) { await _bot.SendTypingIndicator(channel); }
protected async Task SendMessage(Channel channel, string text, Attachment[] attachments = null) { await _bot.SendMessage(channel, text, attachments); }
public virtual Task OnMessage(Channel channel, User user, string text, bool botIsMentioned, CancellationToken cancellationToken) { return OnMessage(channel, user, text, botIsMentioned); }
protected virtual Task OnMessage(Channel channel, User user, string text, bool botIsMentioned) { return Task.FromResult(true); }