public static async Task SendChatbotMessage(string name, string sender, string message) { try { var hub = GlobalHost.ConnectionManager.GetHubContext <ChatHub>(); if (hub != null) { var botMessage = ChatHelper.FilterTextBot(message); var chatItem = new ChatMessageData { UserId = Constant.SYSTEM_USER_CHATBOT.ToString(), Message = HttpUtility.HtmlEncode($"{name}:{sender}:{botMessage}"), IsEnabled = true, Timestamp = DateTime.UtcNow, UserName = name, ChatHandle = sender, IsBot = true, }; await _cache.AddMessage(chatItem); chatItem.Message = botMessage; await BroadcastMessage(hub, chatItem); } } catch (Exception) { } }