Fix: Message threading - navigation now sends new messages at bottom

- Changed HandleMainMenu to send new messages instead of editing
- Changed HandleBrowse to send new messages for category navigation
- Changed HandleViewCart to use SendNewCartMessage (already existed)
- Changed HandleViewOrders to send new messages for order list
- Changed HandleViewOrder to send new messages for order details

This ensures the active conversation always appears at the bottom of the chat
instead of mid-thread when users click menu buttons. Provides better UX and
natural conversation flow in Telegram.
This commit is contained in:
SysAdmin 2025-10-06 00:44:28 +01:00
parent c8f22c783d
commit 6c79c04ebd

View File

@ -253,9 +253,9 @@ namespace TeleBot.Handlers
private async Task HandleMainMenu(ITelegramBotClient bot, Message message, UserSession session)
{
await bot.EditMessageTextAsync(
// Send new message at bottom instead of editing old one
await bot.SendTextMessageAsync(
message.Chat.Id,
message.MessageId,
MessageFormatter.FormatWelcome(true),
parseMode: Telegram.Bot.Types.Enums.ParseMode.Markdown,
replyMarkup: MenuBuilder.MainMenu()
@ -274,13 +274,12 @@ namespace TeleBot.Handlers
var categories = await _shopService.GetCategoriesAsync();
await SafeEditMessageAsync(
bot,
// Send new message at bottom for navigation
await bot.SendTextMessageAsync(
message.Chat.Id,
message.MessageId,
MessageFormatter.FormatCategories(categories),
Telegram.Bot.Types.Enums.ParseMode.Markdown,
MenuBuilder.CategoryMenu(categories)
parseMode: Telegram.Bot.Types.Enums.ParseMode.Markdown,
replyMarkup: MenuBuilder.CategoryMenu(categories)
);
session.State = SessionState.BrowsingCategories;
}
@ -516,14 +515,8 @@ namespace TeleBot.Handlers
session.Cart.GetTotalAmount()
);
await bot.EditMessageTextAsync(
message.Chat.Id,
message.MessageId,
MessageFormatter.FormatCart(session.Cart),
parseMode: Telegram.Bot.Types.Enums.ParseMode.Markdown,
replyMarkup: _menuBuilder.CartMenu(session.Cart)
);
session.State = SessionState.ViewingCart;
// Send new message at bottom instead of editing
await SendNewCartMessage(bot, message.Chat.Id, session);
}
private async Task SendNewCartMessage(ITelegramBotClient bot, long chatId, UserSession session)
@ -1130,11 +1123,11 @@ namespace TeleBot.Handlers
telegramUser.LastName ?? ""
);
// Send new message at bottom for navigation
if (!orders.Any())
{
await bot.EditMessageTextAsync(
await bot.SendTextMessageAsync(
message.Chat.Id,
message.MessageId,
"📦 *Your Orders*\n\nYou have no orders yet.",
parseMode: Telegram.Bot.Types.Enums.ParseMode.Markdown,
replyMarkup: MenuBuilder.MainMenu()
@ -1142,9 +1135,8 @@ namespace TeleBot.Handlers
}
else
{
await bot.EditMessageTextAsync(
await bot.SendTextMessageAsync(
message.Chat.Id,
message.MessageId,
$"📦 *Your Orders*\n\nFound {orders.Count} order(s):",
parseMode: Telegram.Bot.Types.Enums.ParseMode.Markdown,
replyMarkup: MenuBuilder.OrderListMenu(orders)
@ -1171,9 +1163,9 @@ namespace TeleBot.Handlers
return;
}
await bot.EditMessageTextAsync(
// Send new message at bottom for navigation
await bot.SendTextMessageAsync(
message.Chat.Id,
message.MessageId,
MessageFormatter.FormatOrder(order),
parseMode: Telegram.Bot.Types.Enums.ParseMode.Markdown,
replyMarkup: MenuBuilder.MainMenu()