diff --git a/src/VahterBanBot.Tests/BanTests.fs b/src/VahterBanBot.Tests/BanTests.fs index e2853f9..947c621 100644 --- a/src/VahterBanBot.Tests/BanTests.fs +++ b/src/VahterBanBot.Tests/BanTests.fs @@ -3,6 +3,7 @@ module VahterBanBot.Tests.BanTests open System.Net open VahterBanBot.Tests.ContainerTestBase open VahterBanBot.Tests.TgMessageUtils +open VahterBanBot.Utils open Xunit open Xunit.Extensions.AssemblyFixture @@ -16,12 +17,12 @@ type BanTests(fixture: VahterTestContainers) = // send the ban message let! banResp = - Tg.replyMsg(msgUpdate.Message, "/ban", fixture.Vahters[0]) + Tg.replyMsg(msgUpdate.Message.Value, "/ban", fixture.Vahters[0]) |> fixture.SendMessage Assert.Equal(HttpStatusCode.OK, banResp.StatusCode) // assert that the message got banned - let! msgBanned = fixture.MessageBanned msgUpdate.Message + let! msgBanned = fixture.MessageBanned msgUpdate.Message.Value Assert.True msgBanned } @@ -33,12 +34,12 @@ type BanTests(fixture: VahterTestContainers) = // send the ban message from a non-admin user let! banResp = - Tg.replyMsg(msgUpdate.Message, "/ban", Tg.user()) + Tg.replyMsg(msgUpdate.Message.Value, "/ban", Tg.user()) |> fixture.SendMessage Assert.Equal(HttpStatusCode.OK, banResp.StatusCode) // assert that the message NOT banned - let! msgNotBanned = fixture.MessageBanned msgUpdate.Message + let! msgNotBanned = fixture.MessageBanned msgUpdate.Message.Value Assert.False msgNotBanned } @@ -50,12 +51,12 @@ type BanTests(fixture: VahterTestContainers) = // send the ban message let! banResp = - Tg.replyMsg(msgUpdate.Message, "/ban", fixture.Vahters[0]) + Tg.replyMsg(msgUpdate.Message.Value, "/ban", fixture.Vahters[0]) |> fixture.SendMessage Assert.Equal(HttpStatusCode.OK, banResp.StatusCode) // assert that the message NOT banned - let! msgNotBanned = fixture.MessageBanned msgUpdate.Message + let! msgNotBanned = fixture.MessageBanned msgUpdate.Message.Value Assert.False msgNotBanned } @@ -67,12 +68,12 @@ type BanTests(fixture: VahterTestContainers) = // send the ban message let! banResp = - Tg.replyMsg(msgUpdate.Message, "/ban", fixture.Vahters[1]) + Tg.replyMsg(msgUpdate.Message.Value, "/ban", fixture.Vahters[1]) |> fixture.SendMessage Assert.Equal(HttpStatusCode.OK, banResp.StatusCode) // assert that the message NOT banned - let! msgNotBanned = fixture.MessageBanned msgUpdate.Message + let! msgNotBanned = fixture.MessageBanned msgUpdate.Message.Value Assert.False msgNotBanned } @@ -84,22 +85,22 @@ type BanTests(fixture: VahterTestContainers) = // send the ban message let! banResp = - Tg.replyMsg(msgUpdate.Message, "/ban", fixture.Vahters[0]) + Tg.replyMsg(msgUpdate.Message.Value, "/ban", fixture.Vahters[0]) |> fixture.SendMessage Assert.Equal(HttpStatusCode.OK, banResp.StatusCode) // assert that the message got banned - let! msgBanned = fixture.MessageBanned msgUpdate.Message + let! msgBanned = fixture.MessageBanned msgUpdate.Message.Value Assert.True msgBanned // send the unban message from another vahter let! banResp = - Tg.quickMsg($"/unban {msgUpdate.Message.From.Id}", chat = fixture.ChatsToMonitor[0], from = fixture.Vahters[1]) + Tg.quickMsg($"/unban {msgUpdate.Message.Value.FromId}", chat = fixture.ChatsToMonitor[0], from = fixture.Vahters[1]) |> fixture.SendMessage Assert.Equal(HttpStatusCode.OK, banResp.StatusCode) // assert that the message no longer banned - let! msgBanned = fixture.MessageBanned msgUpdate.Message + let! msgBanned = fixture.MessageBanned msgUpdate.Message.Value Assert.False msgBanned } @@ -111,22 +112,22 @@ type BanTests(fixture: VahterTestContainers) = // send the ban message let! banResp = - Tg.replyMsg(msgUpdate.Message, "/ban", fixture.Vahters[0]) + Tg.replyMsg(msgUpdate.Message.Value, "/ban", fixture.Vahters[0]) |> fixture.SendMessage Assert.Equal(HttpStatusCode.OK, banResp.StatusCode) // assert that the message got banned - let! msgBanned = fixture.MessageBanned msgUpdate.Message + let! msgBanned = fixture.MessageBanned msgUpdate.Message.Value Assert.True msgBanned // send the unban message from a random user let! banResp = - Tg.quickMsg($"/unban {msgUpdate.Message.From.Id}", chat = fixture.ChatsToMonitor[0]) + Tg.quickMsg($"/unban {msgUpdate.Message.Value.FromId}", chat = fixture.ChatsToMonitor[0]) |> fixture.SendMessage Assert.Equal(HttpStatusCode.OK, banResp.StatusCode) // assert that the message still banned - let! msgBanned = fixture.MessageBanned msgUpdate.Message + let! msgBanned = fixture.MessageBanned msgUpdate.Message.Value Assert.True msgBanned } diff --git a/src/VahterBanBot.Tests/BaseTests.fs b/src/VahterBanBot.Tests/BaseTests.fs index 7a01316..b4cbcce 100644 --- a/src/VahterBanBot.Tests/BaseTests.fs +++ b/src/VahterBanBot.Tests/BaseTests.fs @@ -3,7 +3,7 @@ module BaseTests open System open System.Net.Http open System.Text -open Telegram.Bot.Types +open Funogram.Telegram.Types open VahterBanBot.Tests.ContainerTestBase open Xunit open Xunit.Extensions.AssemblyFixture @@ -28,7 +28,7 @@ type BaseTests(fixture: VahterTestContainers) = [] let ``Should be possible to interact with the bot`` () = task { - let! resp = Update(Id = 123) |> fixture.SendMessage + let! resp = Update.Create(updateId = 123) |> fixture.SendMessage let! body = resp.Content.ReadAsStringAsync() Assert.Equal(System.Net.HttpStatusCode.OK, resp.StatusCode) Assert.Equal("null", body) diff --git a/src/VahterBanBot.Tests/ContainerTestBase.fs b/src/VahterBanBot.Tests/ContainerTestBase.fs index 8fee468..298b20b 100644 --- a/src/VahterBanBot.Tests/ContainerTestBase.fs +++ b/src/VahterBanBot.Tests/ContainerTestBase.fs @@ -9,8 +9,8 @@ open System.Threading.Tasks open DotNet.Testcontainers.Builders open DotNet.Testcontainers.Configurations open DotNet.Testcontainers.Containers +open Funogram.Telegram.Types open Npgsql -open Telegram.Bot.Types open Testcontainers.PostgreSql open VahterBanBot.Tests.TgMessageUtils open VahterBanBot.Types diff --git a/src/VahterBanBot.Tests/MLBanTests.fs b/src/VahterBanBot.Tests/MLBanTests.fs index d380587..abdf5f5 100644 --- a/src/VahterBanBot.Tests/MLBanTests.fs +++ b/src/VahterBanBot.Tests/MLBanTests.fs @@ -16,7 +16,7 @@ type MLBanTests(fixture: VahterTestContainers, _unused: MlAwaitFixture) = let! _ = fixture.SendMessage msgUpdate // assert that the message got auto banned - let! msgBanned = fixture.MessageIsAutoDeleted msgUpdate.Message + let! msgBanned = fixture.MessageIsAutoDeleted msgUpdate.Message.Value Assert.True msgBanned } @@ -29,7 +29,7 @@ type MLBanTests(fixture: VahterTestContainers, _unused: MlAwaitFixture) = let! _ = fixture.SendMessage msgUpdate // assert that the message got auto banned - let! msgBanned = fixture.MessageIsAutoDeleted msgUpdate.Message + let! msgBanned = fixture.MessageIsAutoDeleted msgUpdate.Message.Value Assert.False msgBanned } @@ -42,7 +42,7 @@ type MLBanTests(fixture: VahterTestContainers, _unused: MlAwaitFixture) = let! _ = fixture.SendMessage msgUpdate // assert that the message got auto banned - let! msgBanned = fixture.MessageIsAutoDeleted msgUpdate.Message + let! msgBanned = fixture.MessageIsAutoDeleted msgUpdate.Message.Value Assert.False msgBanned } @@ -54,7 +54,7 @@ type MLBanTests(fixture: VahterTestContainers, _unused: MlAwaitFixture) = let! _ = fixture.SendMessage msgUpdate // assert that the message got auto banned - let! msgBanned = fixture.MessageIsAutoDeleted msgUpdate.Message + let! msgBanned = fixture.MessageIsAutoDeleted msgUpdate.Message.Value Assert.False msgBanned } @@ -65,7 +65,7 @@ type MLBanTests(fixture: VahterTestContainers, _unused: MlAwaitFixture) = let! _ = fixture.SendMessage msgUpdate // assert that the message got auto banned - let! msgBanned = fixture.MessageIsAutoDeleted msgUpdate.Message + let! msgBanned = fixture.MessageIsAutoDeleted msgUpdate.Message.Value Assert.False msgBanned } @@ -76,7 +76,7 @@ type MLBanTests(fixture: VahterTestContainers, _unused: MlAwaitFixture) = let! _ = fixture.SendMessage msgUpdate // assert that the message got auto banned - let! msgBanned = fixture.MessageIsAutoDeleted msgUpdate.Message + let! msgBanned = fixture.MessageIsAutoDeleted msgUpdate.Message.Value Assert.True msgBanned } @@ -88,19 +88,19 @@ type MLBanTests(fixture: VahterTestContainers, _unused: MlAwaitFixture) = let! _ = fixture.SendMessage msgUpdate // assert that the message got auto banned - let! msgBanned = fixture.MessageIsAutoDeleted msgUpdate.Message + let! msgBanned = fixture.MessageIsAutoDeleted msgUpdate.Message.Value Assert.True msgBanned // assert it is not false-positive - let! isFalsePositive = fixture.IsMessageFalsePositive msgUpdate.Message + let! isFalsePositive = fixture.IsMessageFalsePositive msgUpdate.Message.Value Assert.False isFalsePositive // send a callback to mark it as false-positive - let! callbackId = fixture.GetCallbackId msgUpdate.Message "NotASpam" + let! callbackId = fixture.GetCallbackId msgUpdate.Message.Value "NotASpam" let msgCallback = Tg.callback(string callbackId, from = fixture.Vahters[0]) let! _ = fixture.SendMessage msgCallback // assert it is false-positive - let! isFalsePositive = fixture.IsMessageFalsePositive msgUpdate.Message + let! isFalsePositive = fixture.IsMessageFalsePositive msgUpdate.Message.Value Assert.True isFalsePositive } @@ -112,17 +112,17 @@ type MLBanTests(fixture: VahterTestContainers, _unused: MlAwaitFixture) = let! _ = fixture.SendMessage msgUpdate // assert that the message got auto banned - let! msgBanned = fixture.MessageIsAutoDeleted msgUpdate.Message + let! msgBanned = fixture.MessageIsAutoDeleted msgUpdate.Message.Value Assert.True msgBanned // send a callback to mark it as false-positive // we are sending this as a usual user - let! callbackId = fixture.GetCallbackId msgUpdate.Message (nameof CallbackMessage.NotASpam) - let msgCallback = Tg.callback(string callbackId, from = msgUpdate.Message.From) + let! callbackId = fixture.GetCallbackId msgUpdate.Message.Value (nameof CallbackMessage.NotASpam) + let msgCallback = Tg.callback(string callbackId, from = msgUpdate.Message.Value.From.Value) let! _ = fixture.SendMessage msgCallback // assert it is still NOT a false-positive - let! isFalsePositive = fixture.IsMessageFalsePositive msgUpdate.Message + let! isFalsePositive = fixture.IsMessageFalsePositive msgUpdate.Message.Value Assert.False isFalsePositive } @@ -135,22 +135,22 @@ type MLBanTests(fixture: VahterTestContainers, _unused: MlAwaitFixture) = // 1 - no ban let! _ = fixture.SendMessage msgUpdate - let! msgBanned = fixture.MessageBanned msgUpdate.Message + let! msgBanned = fixture.MessageBanned msgUpdate.Message.Value Assert.False msgBanned // 2 - no ban let! _ = fixture.SendMessage msgUpdate - let! msgBanned = fixture.MessageBanned msgUpdate.Message + let! msgBanned = fixture.MessageBanned msgUpdate.Message.Value Assert.False msgBanned // 3 - no ban let! _ = fixture.SendMessage msgUpdate - let! msgBanned = fixture.MessageBanned msgUpdate.Message + let! msgBanned = fixture.MessageBanned msgUpdate.Message.Value Assert.False msgBanned // 4 - ban (depends on the ML_SPAM_AUTOBAN_SCORE_THRESHOLD) let! _ = fixture.SendMessage msgUpdate - let! msgBanned = fixture.MessageBanned msgUpdate.Message + let! msgBanned = fixture.MessageBanned msgUpdate.Message.Value Assert.True msgBanned } @@ -164,27 +164,27 @@ type MLBanTests(fixture: VahterTestContainers, _unused: MlAwaitFixture) = // 1 - no ban let! _ = fixture.SendMessage spam - let! msgBanned = fixture.MessageBanned spam.Message + let! msgBanned = fixture.MessageBanned spam.Message.Value Assert.False msgBanned // 1.5 - no ban let! _ = fixture.SendMessage notSpam - let! msgBanned = fixture.MessageBanned notSpam.Message + let! msgBanned = fixture.MessageBanned notSpam.Message.Value Assert.False msgBanned // 2 - no ban let! _ = fixture.SendMessage spam - let! msgBanned = fixture.MessageBanned spam.Message + let! msgBanned = fixture.MessageBanned spam.Message.Value Assert.False msgBanned // 3 - no ban let! _ = fixture.SendMessage spam - let! msgBanned = fixture.MessageBanned spam.Message + let! msgBanned = fixture.MessageBanned spam.Message.Value Assert.False msgBanned // 4 - no ban (as user posted 1 good message in beetween) let! _ = fixture.SendMessage spam - let! msgBanned = fixture.MessageBanned spam.Message + let! msgBanned = fixture.MessageBanned spam.Message.Value Assert.False msgBanned } @@ -197,30 +197,30 @@ type MLBanTests(fixture: VahterTestContainers, _unused: MlAwaitFixture) = // 1 - no ban let! _ = fixture.SendMessage spam - let! msgBanned = fixture.MessageBanned spam.Message - let! msgDeleted = fixture.MessageIsAutoDeleted spam.Message + let! msgBanned = fixture.MessageBanned spam.Message.Value + let! msgDeleted = fixture.MessageIsAutoDeleted spam.Message.Value Assert.True msgDeleted Assert.False msgBanned // 1.5 - vahter marked as false-positive via button // send a callback to mark it as false-positive - let! callbackId = fixture.GetCallbackId spam.Message "NotASpam" + let! callbackId = fixture.GetCallbackId spam.Message.Value "NotASpam" let msgCallback = Tg.callback(string callbackId, from = fixture.Vahters[0]) let! _ = fixture.SendMessage msgCallback // 2 - no ban let! _ = fixture.SendMessage spam - let! msgBanned = fixture.MessageBanned spam.Message + let! msgBanned = fixture.MessageBanned spam.Message.Value Assert.False msgBanned // 3 - no ban let! _ = fixture.SendMessage spam - let! msgBanned = fixture.MessageBanned spam.Message + let! msgBanned = fixture.MessageBanned spam.Message.Value Assert.False msgBanned // 4 - no ban (as vahter marked this as false positive) let! _ = fixture.SendMessage spam - let! msgBanned = fixture.MessageBanned spam.Message + let! msgBanned = fixture.MessageBanned spam.Message.Value Assert.False msgBanned } @@ -233,7 +233,7 @@ type MLBanTests(fixture: VahterTestContainers, _unused: MlAwaitFixture) = let! _ = fixture.SendMessage msgUpdate // assert that the message got auto banned - let! msgBanned = fixture.MessageIsAutoDeleted msgUpdate.Message + let! msgBanned = fixture.MessageIsAutoDeleted msgUpdate.Message.Value Assert.True msgBanned } @@ -245,7 +245,7 @@ type MLBanTests(fixture: VahterTestContainers, _unused: MlAwaitFixture) = let! _ = fixture.SendMessage msgUpdate // assert that the message got auto banned - let! msgBanned = fixture.MessageIsAutoDeleted msgUpdate.Message + let! msgBanned = fixture.MessageIsAutoDeleted msgUpdate.Message.Value Assert.True msgBanned } diff --git a/src/VahterBanBot.Tests/MessageTests.fs b/src/VahterBanBot.Tests/MessageTests.fs index b85fc08..2164c1f 100644 --- a/src/VahterBanBot.Tests/MessageTests.fs +++ b/src/VahterBanBot.Tests/MessageTests.fs @@ -1,10 +1,9 @@ module VahterBanBot.Tests.MessageTests open System -open System.Net +open Funogram.Telegram.Types open VahterBanBot.Types -open Telegram.Bot.Types -open Telegram.Bot.Types.Enums +open VahterBanBot.Utils open VahterBanBot.Tests.ContainerTestBase open VahterBanBot.Tests.TgMessageUtils open Xunit @@ -16,23 +15,27 @@ type MessageTests(fixture: VahterTestContainers) = let ``All data from the message being saved`` () = task { // record just a message with some additional data let msgUpdate = Tg.quickMsg(chat = fixture.ChatsToMonitor[0]) - msgUpdate.Message.Entities <- [| MessageEntity(Type = MessageEntityType.Code, Offset = 0, Length = 6) |] - msgUpdate.Message.Sticker <- Sticker(Type = StickerType.Mask, Width = 512, Height = 512, FileId = "sticker-id", FileUniqueId = "sticker-uid") + let message = msgUpdate.Message.Value + let msgUpdate = { msgUpdate with Message = Some { message with + Entities = Some [| MessageEntity.Create(``type`` = "code", offset = 0, length = 6) |] + Sticker = Some <| Sticker.Create(``type`` = "mask", width = 512, height = 512, fileId = "sticker-id", fileUniqueId = "sticker-uid", + isAnimated = false, + isVideo = false) } + } let! _ = fixture.SendMessage msgUpdate // assert that the message got recorded correctly - let! dbMsg = fixture.TryGetDbMessage msgUpdate.Message + let! dbMsg = fixture.TryGetDbMessage message Assert.True dbMsg.IsSome - let msg = msgUpdate.Message - let date = DateTimeOffset(msg.Date).ToUnixTimeSeconds() + let date = DateTimeOffset(message.Date).ToUnixTimeSeconds() Assert.Equal( - { chat_id = msgUpdate.Message.Chat.Id - message_id = msgUpdate.Message.MessageId - user_id = msgUpdate.Message.From.Id - text = msgUpdate.Message.Text - raw_message = $"""{{"chat": {{"id": -666, "type": "supergroup", "is_forum": false, "username": "pro.hell"}}, "date": {date}, "from": {{"id": {msg.From.Id}, "is_bot": false, "first_name": "{msg.From.FirstName}", "is_premium": false, "can_join_groups": false, "has_main_web_app": false, "can_connect_to_business": false, "supports_inline_queries": false, "added_to_attachment_menu": false, "can_read_all_group_messages": false}}, "text": "{msg.Text}", "sticker": {{"type": "mask", "width": 512, "height": 512, "file_id": "sticker-id", "is_video": false, "is_animated": false, "file_unique_id": "sticker-uid", "needs_repainting": false}}, "entities": [{{"type": "code", "length": 6, "offset": 0}}], "message_id": {msg.MessageId}, "is_from_offline": false, "is_topic_message": false, "has_media_spoiler": false, "is_automatic_forward": false, "has_protected_content": false, "show_caption_above_media": false}}""" + { chat_id = message.Chat.Id + message_id = message.MessageId32 + user_id = message.FromId + text = message.TextOrEmpty + raw_message = $"""{{"chat": {{"id": -666, "type": "supergroup", "is_forum": false, "username": "pro.hell"}}, "date": {date}, "from": {{"id": {message.FromId}, "is_bot": false, "first_name": "{message.FromFirstName}", "is_premium": false, "can_join_groups": false, "has_main_web_app": false, "can_connect_to_business": false, "supports_inline_queries": false, "added_to_attachment_menu": false, "can_read_all_group_messages": false}}, "text": "{message.TextOrEmpty}", "sticker": {{"type": "mask", "width": 512, "height": 512, "file_id": "sticker-id", "is_video": false, "is_animated": false, "file_unique_id": "sticker-uid", "needs_repainting": false}}, "entities": [{{"type": "code", "length": 6, "offset": 0}}], "message_id": {message.MessageId}, "is_from_offline": false, "is_topic_message": false, "has_media_spoiler": false, "is_automatic_forward": false, "has_protected_content": false, "show_caption_above_media": false}}""" created_at = dbMsg.Value.created_at }, dbMsg.Value ) diff --git a/src/VahterBanBot.Tests/PingTests.fs b/src/VahterBanBot.Tests/PingTests.fs index 4456e0e..40fac5b 100644 --- a/src/VahterBanBot.Tests/PingTests.fs +++ b/src/VahterBanBot.Tests/PingTests.fs @@ -13,7 +13,7 @@ type PingTests(fixture: VahterTestContainers) = let msg = Tg.quickMsg(chat = fixture.ChatsToMonitor[0]) // assert that the message is not in the db - let! dbMsg = fixture.TryGetDbMessage msg.Message + let! dbMsg = fixture.TryGetDbMessage msg.Message.Value Assert.False dbMsg.IsSome // send the message to the bot @@ -21,7 +21,7 @@ type PingTests(fixture: VahterTestContainers) = Assert.Equal(HttpStatusCode.OK, resp.StatusCode) // assert that the message is in the db - let! dbMsg = fixture.TryGetDbMessage msg.Message + let! dbMsg = fixture.TryGetDbMessage msg.Message.Value Assert.True dbMsg.IsSome } @@ -31,7 +31,7 @@ type PingTests(fixture: VahterTestContainers) = let msg = Tg.quickMsg(chat = Tg.chat()) // assert that the message is not in the db - let! dbMsg = fixture.TryGetDbMessage msg.Message + let! dbMsg = fixture.TryGetDbMessage msg.Message.Value Assert.False dbMsg.IsSome // send the message to the bot @@ -39,7 +39,7 @@ type PingTests(fixture: VahterTestContainers) = Assert.Equal(HttpStatusCode.OK, resp.StatusCode) // assert that the message is still not in the db - let! dbMsg = fixture.TryGetDbMessage msg.Message + let! dbMsg = fixture.TryGetDbMessage msg.Message.Value Assert.False dbMsg.IsSome } diff --git a/src/VahterBanBot.Tests/TgMessageUtils.fs b/src/VahterBanBot.Tests/TgMessageUtils.fs index 80d43b3..9141e5f 100644 --- a/src/VahterBanBot.Tests/TgMessageUtils.fs +++ b/src/VahterBanBot.Tests/TgMessageUtils.fs @@ -2,77 +2,74 @@ module VahterBanBot.Tests.TgMessageUtils open System open System.Threading -open Telegram.Bot.Types -open Telegram.Bot.Types.Enums +open Funogram.Telegram.Types type Tg() = static let mutable i = 1L // higher than the data in the test_seed.sql static let nextInt64() = Interlocked.Increment &i static let next() = nextInt64() |> int static member user (?id: int64, ?username: string, ?firstName: string) = - User( - Id = (id |> Option.defaultValue (nextInt64())), - Username = (username |> Option.defaultValue null), - FirstName = (firstName |> Option.defaultWith (fun () -> Guid.NewGuid().ToString())) + User.Create( + id = (id |> Option.defaultValue (nextInt64())), + isBot = false, + username = (username |> Option.defaultValue null), + firstName = (firstName |> Option.defaultWith (fun () -> Guid.NewGuid().ToString())) ) static member chat (?id: int64, ?username: string) = - Chat( - Id = (id |> Option.defaultValue (nextInt64())), - Username = (username |> Option.defaultValue null), - Type = ChatType.Supergroup + Chat.Create( + id = (id |> Option.defaultValue (nextInt64())), + username = (username |> Option.defaultValue null), + ``type`` = ChatType.SuperGroup ) static member callback(data: string, ?from: User) = - Update( - Id = next(), - Message = null, - CallbackQuery = CallbackQuery( - Id = Guid.NewGuid().ToString(), - Data = data, - From = (from |> Option.defaultValue (Tg.user())), - ChatInstance = Guid.NewGuid().ToString() + Update.Create( + updateId = next(), + callbackQuery = CallbackQuery.Create( + id = Guid.NewGuid().ToString(), + data = data, + from = (from |> Option.defaultValue (Tg.user())), + chatInstance = Guid.NewGuid().ToString() ) ) static member quickMsg (?text: string, ?chat: Chat, ?from: User, ?date: DateTime, ?callback: CallbackQuery, ?caption: string, ?editedText: string) = let updateId = next() let msgId = next() - Update( - Id = updateId, - Message = - Message( - MessageId = msgId, - Text = (text |> Option.defaultValue (Guid.NewGuid().ToString())), - Chat = (chat |> Option.defaultValue (Tg.chat())), - From = (from |> Option.defaultValue (Tg.user())), - Date = (date |> Option.defaultValue DateTime.UtcNow), - Caption = (caption |> Option.defaultValue null), - ReplyToMessage = null - ), - EditedMessage = - if editedText |> Option.isSome then - Message( - MessageId = msgId, - Text = editedText.Value, - Chat = (chat |> Option.defaultValue (Tg.chat())), - From = (from |> Option.defaultValue (Tg.user())), - Date = (date |> Option.defaultValue DateTime.UtcNow), - Caption = (caption |> Option.defaultValue null), - ReplyToMessage = null + Update.Create( + updateId, + message = Message.Create( + messageId = msgId, + text = (text |> Option.defaultValue (Guid.NewGuid().ToString())), + chat = (chat |> Option.defaultValue (Tg.chat())), + from = (from |> Option.defaultValue (Tg.user())), + date = (date |> Option.defaultValue DateTime.UtcNow), + caption = (caption |> Option.defaultValue null) + ), + ?editedMessage = ( + editedText |> Option.map (fun editedText -> + Message.Create( + messageId = msgId, + text = editedText, + chat = (chat |> Option.defaultValue (Tg.chat())), + from = (from |> Option.defaultValue (Tg.user())), + date = (date |> Option.defaultValue DateTime.UtcNow), + caption = (caption |> Option.defaultValue null) ) - else null + ) ) + ) static member replyMsg (msg: Message, ?text: string, ?from: User, ?date: DateTime) = - Update( - Id = next(), - Message = - Message( - MessageId = next(), - Text = (text |> Option.defaultValue (Guid.NewGuid().ToString())), - Chat = msg.Chat, - From = (from |> Option.defaultValue (Tg.user())), - Date = (date |> Option.defaultValue DateTime.UtcNow), - ReplyToMessage = msg + Update.Create( + updateId = next(), + message = + Message.Create( + messageId = next(), + text = (text |> Option.defaultValue (Guid.NewGuid().ToString())), + chat = msg.Chat, + from = (from |> Option.defaultValue (Tg.user())), + date = (date |> Option.defaultValue DateTime.UtcNow), + replyToMessage = msg ) )