private void ChatOnUrlAdded(object sender, ChatUpdateEventArgs e) { using (Trace.Main.scope()) { try { // We only want to act on messages from an external party if (e.ChatMember.ChatMemberType != ChatMemberType.External) { return; } // Get a response from a bot var chat = sender as ChatInteraction; var response = _botManager.GetResponse(chat.InteractionId.Id, new UrlChatMessage { Uri = new Uri(e.Url) }); if (response == null) { return; } SendToChat(chat, response); } catch (Exception ex) { Trace.Main.exception(ex); } } }
private void ChatOnTextAdded(object sender, ChatUpdateEventArgs e) { using (Trace.Main.scope()) { try { // We only want to act on messages from an external party if (e.ChatMember.ChatMemberType != ChatMemberType.External) { return; } var chat = sender as ChatInteraction; // Check for commands // These are special commands, probably to be used for testing. They can be disabled via the EnableCommands parameter in the config file if (_enableCommands) { // Return a list of bot names if (e.Text.Trim().Equals("/bots", StringComparison.InvariantCultureIgnoreCase)) { SendToChat(chat, new TextChatMessage { Text = "Bot names: " + _botManager.Bots.Select(bot => bot.BotName).Aggregate((a, b) => a + ", " + b) }); return; } // Reassign the chat to a specific bot if (e.Text.Trim().StartsWith("/bot", StringComparison.InvariantCultureIgnoreCase)) { ReassignChat(chat.InteractionId.Id, e.Text.Substring(4).Trim(), null); return; } } // Get a response from a bot var response = _botManager.GetResponse(chat.InteractionId.Id, new TextChatMessage { Text = e.Text }); if (response == null) { return; } SendToChat(chat, response); } catch (Exception ex) { Trace.Main.exception(ex); } } }