public static bool CanHandleGroup(string dashboardUserId, string groupId) { DashboardUser du = dul.GetById(dashboardUserId); if (du == null) { return(false); } if (BotTools.IsUserOperator(du.TelegramUserId)) { return(true); } return(dpl.GetGroups(dashboardUserId) .SingleOrDefault(x => x.GroupId == groupId) != null); }
private static void RecordSupportSessionMessage(Message message) { Models.SupportSessionLog.SenderType senderType = Models.SupportSessionLog.SenderType.User; if (BotTools.IsUserOperator(message.From.Id)) { senderType = Models.SupportSessionLog.SenderType.Operator; } else if (CacheData.CurrentChatAdmins[message.Chat.Id] .Contains(message.From.Id)) { senderType = Models.SupportSessionLog.SenderType.Admin; } LogTools.AddSupportSessionLog(new Models.SupportSessionLog() { GroupId = CacheData.Groups[message.Chat.Id].GroupId, SenderId = message.From.Id, Text = message.Text, Timestamp = DateTime.UtcNow, Type = senderType }); }
public static bool HandleSupportSessionMsg(Message message) { if (!CacheData.ActiveSupport .Contains(message.Chat.Id)) { return(false); } if (!lastOperatorSupportMsg.ContainsKey(message.Chat.Id)) { lastOperatorSupportMsg[message.Chat.Id] = DateTime.UtcNow; } bool isFromOperator = false; if (BotTools.IsUserOperator(message.From.Id)) { isFromOperator = true; Manager.BotClient.DeleteMessageAsync(message.Chat.Id, message.MessageId); ChatMessage newMsg = new ChatMessage() { Timestamp = DateTime.UtcNow, Chat = message.Chat, ParseMode = ParseMode.Html, Text = message.Text + "\n\nMessage from operator: <b>" + message.From.Username + "</b>" }; if (message.ReplyToMessage != null) { newMsg.ReplyToMessageId = message.ReplyToMessage.MessageId; } MessageQueueManager.EnqueueMessage(newMsg); lastOperatorSupportMsg[message.Chat.Id] = DateTime.UtcNow; } var timeDifference = DateTime.UtcNow - lastOperatorSupportMsg[message.Chat.Id]; if (timeDifference.Minutes >= 3 && timeDifference.Minutes < 5) { ChatMessage newMsg = new ChatMessage() { Timestamp = DateTime.UtcNow, Chat = message.Chat, ParseMode = ParseMode.Markdown, Text = "*[Alert]*" + "\n\nSupport session is going to be automatically closed in 2 minutes " + "due to operator's inactivity" }; MessageQueueManager.EnqueueMessage(newMsg); } if (timeDifference.Minutes >= 5) { ChatMessage newMsg = new ChatMessage() { Timestamp = DateTime.UtcNow, Chat = message.Chat, ParseMode = ParseMode.Markdown, Text = "*[Alert]*" + "\n\nSupport session is closed due to operator's inactivity" }; MessageQueueManager.EnqueueMessage(newMsg); CacheData.ActiveSupport.Remove(message.Chat.Id); CacheData.CurrentChatAdmins.Remove(message.Chat.Id); MessageQueueManager.EnqueueLog(new ChatMessage() { ParseMode = ParseMode.Markdown, Text = String.Format( "*[Log]*" + "\n\nSupport session ended due to operator's inactivity" + "\nChatId: `{0}`" + "\nChat: `{1}`" + "\n\n*hash_code:* #UB{2}-{3}", message.Chat.Id, message.Chat.Title, message.Chat.Id.ToString().Replace("-", ""), Guid.NewGuid()) }); } Task.Run(() => RecordSupportSessionMessage(message)); return(isFromOperator); }