mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2026-08-16 22:26:26 +00:00
tmp improvements
This commit is contained in:
@@ -20,17 +20,28 @@ import dev.inmo.tgbotapi.extensions.utils.contentMessageOrNull
|
||||
import dev.inmo.tgbotapi.extensions.utils.onlyRichMessageContentMessages
|
||||
import dev.inmo.tgbotapi.extensions.utils.withContentOrNull
|
||||
import dev.inmo.tgbotapi.requests.edit.text.EditChatMessageRichText
|
||||
import dev.inmo.tgbotapi.requests.abstracts.InputFile
|
||||
import dev.inmo.tgbotapi.types.BotCommand
|
||||
import dev.inmo.tgbotapi.types.CustomEmojiId
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.InlineQueryResultArticle
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputRichMessageContent
|
||||
import dev.inmo.tgbotapi.types.InlineQueryId
|
||||
import dev.inmo.tgbotapi.types.TelegramDate
|
||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||
import dev.inmo.tgbotapi.types.message.textsources.BotCommandTextSource
|
||||
import dev.inmo.tgbotapi.types.media.TelegramMediaAnimation
|
||||
import dev.inmo.tgbotapi.types.media.TelegramMediaAudio
|
||||
import dev.inmo.tgbotapi.types.media.TelegramMediaPhoto
|
||||
import dev.inmo.tgbotapi.types.media.TelegramMediaVideo
|
||||
import dev.inmo.tgbotapi.types.media.TelegramMediaVoiceNote
|
||||
import dev.inmo.tgbotapi.types.rich.InputRichMessageBlocks
|
||||
import dev.inmo.tgbotapi.types.rich.InputRichMessageHTML
|
||||
import dev.inmo.tgbotapi.types.rich.InputRichMessageMarkdown
|
||||
import dev.inmo.tgbotapi.types.rich.InputRichMessageMedia
|
||||
import dev.inmo.tgbotapi.types.rich.RichBlockCaption
|
||||
import dev.inmo.tgbotapi.types.rich.RichBlockTableCell
|
||||
import dev.inmo.tgbotapi.types.rich.RichTextPlain
|
||||
import dev.inmo.tgbotapi.types.rich.buildRichText
|
||||
import dev.inmo.tgbotapi.types.toChatId
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -298,6 +309,250 @@ suspend fun main(vararg args: String) {
|
||||
|
||||
</details>
|
||||
""".trimIndent()
|
||||
val testMarkdownMediaLessInputRichMessageBlocks = InputRichMessageBlocks {
|
||||
paragraph {
|
||||
bold("bold text")
|
||||
plain("\n")
|
||||
bold("bold text")
|
||||
plain("\n")
|
||||
italic("italic text")
|
||||
plain("\n")
|
||||
italic("italic text")
|
||||
plain("\n")
|
||||
strikethrough("strikethrough text")
|
||||
plain("\n")
|
||||
code("inline fixed-width code")
|
||||
plain("\n")
|
||||
marked("marked text")
|
||||
plain("\n")
|
||||
spoiler("spoiler")
|
||||
}
|
||||
paragraph {
|
||||
url("inline URL", "https://t.me/")
|
||||
plain("\n")
|
||||
email("inline e-mail", "user@example.com")
|
||||
plain("\n")
|
||||
phone("inline phone number", "+123456789")
|
||||
plain("\n")
|
||||
url("inline mention of a user", "tg://user?id=123456789")
|
||||
plain("\n")
|
||||
customEmoji(CustomEmojiId("5368324170671202286"), "👍")
|
||||
plain("\n")
|
||||
dateTime("22:45 tomorrow", TelegramDate(1647531900L), "wDT")
|
||||
plain("\n")
|
||||
mathematicalExpression("x^2 + y^2")
|
||||
plain("\n#hashtag ${'$'}USD +12345678901, card: 4242 4242 4242 4242, https://t.me t.me a@t.me /command @username\n")
|
||||
plain("all the text above was on the same line")
|
||||
}
|
||||
|
||||
h1("Heading 1")
|
||||
h2("Heading 2")
|
||||
h3("Heading 3")
|
||||
h4("Heading 4")
|
||||
h5("Heading 5")
|
||||
h6("Heading 6")
|
||||
paragraph("Paragraph text")
|
||||
preformatted(
|
||||
" print('pre-formatted fixed-width code block written in the Python programming language')",
|
||||
language = "python"
|
||||
)
|
||||
divider()
|
||||
|
||||
unorderedList {
|
||||
item("unordered list item")
|
||||
item("unordered list item")
|
||||
item("unordered list item")
|
||||
}
|
||||
orderedList {
|
||||
item(1) { paragraph("ordered list item") }
|
||||
item(2) { paragraph("ordered list item") }
|
||||
}
|
||||
unorderedList {
|
||||
item(hasCheckbox = true, isChecked = false) { paragraph("task list item") }
|
||||
item(hasCheckbox = true, isChecked = true) { paragraph("completed task list item") }
|
||||
}
|
||||
blockQuotation {
|
||||
paragraph("Block quotation started\nBlock quotation continued on the next line\nBlock quotation continued on the same line\nThe last line of the block quotation")
|
||||
}
|
||||
|
||||
table(
|
||||
listOf(
|
||||
listOf(
|
||||
RichBlockTableCell(RichTextPlain("Header 1"), isHeader = true, align = "left", valign = "middle"),
|
||||
RichBlockTableCell(RichTextPlain("Header 2"), isHeader = true, align = "center", valign = "middle")
|
||||
),
|
||||
listOf(
|
||||
RichBlockTableCell(RichTextPlain("left"), align = "left", valign = "middle"),
|
||||
RichBlockTableCell(RichTextPlain("center"), align = "center", valign = "middle")
|
||||
)
|
||||
)
|
||||
)
|
||||
paragraph {
|
||||
plain("Text with a reference")
|
||||
referenceLink("id1", "id1")
|
||||
plain(" and another one")
|
||||
referenceLink("id2", "id2")
|
||||
plain(".")
|
||||
}
|
||||
paragraph { reference("Definition of the first footnote.", "id1") }
|
||||
paragraph { reference("Definition of the second footnote.", "id2") }
|
||||
mathematicalExpression("E = mc^2")
|
||||
preformatted("E = mc^2", language = "math")
|
||||
|
||||
h2 {
|
||||
plain("Example Nested Syntax Report for ")
|
||||
italic("Q1")
|
||||
}
|
||||
paragraph {
|
||||
plain("Intro with ")
|
||||
underline("underlined text")
|
||||
plain(", ")
|
||||
marked("marked text")
|
||||
plain(", and ")
|
||||
mathematicalExpression("x^2 + y^2")
|
||||
plain(".")
|
||||
}
|
||||
paragraph {
|
||||
bold {
|
||||
plain("Bold ")
|
||||
italic {
|
||||
plain("italic ")
|
||||
underline("underlined italic bold")
|
||||
plain(" italic")
|
||||
}
|
||||
plain(" bold")
|
||||
}
|
||||
}
|
||||
paragraph {
|
||||
underline {
|
||||
plain("In inline tags, nested ")
|
||||
bold("markdown")
|
||||
plain(" is parsed")
|
||||
}
|
||||
}
|
||||
blockQuotation {
|
||||
paragraph {
|
||||
plain("Quote with ")
|
||||
bold {
|
||||
plain("bold text, ")
|
||||
strikethrough {
|
||||
plain("strikethrough, and ")
|
||||
spoiler("spoiler")
|
||||
}
|
||||
}
|
||||
plain(", plus ")
|
||||
url("a link", "https://t.me/")
|
||||
plain(".")
|
||||
}
|
||||
}
|
||||
unorderedList {
|
||||
item {
|
||||
paragraph {
|
||||
plain("List item with ")
|
||||
code("code")
|
||||
plain(", ")
|
||||
superscript("superscript")
|
||||
plain(", ")
|
||||
subscript("subscript")
|
||||
plain(", and a footnote")
|
||||
referenceLink("note", "note")
|
||||
}
|
||||
}
|
||||
item {
|
||||
paragraph {
|
||||
plain("Another item with ")
|
||||
bold { spoiler { code("spoiler code") } }
|
||||
}
|
||||
}
|
||||
item {
|
||||
paragraph {
|
||||
plain("Another item with ")
|
||||
strikethrough {
|
||||
plain("strikethrough and ")
|
||||
underline("inserted text")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
table(
|
||||
listOf(
|
||||
listOf(
|
||||
RichBlockTableCell(RichTextPlain("Metric"), isHeader = true, align = "left", valign = "middle"),
|
||||
RichBlockTableCell(RichTextPlain("Value"), isHeader = true, align = "right", valign = "middle")
|
||||
),
|
||||
listOf(
|
||||
RichBlockTableCell(RichTextPlain("Speed"), align = "left", valign = "middle"),
|
||||
RichBlockTableCell(buildRichText { bold("42"); plain(" "); superscript("ms") }, align = "right", valign = "middle")
|
||||
),
|
||||
listOf(
|
||||
RichBlockTableCell(RichTextPlain("Status"), align = "left", valign = "middle"),
|
||||
RichBlockTableCell(buildRichText { spoiler("ready") }, align = "right", valign = "middle")
|
||||
)
|
||||
)
|
||||
)
|
||||
paragraph {
|
||||
reference("note") {
|
||||
plain("Footnote with ")
|
||||
italic("italic text")
|
||||
plain(" and ")
|
||||
underline("HTML underline")
|
||||
plain(".")
|
||||
}
|
||||
}
|
||||
divider()
|
||||
h1("Details blocks can contain Markdown content:")
|
||||
details(
|
||||
summary = buildRichText {
|
||||
plain("Summary with ")
|
||||
bold("bold text")
|
||||
},
|
||||
isOpen = true
|
||||
) {
|
||||
h3("Details heading")
|
||||
unorderedList {
|
||||
item { paragraph { plain("List item with "); italic("italic text") } }
|
||||
item { paragraph { plain("List item with "); spoiler("spoiler") } }
|
||||
}
|
||||
}
|
||||
}
|
||||
val testMarkdownInputRichMessageBlocks = InputRichMessageBlocks {
|
||||
testMarkdownMediaLessInputRichMessageBlocks.blocks.orEmpty().forEach(::add)
|
||||
|
||||
val photo = TelegramMediaPhoto(InputFile.fromUrl("https://telegram.org/example/photo.jpg"))
|
||||
val video = TelegramMediaVideo(InputFile.fromUrl("https://telegram.org/example/video.mp4"))
|
||||
val audio = TelegramMediaAudio(InputFile.fromUrl("https://telegram.org/example/audio.mp3"))
|
||||
val voiceNote = TelegramMediaVoiceNote(InputFile.fromUrl("https://telegram.org/example/audio.ogg"))
|
||||
val animation = TelegramMediaAnimation(InputFile.fromUrl("https://telegram.org/example/animation.gif"))
|
||||
|
||||
photo(photo)
|
||||
video(video)
|
||||
audio(audio)
|
||||
voiceNote(voiceNote)
|
||||
animation(animation)
|
||||
|
||||
photo(photo, RichBlockCaption(RichTextPlain("Photo caption")))
|
||||
video(video, RichBlockCaption(RichTextPlain("Video caption")))
|
||||
audio(audio, RichBlockCaption(RichTextPlain("Audio caption")))
|
||||
voiceNote(voiceNote, RichBlockCaption(RichTextPlain("Voice note caption")))
|
||||
animation(animation, RichBlockCaption(RichTextPlain("Animation caption")))
|
||||
|
||||
collage {
|
||||
photo(photo)
|
||||
video(video)
|
||||
}
|
||||
collage(RichBlockCaption(RichTextPlain("Collage caption"))) {
|
||||
video(video)
|
||||
photo(photo)
|
||||
}
|
||||
slideshow {
|
||||
photo(photo)
|
||||
video(video)
|
||||
}
|
||||
slideshow(RichBlockCaption(RichTextPlain("Slideshow caption"))) {
|
||||
video(video)
|
||||
photo(photo)
|
||||
}
|
||||
}
|
||||
|
||||
telegramBotWithBehaviourAndLongPolling(
|
||||
botToken,
|
||||
@@ -404,10 +659,7 @@ suspend fun main(vararg args: String) {
|
||||
onCommand("rich_markdown") {
|
||||
val sent = sendRichMessage(
|
||||
it.chat.id,
|
||||
// InputRichMessageMarkdown factory — content described using Markdown formatting
|
||||
InputRichMessageMarkdown(
|
||||
testMarkdownText
|
||||
)
|
||||
testMarkdownInputRichMessageBlocks
|
||||
)
|
||||
println(sent)
|
||||
}
|
||||
@@ -416,10 +668,7 @@ suspend fun main(vararg args: String) {
|
||||
onCommand("rich_markdown_medialess") {
|
||||
val sent = sendRichMessage(
|
||||
it.chat.id,
|
||||
// InputRichMessageMarkdown factory — content described using Markdown formatting
|
||||
InputRichMessageMarkdown(
|
||||
testMarkdownMediaLessText
|
||||
)
|
||||
testMarkdownMediaLessInputRichMessageBlocks
|
||||
)
|
||||
println(sent)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user