Skip to content

Commit

Permalink
Update to API 7.0 (#66)
Browse files Browse the repository at this point in the history
Update to API 7.0
  • Loading branch information
ForNeVeR authored Jan 3, 2024
1 parent 3a46fb1 commit bb9afb3
Show file tree
Hide file tree
Showing 10 changed files with 3,132 additions and 864 deletions.
1 change: 1 addition & 0 deletions src/Funogram.Generator/Helpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ let typeMap =
"Float number", "float"
"InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove or ForceReply", "Markup"
"array of Messages", "Message[]"
"array of MessageId", "MessageId[]"
"InputMediaAudio, InputMediaDocument, InputMediaPhoto and InputMediaVideo", "InputMedia"
"Message or True", "EditMessageResult"
] |> Map.ofList
Expand Down
6 changes: 5 additions & 1 deletion src/Funogram.Generator/Types/TypesParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ let private splitCaseNameAndType (typeName: string) (nameAndType: string) =
| "InputMessageContent" -> "Input"
| _ -> typeName

try nameAndType.Substring(typeName.Length) with | _ -> "ERROR!"
match typeName, nameAndType with
| "MaybeInaccessibleMessage", "Message" -> "Message"
| "MaybeInaccessibleMessage", "InaccessibleMessage" -> "InaccessibleMessage"
| _ ->
try nameAndType.Substring(typeName.Length) with | _ -> "ERROR!"

let private isValidTypeNode (typeNodeInfo: ApiTypeNodeInfo) =
let name = Helpers.innerText typeNodeInfo.TypeName
Expand Down
567 changes: 318 additions & 249 deletions src/Funogram.Generator/out/methods.json

Large diffs are not rendered by default.

1,949 changes: 1,666 additions & 283 deletions src/Funogram.Generator/out/types.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/Funogram.Telegram/Api.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
module Funogram.Telegram.Api

open Funogram.Telegram
open Funogram.Telegram.Types
open Types

let deleteWebhookBase () =
Expand All @@ -15,7 +16,7 @@ let sendMessageByChatName chatName text = Req.SendMessage.Make(ChatId.String cha

let sendMessageMarkup chatId text replyMarkup = Req.SendMessage.Make(ChatId.Int chatId, text, replyMarkup = replyMarkup)

let sendMessageReply chatId text replyToMessageId = Req.SendMessage.Make(ChatId.Int chatId, text, replyToMessageId = replyToMessageId)
let sendMessageReply chatId text replyToMessageId = Req.SendMessage.Make(ChatId.Int chatId, text, replyParameters = ReplyParameters.Create replyToMessageId)

let forwardMessage chatId fromChatId messageId = Req.ForwardMessage.Make(ChatId.Int chatId, ChatId.Int fromChatId, messageId)

Expand Down
2 changes: 1 addition & 1 deletion src/Funogram.Telegram/Bot.fs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ let private runBot config me updateArrived updatesArrived =
async {
try
let! updatesResult =
Req.GetUpdates.Make(offset, ?limit = config.Limit, ?timeout = config.Timeout)
Req.GetUpdates.Make(offset, ?limit = config.Limit, ?timeout = config.Timeout, ?allowedUpdates = (config.AllowedUpdates |> Option.map Seq.toArray))
|> bot

match updatesResult with
Expand Down
397 changes: 234 additions & 163 deletions src/Funogram.Telegram/RequestsTypes.fs

Large diffs are not rendered by default.

1,049 changes: 890 additions & 159 deletions src/Funogram.Telegram/Types.fs

Large diffs are not rendered by default.

18 changes: 13 additions & 5 deletions src/Funogram.Tests/Constants.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ module Constants =

let testDate = System.DateTime(2117, 05, 28, 12, 47, 51, DateTimeKind.Utc)
let testDateUnix = 4651649271L

let testForwardOrigin = MessageOrigin.HiddenUser(
MessageOriginHiddenUser.Create(
``type`` = "hidden_user",
date = testDate,
senderUserName = "test user"
)
)

let jsonTestObj = { Type = "italic"; Offset = 0L; Length = 100L; Url = Some("http://github.com"); User = None; Language = None; CustomEmojiId = None }
let jsonTestObjString = """{"type":"italic","offset":0,"length":100,"url":"http://github.com"}"""
let jsonTestObjResultString = """{"ok":true,"result":{"type":"italic","offset":0,"length":100,"url":"http://github.com","user":null,"language":null} }"""
Expand All @@ -35,12 +42,13 @@ module Constants =
let testMaskPosition = { MaskPosition.Point = MaskPoint.Eyes; XShift = 0.0; YShift = 0.0; Scale = 0.0 }
let jsonTestMaskPosition = """{"point":"eyes","x_shift":0,"y_shift":0,"scale":0}"""
let jsonTestMaskPositionResult = ok jsonTestMaskPosition


let jsonMessageForwardDate = Message.Create(1L, testDate, jsonTestChat, text = "abc", forwardOrigin = testForwardOrigin)

let jsonMessageForwardDate = Message.Create(1L, testDate, jsonTestChat, text = "abc", forwardDate = testDate)

let jsonMessageForward = Message.Create(1L, testDate, jsonTestChat, forwardDate = testDate, text = "abc")
let jsonMessageForward = Message.Create(1L, testDate, jsonTestChat, forwardOrigin = testForwardOrigin, text = "abc")

let jsonMessageForwardDateString = sprintf """{"message_id":1,"date":%i,"chat":{"id":1,"type":"group","title":"Test group"},"forward_date":%i,"text":"abc"}""" testDateUnix testDateUnix
let jsonMessageForwardDateString = sprintf """{"message_id":1,"date":%i,"chat":{"id":1,"type":"group","title":"Test group"},"forward_origin":{"type":"hidden_user","date":%i,"sender_user_name":"test user"},"text":"abc"}""" testDateUnix testDateUnix
let jsonMessageForwardDateApiString = ok jsonMessageForwardDateString

let paramsDictionary =
Expand Down
4 changes: 2 additions & 2 deletions src/examples/Funogram.TestBot/Commands/TextMessages.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ let testNoWebpageAndNotification config chatId =
ChatId.Int chatId,
"@Dolfik! See http://fsharplang.ru - Russian F# Community",
disableNotification = true,
disableWebPagePreview = true
linkPreviewOptions = LinkPreviewOptions.Create(isDisabled = true)
) |> bot config

let testReply (ctx: UpdateContext) config (chatId: int64) =
Req.SendMessage.Make(
chatId,
"That's message with reply!",
replyToMessageId = ctx.Update.Message.Value.MessageId
replyParameters = ReplyParameters.Create(messageId = ctx.Update.Message.Value.MessageId)
) |> bot config

let testForwardMessage (ctx: UpdateContext) config (chatId: int64) =
Expand Down

0 comments on commit bb9afb3

Please sign in to comment.