mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2026-03-03 17:32:23 +00:00
add drafts flows
This commit is contained in:
@@ -1782,6 +1782,10 @@ public final class dev/inmo/tgbotapi/extensions/api/send/SendMessageDraftKt {
|
||||
public static final fun sendMessageDraft-PjdzSgQ (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ldev/inmo/tgbotapi/types/chat/Chat;JLjava/lang/String;Ldev/inmo/tgbotapi/types/message/ParseMode;Ldev/inmo/tgbotapi/types/MessageThreadId;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public static synthetic fun sendMessageDraft-PjdzSgQ$default (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ldev/inmo/tgbotapi/types/IdChatIdentifier;JLjava/lang/String;Ldev/inmo/tgbotapi/types/message/ParseMode;Ldev/inmo/tgbotapi/types/MessageThreadId;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
|
||||
public static synthetic fun sendMessageDraft-PjdzSgQ$default (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ldev/inmo/tgbotapi/types/chat/Chat;JLjava/lang/String;Ldev/inmo/tgbotapi/types/message/ParseMode;Ldev/inmo/tgbotapi/types/MessageThreadId;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
|
||||
public static final fun sendMessageDraftFlow-85jglgs (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ldev/inmo/tgbotapi/types/IdChatIdentifier;JLkotlinx/coroutines/flow/Flow;Ldev/inmo/tgbotapi/types/MessageThreadId;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public static synthetic fun sendMessageDraftFlow-85jglgs$default (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ldev/inmo/tgbotapi/types/IdChatIdentifier;JLkotlinx/coroutines/flow/Flow;Ldev/inmo/tgbotapi/types/MessageThreadId;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
|
||||
public static final fun sendMessageDraftFlowWithTextAndParseMode (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ldev/inmo/tgbotapi/types/IdChatIdentifier;JLkotlinx/coroutines/flow/Flow;Ldev/inmo/tgbotapi/types/MessageThreadId;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public static synthetic fun sendMessageDraftFlowWithTextAndParseMode$default (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ldev/inmo/tgbotapi/types/IdChatIdentifier;JLkotlinx/coroutines/flow/Flow;Ldev/inmo/tgbotapi/types/MessageThreadId;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
|
||||
}
|
||||
|
||||
public final class dev/inmo/tgbotapi/extensions/api/send/SendMessageKt {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package dev.inmo.tgbotapi.extensions.api.send
|
||||
|
||||
import dev.inmo.kslog.common.logger
|
||||
import dev.inmo.micro_utils.coroutines.runCatchingLogging
|
||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||
import dev.inmo.tgbotapi.requests.send.SendMessageDraft
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
@@ -11,6 +13,14 @@ import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||
import dev.inmo.tgbotapi.types.message.textsources.TextSource
|
||||
import dev.inmo.tgbotapi.utils.EntitiesBuilderBody
|
||||
import dev.inmo.tgbotapi.utils.buildEntities
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.flow.firstOrNull
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.takeWhile
|
||||
import kotlin.js.JsName
|
||||
import kotlin.jvm.JvmName
|
||||
|
||||
public suspend fun TelegramBot.sendMessageDraft(
|
||||
chatId: IdChatIdentifier,
|
||||
@@ -28,6 +38,52 @@ public suspend fun TelegramBot.sendMessageDraft(
|
||||
)
|
||||
)
|
||||
|
||||
private suspend fun TelegramBot.sendMessageDraftFlow(
|
||||
messagesFlow: Flow<SendMessageDraft>,
|
||||
): Boolean {
|
||||
val done = messagesFlow
|
||||
.filter { draft ->
|
||||
val sent = runCatchingLogging(logger = logger) {
|
||||
execute(draft)
|
||||
}.getOrElse {
|
||||
false
|
||||
}
|
||||
|
||||
sent == false
|
||||
}
|
||||
.firstOrNull()
|
||||
|
||||
return done == null
|
||||
}
|
||||
|
||||
public suspend fun TelegramBot.sendMessageDraftFlow(
|
||||
chatId: IdChatIdentifier,
|
||||
draftId: DraftId,
|
||||
messagesFlow: Flow<TextSourcesList>,
|
||||
threadId: MessageThreadId? = chatId.threadId
|
||||
): Boolean {
|
||||
return sendMessageDraftFlow(
|
||||
messagesFlow.map {
|
||||
SendMessageDraft(chatId = chatId, draftId = draftId, entities = it, threadId = threadId)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@JvmName("sendMessageDraftFlowWithTextAndParseMode")
|
||||
@JsName("sendMessageDraftFlowWithTextAndParseMode")
|
||||
public suspend fun TelegramBot.sendMessageDraftFlow(
|
||||
chatId: IdChatIdentifier,
|
||||
draftId: DraftId,
|
||||
messagesFlow: Flow<Pair<String, ParseMode?>>,
|
||||
threadId: MessageThreadId? = chatId.threadId
|
||||
): Boolean {
|
||||
return sendMessageDraftFlow(
|
||||
messagesFlow.map {
|
||||
SendMessageDraft(chatId = chatId, draftId = draftId, text = it.first, parseMode = it.second, threadId = threadId)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
public suspend fun TelegramBot.sendMessageDraft(
|
||||
chat: Chat,
|
||||
draftId: DraftId,
|
||||
|
||||
Reference in New Issue
Block a user