de9f56c97d
PR Checks / test-and-build (pull_request) Failing after 3m18s
Route new schedules to an existing forum topic when /newsession is sent inside one, create bot-owned topics only from the forum root, and keep group notifications/dashboard updates threaded to the stored topic. Persist topic ownership so deletion only removes empty bot-created topics, add topic routing tests and smoke coverage, and bump release metadata to 1.14.0.
41 lines
1.6 KiB
C#
41 lines
1.6 KiB
C#
namespace GmRelay.Bot.Infrastructure.Telegram;
|
|
|
|
public sealed record TelegramTopicDestination(
|
|
int? MessageThreadId,
|
|
bool ShouldCreateForumTopic,
|
|
bool TopicCreatedByBot);
|
|
|
|
public static class TelegramTopicRouting
|
|
{
|
|
public const string MissingForumTopicRightsMessage =
|
|
"Не удалось создать Telegram topic. Сделайте бота admin и включите право Manage Topics, затем повторите команду.";
|
|
|
|
public static TelegramTopicDestination ResolveNewScheduleDestination(
|
|
bool chatIsForum,
|
|
int? incomingMessageThreadId)
|
|
{
|
|
if (!chatIsForum)
|
|
{
|
|
return new TelegramTopicDestination(null, ShouldCreateForumTopic: false, TopicCreatedByBot: false);
|
|
}
|
|
|
|
if (incomingMessageThreadId.HasValue)
|
|
{
|
|
return new TelegramTopicDestination(
|
|
incomingMessageThreadId,
|
|
ShouldCreateForumTopic: false,
|
|
TopicCreatedByBot: false);
|
|
}
|
|
|
|
return new TelegramTopicDestination(null, ShouldCreateForumTopic: true, TopicCreatedByBot: true);
|
|
}
|
|
|
|
public static bool ShouldDeleteForumTopic(bool topicCreatedByBot, int remainingSessionsInTopic) =>
|
|
topicCreatedByBot && remainingSessionsInTopic == 0;
|
|
|
|
public static bool IsMissingForumTopicRightsError(string apiError) =>
|
|
apiError.Contains("not enough rights", StringComparison.OrdinalIgnoreCase) ||
|
|
apiError.Contains("CHAT_ADMIN_REQUIRED", StringComparison.OrdinalIgnoreCase) ||
|
|
apiError.Contains("not an administrator", StringComparison.OrdinalIgnoreCase);
|
|
}
|