Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public ICallbackQueryHandler CreateCallbackHandler(CallbackQuery callbackQuery)
=> _serviceProvider.GetService<EditProfileCallbackQueryHandler>(),
{ Data: { } data } when data.StartsWith("fr-session")
=> _serviceProvider.GetService<FileReceivingSessionCallbackQueryHandler>(),
{ Data: { } data } when data.StartsWith("menu-")
=> _serviceProvider.GetService<BotMenuCallbackQueryHandler>(),
_ => _serviceProvider.GetService<DefaultCallbackQueryHandler>(),
};
}
Expand Down
1 change: 1 addition & 0 deletions src/FileReceiver.Bl.Impl/FileReceiverBlInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ private static void AddCallbackQueryHandlers(this IServiceCollection services)
{
services.AddTransient<EditProfileCallbackQueryHandler, EditProfileCallbackQueryHandler>();
services.AddTransient<FileReceivingSessionCallbackQueryHandler, FileReceivingSessionCallbackQueryHandler>();
services.AddTransient<BotMenuCallbackQueryHandler, BotMenuCallbackQueryHandler>();
services.AddTransient<DefaultCallbackQueryHandler, DefaultCallbackQueryHandler>();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Threading.Tasks;

using FileReceiver.Bl.Abstract.Factories;
using FileReceiver.Bl.Abstract.Handlers;

using Telegram.Bot.Types;

namespace FileReceiver.Bl.Impl.Handlers.CallbackQuery
{
public class BotMenuCallbackQueryHandler : ICallbackQueryHandler
{
private readonly ICommandHandlerFactory _commandHandlerFactory;

public BotMenuCallbackQueryHandler(ICommandHandlerFactory commandHandlerFactory)
{
_commandHandlerFactory = commandHandlerFactory;
}

public async Task HandleCallback(Telegram.Bot.Types.CallbackQuery callbackQuery)
{
var update = new Update()
{
CallbackQuery = callbackQuery
};

switch (callbackQuery)
{
case { Data: "menu-/profile", From: { } from }:
await _commandHandlerFactory
.CreateCommandHandler("/profile")
.HandleCommandAsync(update);
break;
case { Data: "menu-/send_file", From: { } from }:
await _commandHandlerFactory
.CreateCommandHandler("/send_file")
.HandleCommandAsync(update);
break;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public async Task HandleUpdateAsync(Update update)
TransactionData = transactionData,
};

// TODO: rewrite with pattern matching
switch (editingAction)
{
case ProfileEditingAction.UpdateFirstName:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,9 @@ private async Task SetFileSizeConstraintAsync(FileReceivingSessionDataDto data)

await _receivingSessionService.SetFileSizeConstraintAsync(data.SessionId, maxFileSize);
await _botMessagesService.SendTextMessageAsync(data.UserId,
// TODO: Add regex pattern examples
"Now send me file name constraints written with regex pattern. " +
"You can check your pattern [here](https://regex101.com/). " +
"To send several patterns separate them with a coma");
"If you don't want to use any file name constraints send `-1`.");
}
catch (Exception ex)
{
Expand Down
10 changes: 7 additions & 3 deletions src/FileReceiver.Bl.Impl/Services/BotMessagesService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Threading.Tasks;

using FileReceiver.Bl.Abstract.Services;
using FileReceiver.Common.Constants;

using Microsoft.Extensions.Logging;

Expand All @@ -25,14 +26,17 @@ public BotMessagesService(

public async Task SendMenuAsync(long userOrChatId)
{
// TODO: Create a real bot menu with buttons which will invoke command handlers and replace plain text with resources file
var sentMsg = await _botClient.SendTextMessageAsync(userOrChatId, "This is a bot menu...");
var sentMsg = await _botClient.SendTextMessageAsync(
userOrChatId,
"Menu:",
ParseMode.Markdown,
replyMarkup: Keyboards.BotMenu);

if (sentMsg is null) _logger.LogWarning("Message wasn't sent to {userId}", userOrChatId);
}

public async Task SendErrorAsync(long userOrChatId, string errorMessage)
{
// TODO: Update error sending, maybe add an image or smth like that and replace plain text with resources file
var sentMsg = await _botClient.SendTextMessageAsync(userOrChatId,
$"Sorry, an error happen. Error description: {errorMessage}");
if (sentMsg is null) _logger.LogWarning("Message wasn't sent to {userId}", userOrChatId);
Expand Down
1 change: 0 additions & 1 deletion src/FileReceiver.Bl.Impl/Services/FileReceivingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public async Task FinishReceivingTransaction(long userId)

public async Task<bool> SaveDocument(long userId, Guid sessionId, Document document)
{
// TODO: Add constraints check
var transaction = await _transactionService.Get(userId, TransactionType.FileSending);
var memStream = new MemoryStream();
var fileInfo = await _botClient.GetFileAsync(document.FileId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using AutoMapper;

using FileReceiver.Bl.Abstract.Services;
using FileReceiver.Common.Constants;
using FileReceiver.Common.Enums;
using FileReceiver.Common.Exceptions;
using FileReceiver.Common.Models;
Expand Down Expand Up @@ -47,7 +48,7 @@ public async Task CreateFileReceivingSessionAsync(long userId)
UserId = userId,
Constrains = new ConstraintsModel(),
SessionState = FileReceivingSessionState.FileSizeConstraintSet,
MaxFiles = 50, // TODO: should be moved to a constants file
MaxFiles = DefaultValues.FilesAtSession,
CreateData = DateTimeOffset.UtcNow,
};

Expand Down
7 changes: 7 additions & 0 deletions src/FileReceiver.Common/Constants/DefaultValues.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace FileReceiver.Common.Constants
{
public static class DefaultValues
{
public const int FilesAtSession = 50;
}
}
11 changes: 11 additions & 0 deletions src/FileReceiver.Common/Constants/Keyboards.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,16 @@ public static class Keyboards
},
});

public static readonly InlineKeyboardMarkup BotMenu = new(new[]
{
new[]
{
InlineKeyboardButton.WithCallbackData("Profile", "menu-/profile"),
},
new[]
{
InlineKeyboardButton.WithCallbackData("Send File", "menu-/send_file"),
},
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using FileReceiver.Bl.Abstract.Services;
using FileReceiver.Bl.Impl.Services;
using FileReceiver.Common.Constants;

using Microsoft.Extensions.Logging;

Expand Down Expand Up @@ -36,7 +37,11 @@ public async Task SendMenuAsync_ShouldReturnNothing_WhenUserIdValid(long userId)
await _sut.SendMenuAsync(userId);

// Assert
await _botClient.Received(1).SendTextMessageAsync(userId, "This is a bot menu...");
await _botClient.Received(1).SendTextMessageAsync(
userId,
"Menu:",
ParseMode.Markdown,
replyMarkup: Keyboards.BotMenu);
}

[Theory]
Expand Down