Skip to content

Commit

Permalink
Version 7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Omar Miatello committed Jun 11, 2024
1 parent 43bae5f commit 16a15f5
Show file tree
Hide file tree
Showing 12 changed files with 4,100 additions and 1,382 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# telegram-api-generator
Parse https://core.telegram.org/bots/api page and generate a Kotlin class "DocSection" with "DocType" and "DocMethod"

Last update: Telegram Bot API 7.2
Last update: Telegram Bot API 7.4

Example in:

Expand Down
881 changes: 755 additions & 126 deletions data/telegramapi.html

Large diffs are not rendered by default.

460 changes: 277 additions & 183 deletions example/TelegramClient.kt

Large diffs are not rendered by default.

833 changes: 594 additions & 239 deletions example/TelegramModels.kt

Large diffs are not rendered by default.

837 changes: 611 additions & 226 deletions example/TelegramModels.rs

Large diffs are not rendered by default.

737 changes: 498 additions & 239 deletions example/TelegramModelsOnly.kt

Large diffs are not rendered by default.

988 changes: 859 additions & 129 deletions example/telegram.json

Large diffs are not rendered by default.

140 changes: 92 additions & 48 deletions example/telegram.md

Large diffs are not rendered by default.

483 changes: 331 additions & 152 deletions example/telegram_full.md

Large diffs are not rendered by default.

83 changes: 47 additions & 36 deletions example/telegram_tiny.md

Large diffs are not rendered by default.

22 changes: 19 additions & 3 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@ fun main() = runBlocking {
HttpClient(CIO).get("https://core.telegram.org/bots/api").bodyAsText()
.also { File("data/telegramapi.html").writeText(it) }
).toSection()

val docsRequiredFirst = docs.map { doc ->
doc.copy(
docTypes = doc.docTypes.map { type ->
type.copy(
docFields = type.docFields.sortedByDescending { it.required }
)
},
docMethods = doc.docMethods.map { method ->
method.copy(
docParameters = method.docParameters.sortedByDescending { it.required }
)
}
)
}

val version = "Bot API ([\\d.]+)".toRegex().find(File("data/telegramapi.html").readText())?.value

println("👓 $version - Parse completed")
Expand All @@ -31,9 +47,9 @@ fun main() = runBlocking {
File("example/telegram_tiny.md").writeText(docs.toReadmeTinyExample())
File("example/telegram_full.md").writeText(docs.toReadmeFullExample())
File("example/telegram.json").writeText(docs.toJson())
File("example/TelegramModelsOnly.kt").writeText(docs.toKotlinModels(useKotlinXSerialization = false))
File("example/TelegramModels.kt").writeText(docs.toKotlinModels(useKotlinXSerialization = true))
File("example/TelegramClient.kt").writeText(docs.toKotlinMethods())
File("example/TelegramModelsOnly.kt").writeText(docsRequiredFirst.toKotlinModels(useKotlinXSerialization = false))
File("example/TelegramModels.kt").writeText(docsRequiredFirst.toKotlinModels(useKotlinXSerialization = true))
File("example/TelegramClient.kt").writeText(docsRequiredFirst.toKotlinMethods())
File("example/TelegramModels.rs").writeText(docs.toRustModels())

println("🎉 $version - Examples generated!")
Expand Down
16 changes: 16 additions & 0 deletions src/main/kotlin/TelegramType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ sealed class TelegramType(val name: String, val superType: TelegramType? = findS
deserializer = ""
)

object BackgroundFill : Super(
name = "BackgroundFill",
subclasses = { it.startsWith("BackgroundFill") },
deserializer = ""
)

object BackgroundType : Super(
name = "BackgroundType",
subclasses = { it.startsWith("BackgroundType") },
deserializer = ""
)

object KeyboardOption : Super(
name = "KeyboardOption",
subclasses = { it in listOf("InlineKeyboardMarkup", "ReplyKeyboardMarkup", "ReplyKeyboardRemove", "ForceReply") },
Expand Down Expand Up @@ -149,6 +161,8 @@ sealed class TelegramType(val name: String, val superType: TelegramType? = findS
Super.MessageOrigin,
Super.ChatBoostSource,
Super.MenuButton,
Super.BackgroundFill,
Super.BackgroundType,
Super.KeyboardOption,
Super.MaybeInaccessibleMessage,
WithAlternative.InputFileOrString,
Expand Down Expand Up @@ -184,6 +198,8 @@ sealed class TelegramType(val name: String, val superType: TelegramType? = findS
"PassportElementError" -> Super.PassportElementError
"ChatMember" -> Super.ChatMember
"MenuButton" -> Super.MenuButton
"BackgroundFill" -> Super.BackgroundFill
"BackgroundType" -> Super.BackgroundType
"BotCommandScope" -> Super.BotCommandScope
"KeyboardOption" -> Super.KeyboardOption
"MaybeInaccessibleMessage" -> Super.MaybeInaccessibleMessage
Expand Down

0 comments on commit 16a15f5

Please sign in to comment.