private async Task GenerateFileLog(Message message, BotManager.File file, Bot bot) { BotUser botUser = null; using (_dataFilter.Disable <IMultiTenant>()) botUser = await _botUserRepository.FindAsync(bu => bu.BotId.CompareTo(bot.Id) == 0 && bu.UserId == message.From.Id); if (botUser == null) { botUser = new BotUser() { BotId = bot.Id, FirstName = message.From.FirstName, IsActive = true, LastName = message.From.LastName, UserId = message.From.Id, UserName = message.From.Username, TenantId = bot.TenantId }; await _botUserRepository.InsertAsync(botUser); } var usageLog = new UsageLog() { BotUserId = botUser.Id, FileId = file.Id, requestDateTime = DateTime.Now, RequestUrl = file.ShareUrl,//TODO TenantId = bot.TenantId, UsageResultType = UsageResultType.Done }; await _usageLogRepository.InsertAsync(usageLog); }
private async Task SendDocument(Message message, TelegramBotClient telegramBotClient, Bot bot) { var messages = message.Text.Split(' '); if (messages.Length < 2) { return; } var fileCodepath = messages[1]; if (fileCodepath == null || fileCodepath.Equals(string.Empty)) { return; } BotManager.File file = null; using (_dataFilter.Disable <IMultiTenant>()) file = await _fileRepository.FindAsync(f => f.ShareUrl.Contains(fileCodepath) && f.BotId == bot.Id); if (file == null) { return; } switch (file.FileType) { case BotManager.FileType.Audio: await telegramBotClient.SendChatActionAsync(message.Chat.Id, ChatAction.UploadAudio); await telegramBotClient.SendAudioAsync(chatId : message.Chat.Id, audio : file.FileUrl); break; case BotManager.FileType.Video: await telegramBotClient.SendChatActionAsync(message.Chat.Id, ChatAction.UploadVideo); await telegramBotClient.SendVideoAsync(chatId : message.Chat.Id, video : file.FileUrl); break; case BotManager.FileType.Document: await telegramBotClient.SendChatActionAsync(message.Chat.Id, ChatAction.UploadDocument); await telegramBotClient.SendDocumentAsync(chatId : message.Chat.Id, document : file.FileUrl); break; case BotManager.FileType.Image: await telegramBotClient.SendChatActionAsync(message.Chat.Id, ChatAction.UploadPhoto); await telegramBotClient.SendPhotoAsync(chatId : message.Chat.Id, photo : file.FileUrl); break; default: break; } await GenerateFileLog(message, file, bot); }