mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +00:00
fixes
This commit is contained in:
parent
c04f795fdd
commit
e029b29f7f
@ -19,5 +19,5 @@ suspend fun BehaviourContext.waitDeepLinks(
|
||||
.requireSingleCommand()
|
||||
.requireCommandAtStart()
|
||||
.flattenCommandsWithParams().mapNotNull {
|
||||
it.first to (it.second.second.singleOrNull() ?.regularTextSourceOrNull() ?.source ?: return@mapNotNull null)
|
||||
it.first to (it.second.second.singleOrNull() ?.regularTextSourceOrNull() ?.source ?.removePrefix(" ") ?: return@mapNotNull null)
|
||||
}
|
||||
|
@ -17,9 +17,11 @@ import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||
import dev.inmo.tgbotapi.types.message.content.TextMessage
|
||||
import dev.inmo.tgbotapi.types.message.textsources.RegularTextSource
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
import io.ktor.http.decodeURLQueryComponent
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.filter
|
||||
|
||||
private val startRegex = Regex("start")
|
||||
suspend fun <BC : BehaviourContext> BC.onDeepLink(
|
||||
initialFilter: SimpleFilter<Pair<TextMessage, String>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, Pair<TextMessage, String>, Update> = { (message, _), update -> MessageFilterByChat(this, message, update) },
|
||||
@ -36,6 +38,11 @@ suspend fun <BC : BehaviourContext> BC.onDeepLink(
|
||||
scenarioReceiver,
|
||||
) {
|
||||
(it.messageUpdateOrNull()) ?.data ?.commonMessageOrNull() ?.withContentOrNull<TextContent>() ?.let { message ->
|
||||
message to message.content.textSources[1].source
|
||||
message to message.content.textSources[1].source.removePrefix(" ").decodeURLQueryComponent()
|
||||
} ?.let(::listOfNotNull)
|
||||
}.also {
|
||||
triggersHolder.handleableCommandsHolder.registerHandleable(startRegex)
|
||||
it.invokeOnCompletion {
|
||||
this@onDeepLink.launchSafelyWithoutExceptions { triggersHolder.handleableCommandsHolder.unregisterHandleable(startRegex) }
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.chat.*
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||
import dev.inmo.tgbotapi.types.message.textsources.link
|
||||
import io.ktor.http.encodeURLQueryComponent
|
||||
|
||||
|
||||
fun makeUsernameLink(username: String) = "$internalLinkBeginning/$username"
|
||||
@ -17,11 +18,11 @@ inline val Username.deepLinkPrefix
|
||||
inline val Username.startattachPrefix
|
||||
get() = makeUsernameStartattachPrefix(usernameWithoutAt)
|
||||
inline fun makeLink(username: Username) = username.link
|
||||
inline fun makeTelegramDeepLink(username: String, startParameter: String) = "${makeUsernameDeepLinkPrefix(username)}$startParameter"
|
||||
inline fun makeTelegramDeepLink(username: String, startParameter: String) = "${makeUsernameDeepLinkPrefix(username)}$startParameter".encodeURLQueryComponent()
|
||||
inline fun makeTelegramStartattach(username: String, data: String? = null) = makeUsernameStartattachLink(username, data)
|
||||
inline fun makeDeepLink(username: Username, startParameter: String) = "${username.deepLinkPrefix}$startParameter"
|
||||
inline fun makeDeepLink(username: Username, startParameter: String) = makeTelegramDeepLink(username.usernameWithoutAt, startParameter)
|
||||
inline fun makeTelegramDeepLink(username: Username, startParameter: String) = makeDeepLink(username, startParameter)
|
||||
inline fun makeTelegramStartattach(username: Username, data: String? = null) = makeTelegramStartattach(username.username, data)
|
||||
inline fun makeTelegramStartattach(username: Username, data: String? = null) = makeTelegramStartattach(username.usernameWithoutAt, data)
|
||||
|
||||
fun makeLinkToMessage(
|
||||
username: String,
|
||||
|
Loading…
Reference in New Issue
Block a user