Enhance Telegram bot functionality with message management and new API methods
ci / tests (push) Successful in 4m0s
ci / build-backend (push) Successful in 3m27s
ci / build-frontend (push) Successful in 1m5s
ci / sonar (push) Successful in 8m22s

Updated the ITelegramApi interface to include a method for deleting messages and modified SendMessageAsync to return the message ID. Enhanced the TelegramBotService to manage message visibility by replacing previous messages with new ones, ensuring a cleaner user experience. Introduced properties in TelegramSubscriber to track the latest menu and notice message IDs. Updated related tests to verify the new message management behavior and adjusted documentation to reflect these changes.
This commit is contained in:
Leonid Pershin committed 2026-07-31 08:24:42 +03:00
1 parent 8a439f1351
commit d6bc2b15ac
9 files changed
+1835 -24

No files matched your search

@@ -235,6 +235,67 @@ public class TelegramBotTests
Assert.Equal(1, sent!.Split("Симпсоны").Length - 1);
}
[Fact]
public async Task Menu_ReplacesThePreviousOne()
{
// Два меню в чате — это две панели с разными галочками, и одна из них врёт. Старое снимаем.
var fixture = new TestDb();
var channel = Channel.Create("Мультреалити", "mult", Now);
channel.UpdateSettings(channel.Name, isEnabled: true, null);
var subscriber = TelegramSubscriber.Create(100, Guid.NewGuid(), "viewer", Now);
await using (var seed = fixture.New())
{
seed.Channels.Add(channel);
seed.TelegramSubscribers.Add(subscriber);
await seed.SaveChangesAsync(CancellationToken.None);
}
var api = Substitute.For<ITelegramApi>();
api.SendMessageAsync(
Arg.Any<TelegramSettings>(),
Arg.Any<long>(),
Arg.Any<string>(),
Arg.Any<IReadOnlyList<IReadOnlyList<TelegramButton>>?>(),
Arg.Any<CancellationToken>()
)
.Returns(777L);
await using (var db = fixture.New())
{
await new TelegramBotService(db, api).HandleAsync(
Settings(),
Message(100, "/start"),
Now,
CancellationToken.None
);
}
await using (var check = fixture.New())
{
Assert.Equal(777L, check.TelegramSubscribers.Single().MenuMessageId);
}
await using (var db = fixture.New())
{
await new TelegramBotService(db, api).HandleAsync(
Settings(),
Message(100, "/start"),
Now,
CancellationToken.None
);
}
// Второй заход снял предыдущее меню, а не оставил его висеть.
await api.Received(1)
.DeleteMessageAsync(
Arg.Any<TelegramSettings>(),
100,
777L,
Arg.Any<CancellationToken>()
);
}
[Fact]
public async Task Callback_FromUnknownChat_IsRefused()
{