From 9f62177c4ea7db2cb7f0a460cf6f4656ac7b60f2 Mon Sep 17 00:00:00 2001 From: Keroosha Date: Tue, 7 Feb 2023 22:32:33 +0300 Subject: [PATCH] Less fragile obsolete validation, forward message on relay --- PublishHelperBot/Handlers.fs | 2 +- PublishHelperBot/Program.fs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/PublishHelperBot/Handlers.fs b/PublishHelperBot/Handlers.fs index 7ffb5cb..a708311 100644 --- a/PublishHelperBot/Handlers.fs +++ b/PublishHelperBot/Handlers.fs @@ -59,7 +59,7 @@ let public RelayHandler: Handler = fun (u, c, tg) -> let caption = lazy RelayResolveCaption(captionMode, author, c.relayUrl) match reply.Type with - | MessageType.Text -> tg.SendTextMessageAsync(channelId, reply.Text) + | MessageType.Text -> tg.ForwardMessageAsync(channelId, reply.Chat.Id, reply.MessageId) | MessageType.Photo -> tg.SendPhotoAsync(channelId, photoMedia.Value, caption = caption.Value, parseMode = RelayParseMode) | MessageType.Video -> tg.SendVideoAsync(channelId, reply.Video.FileId, caption = caption.Value, diff --git a/PublishHelperBot/Program.fs b/PublishHelperBot/Program.fs index c006fdc..b25c6a1 100644 --- a/PublishHelperBot/Program.fs +++ b/PublishHelperBot/Program.fs @@ -15,11 +15,11 @@ let CreateBot (config: BotConfig, http: HttpClient) = TelegramBotClient(config.t let config = CreateConfig <| "SBPB_CONFIG_PATH"; let botClient = CreateBot <| (config, new HttpClient()) let startDate = DateTime.UtcNow +let isObsoleteUpdate (u: Update) = u.Type = UpdateType.Message && u.Message.Date < startDate; let updateHandle (bc: ITelegramBotClient) (u: Update) (ct: CancellationToken): Task = match u with - // Ignore old messages (to prevent overposting on downtime) - | _ when u.Message.Date < startDate -> Task.CompletedTask + | _ when isObsoleteUpdate u -> Task.CompletedTask | _ when RelayMatch <| (u, config) -> RelayHandler <| (u, config, bc) | _ -> Task.CompletedTask