diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt index 872bda30e3..b005d1b9e9 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt @@ -13,8 +13,9 @@ import kotlinx.serialization.json.JsonPrimitive import kotlinx.serialization.json.longOrNull import kotlin.jvm.JvmInline +const val internalTgLinksBeginning = "tg://" const val internalLinkBeginning = "https://t.me" -const val internalUserLinkBeginning = "tg://user?id=" +const val internalUserLinkBeginning = "${internalTgLinksBeginning}user?id=" @Serializable(ChatIdentifierSerializer::class) @ClassCastsIncluded diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index 73fa5dec7b..11e4e6fbe3 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -41,7 +41,10 @@ typealias WebAppQueryId = String @JvmInline value class CustomEmojiId( val string: String -) +) { + val appLink + get() = "${internalTgLinksBeginning}emoji?id=$this" +} typealias Seconds = Int typealias MilliSeconds = Long diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/textsources/CustomEmojiTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/textsources/CustomEmojiTextSource.kt index 01a68e1935..cc958faf5a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/textsources/CustomEmojiTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/textsources/CustomEmojiTextSource.kt @@ -16,8 +16,8 @@ data class CustomEmojiTextSource @RiskFeature(DirectInvocationOfTextSourceConstr override val subsources: TextSourcesList ) : MultilevelTextSource { override val markdown: String by lazy { source.customEmojiMarkdown() } - override val markdownV2: String by lazy { source.customEmojiMarkdownV2() } - override val html: String by lazy { source.customEmojiHTML() } + override val markdownV2: String by lazy { source.customEmojiMarkdownV2(customEmojiId) } + override val html: String by lazy { source.customEmojiHTML(customEmojiId) } } @Suppress("NOTHING_TO_INLINE", "EXPERIMENTAL_API_USAGE") diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/StringFormatting.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/StringFormatting.kt index 6a5ee9091a..ce3a22f25e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/StringFormatting.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/StringFormatting.kt @@ -24,6 +24,7 @@ const val htmlCodeControl = "code" const val htmlPreControl = "pre" const val htmlUnderlineControl = "u" const val htmlStrikethroughControl = "s" +const val htmlCustomEmojiControl = "tg-emoji" private fun String.markdownDefault( openControlSymbol: String, @@ -120,8 +121,8 @@ internal fun String.commandMarkdownV2(): String = command(String::escapeMarkdown internal fun String.commandHTML(): String = command(String::toHtml) internal fun String.customEmojiMarkdown(): String = toMarkdown() -internal fun String.customEmojiMarkdownV2(): String = escapeMarkdownV2Common() -internal fun String.customEmojiHTML(): String = toHtml() +internal fun String.customEmojiMarkdownV2(customEmojiId: CustomEmojiId): String = "!${linkMarkdownV2(customEmojiId.appLink)}" +internal fun String.customEmojiHTML(customEmojiId: CustomEmojiId): String = "<$htmlCustomEmojiControl $htmlCustomEmojiControl=\"${customEmojiId.string}\">$this" internal fun String.regularMarkdown(): String = toMarkdown() internal fun String.regularMarkdownV2(): String = escapeMarkdownV2Common()