diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendAction.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendAction.kt index d7ad4ec7cc..2f876bdacd 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendAction.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendAction.kt @@ -3,104 +3,129 @@ package dev.inmo.tgbotapi.extensions.api.send import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.send.SendAction import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.MessageThreadId import dev.inmo.tgbotapi.types.actions.* import dev.inmo.tgbotapi.types.chat.Chat +import dev.inmo.tgbotapi.types.threadId suspend fun TelegramBot.sendBotAction( chatId: ChatIdentifier, - action: BotAction + action: BotAction, + threadId: MessageThreadId? = chatId.threadId ) = execute( - SendAction(chatId, action) + SendAction(chatId, action, threadId) ) suspend fun TelegramBot.sendBotAction( chat: Chat, - action: BotAction -) = sendBotAction(chat.id, action) + action: BotAction, + threadId: MessageThreadId? = chat.id.threadId +) = sendBotAction(chat.id, action, threadId) suspend fun TelegramBot.sendActionTyping( - chatId: ChatIdentifier -) = sendBotAction(chatId, TypingAction) + chatId: ChatIdentifier, + threadId: MessageThreadId? = chatId.threadId +) = sendBotAction(chatId, TypingAction, threadId) suspend fun TelegramBot.sendActionUploadPhoto( - chatId: ChatIdentifier -) = sendBotAction(chatId, UploadPhotoAction) + chatId: ChatIdentifier, + threadId: MessageThreadId? = chatId.threadId +) = sendBotAction(chatId, UploadPhotoAction, threadId) suspend fun TelegramBot.sendActionRecordVideo( - chatId: ChatIdentifier -) = sendBotAction(chatId, RecordVideoAction) + chatId: ChatIdentifier, + threadId: MessageThreadId? = chatId.threadId +) = sendBotAction(chatId, RecordVideoAction, threadId) suspend fun TelegramBot.sendActionUploadVideo( - chatId: ChatIdentifier -) = sendBotAction(chatId, UploadVideoAction) + chatId: ChatIdentifier, + threadId: MessageThreadId? = chatId.threadId +) = sendBotAction(chatId, UploadVideoAction, threadId) suspend fun TelegramBot.sendActionRecordVoice( - chatId: ChatIdentifier -) = sendBotAction(chatId, RecordVoiceAction) + chatId: ChatIdentifier, + threadId: MessageThreadId? = chatId.threadId +) = sendBotAction(chatId, RecordVoiceAction, threadId) suspend fun TelegramBot.sendActionUploadVoice( - chatId: ChatIdentifier -) = sendBotAction(chatId, UploadVoiceAction) + chatId: ChatIdentifier, + threadId: MessageThreadId? = chatId.threadId +) = sendBotAction(chatId, UploadVoiceAction, threadId) suspend fun TelegramBot.sendActionUploadDocument( - chatId: ChatIdentifier -) = sendBotAction(chatId, UploadDocumentAction) + chatId: ChatIdentifier, + threadId: MessageThreadId? = chatId.threadId +) = sendBotAction(chatId, UploadDocumentAction, threadId) suspend fun TelegramBot.sendActionFindLocation( - chatId: ChatIdentifier -) = sendBotAction(chatId, FindLocationAction) + chatId: ChatIdentifier, + threadId: MessageThreadId? = chatId.threadId +) = sendBotAction(chatId, FindLocationAction, threadId) suspend fun TelegramBot.sendActionRecordVideoNote( - chatId: ChatIdentifier -) = sendBotAction(chatId, RecordVideoNoteAction) + chatId: ChatIdentifier, + threadId: MessageThreadId? = chatId.threadId +) = sendBotAction(chatId, RecordVideoNoteAction, threadId) suspend fun TelegramBot.sendActionUploadVideoNote( - chatId: ChatIdentifier -) = sendBotAction(chatId, UploadVideoNoteAction) + chatId: ChatIdentifier, + threadId: MessageThreadId? = chatId.threadId +) = sendBotAction(chatId, UploadVideoNoteAction, threadId) suspend fun TelegramBot.sendActionTyping( - chat: Chat -) = sendBotAction(chat, TypingAction) + chat: Chat, + threadId: MessageThreadId? = chat.id.threadId +) = sendBotAction(chat, TypingAction, threadId) suspend fun TelegramBot.sendActionUploadPhoto( - chat: Chat -) = sendBotAction(chat, UploadPhotoAction) + chat: Chat, + threadId: MessageThreadId? = chat.id.threadId +) = sendBotAction(chat, UploadPhotoAction, threadId) suspend fun TelegramBot.sendActionRecordVideo( - chat: Chat -) = sendBotAction(chat, RecordVideoAction) + chat: Chat, + threadId: MessageThreadId? = chat.id.threadId +) = sendBotAction(chat, RecordVideoAction, threadId) suspend fun TelegramBot.sendActionUploadVideo( - chat: Chat -) = sendBotAction(chat, UploadVideoAction) + chat: Chat, + threadId: MessageThreadId? = chat.id.threadId +) = sendBotAction(chat, UploadVideoAction, threadId) suspend fun TelegramBot.sendActionRecordVoice( - chat: Chat -) = sendBotAction(chat, RecordVoiceAction) + chat: Chat, + threadId: MessageThreadId? = chat.id.threadId +) = sendBotAction(chat, RecordVoiceAction, threadId) suspend fun TelegramBot.sendActionUploadVoice( - chat: Chat -) = sendBotAction(chat, UploadVoiceAction) + chat: Chat, + threadId: MessageThreadId? = chat.id.threadId +) = sendBotAction(chat, UploadVoiceAction, threadId) suspend fun TelegramBot.sendActionUploadDocument( - chat: Chat -) = sendBotAction(chat, UploadDocumentAction) + chat: Chat, + threadId: MessageThreadId? = chat.id.threadId +) = sendBotAction(chat, UploadDocumentAction, threadId) suspend fun TelegramBot.sendActionFindLocation( - chat: Chat -) = sendBotAction(chat, FindLocationAction) + chat: Chat, + threadId: MessageThreadId? = chat.id.threadId +) = sendBotAction(chat, FindLocationAction, threadId) suspend fun TelegramBot.sendActionRecordVideoNote( - chat: Chat -) = sendBotAction(chat, RecordVideoNoteAction) + chat: Chat, + threadId: MessageThreadId? = chat.id.threadId +) = sendBotAction(chat, RecordVideoNoteAction, threadId) suspend fun TelegramBot.sendActionUploadVideoNote( - chat: Chat -) = sendBotAction(chat, UploadVideoNoteAction) + chat: Chat, + threadId: MessageThreadId? = chat.id.threadId +) = sendBotAction(chat, UploadVideoNoteAction, threadId) suspend fun TelegramBot.sendActionChooseStickerAction( - chat: Chat -) = sendBotAction(chat, ChooseStickerAction) + chat: Chat, + threadId: MessageThreadId? = chat.id.threadId +) = sendBotAction(chat, ChooseStickerAction, threadId) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendActionDSL.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendActionDSL.kt index 3a9db0be3a..c182898837 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendActionDSL.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendActionDSL.kt @@ -38,13 +38,14 @@ suspend fun TelegramBot.withAction( suspend fun TelegramBot.withAction( chatId: IdChatIdentifier, action: BotAction, + threadId: MessageThreadId? = chatId.threadId, block: TelegramBotActionCallback ): T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } return withAction( - SendAction(chatId, action), + SendAction(chatId, action, threadId), block ) } @@ -53,6 +54,7 @@ suspend fun TelegramBot.withAction( suspend fun TelegramBot.withAction( chat: Chat, action: BotAction, + threadId: MessageThreadId? = chat.id.threadId, block: TelegramBotActionCallback ): T { contract { @@ -61,163 +63,164 @@ suspend fun TelegramBot.withAction( return withAction( chat.id, action, + threadId, block ) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withTypingAction(chatId: IdChatIdentifier, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withTypingAction(chatId: IdChatIdentifier, threadId: MessageThreadId? = chatId.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chatId, TypingAction, block) + return withAction(chatId, TypingAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withUploadPhotoAction(chatId: IdChatIdentifier, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withUploadPhotoAction(chatId: IdChatIdentifier, threadId: MessageThreadId? = chatId.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chatId, UploadPhotoAction, block) + return withAction(chatId, UploadPhotoAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withRecordVideoAction(chatId: IdChatIdentifier, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withRecordVideoAction(chatId: IdChatIdentifier, threadId: MessageThreadId? = chatId.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chatId, RecordVideoAction, block) + return withAction(chatId, RecordVideoAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withUploadVideoAction(chatId: IdChatIdentifier, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withUploadVideoAction(chatId: IdChatIdentifier, threadId: MessageThreadId? = chatId.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chatId, UploadVideoAction, block) + return withAction(chatId, UploadVideoAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withRecordVoiceAction(chatId: IdChatIdentifier, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withRecordVoiceAction(chatId: IdChatIdentifier, threadId: MessageThreadId? = chatId.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chatId, RecordVoiceAction, block) + return withAction(chatId, RecordVoiceAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withUploadVoiceAction(chatId: IdChatIdentifier, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withUploadVoiceAction(chatId: IdChatIdentifier, threadId: MessageThreadId? = chatId.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chatId, UploadVoiceAction, block) + return withAction(chatId, UploadVoiceAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withUploadDocumentAction(chatId: IdChatIdentifier, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withUploadDocumentAction(chatId: IdChatIdentifier, threadId: MessageThreadId? = chatId.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chatId, UploadDocumentAction, block) + return withAction(chatId, UploadDocumentAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withFindLocationAction(chatId: IdChatIdentifier, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withFindLocationAction(chatId: IdChatIdentifier, threadId: MessageThreadId? = chatId.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chatId, FindLocationAction, block) + return withAction(chatId, FindLocationAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withRecordVideoNoteAction(chatId: IdChatIdentifier, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withRecordVideoNoteAction(chatId: IdChatIdentifier, threadId: MessageThreadId? = chatId.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chatId, RecordVideoNoteAction, block) + return withAction(chatId, RecordVideoNoteAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withUploadVideoNoteAction(chatId: IdChatIdentifier, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withUploadVideoNoteAction(chatId: IdChatIdentifier, threadId: MessageThreadId? = chatId.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chatId, UploadVideoNoteAction, block) + return withAction(chatId, UploadVideoNoteAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withChooseStickerAction(chatId: IdChatIdentifier, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withChooseStickerAction(chatId: IdChatIdentifier, threadId: MessageThreadId? = chatId.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chatId, ChooseStickerAction, block) + return withAction(chatId, ChooseStickerAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withTypingAction(chat: Chat, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withTypingAction(chat: Chat, threadId: MessageThreadId? = chat.id.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chat, TypingAction, block) + return withAction(chat, TypingAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withUploadPhotoAction(chat: Chat, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withUploadPhotoAction(chat: Chat, threadId: MessageThreadId? = chat.id.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chat, UploadPhotoAction, block) + return withAction(chat, UploadPhotoAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withRecordVideoAction(chat: Chat, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withRecordVideoAction(chat: Chat, threadId: MessageThreadId? = chat.id.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chat, RecordVideoAction, block) + return withAction(chat, RecordVideoAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withUploadVideoAction(chat: Chat, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withUploadVideoAction(chat: Chat, threadId: MessageThreadId? = chat.id.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chat, UploadVideoAction, block) + return withAction(chat, UploadVideoAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withRecordVoiceAction(chat: Chat, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withRecordVoiceAction(chat: Chat, threadId: MessageThreadId? = chat.id.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chat, RecordVoiceAction, block) + return withAction(chat, RecordVoiceAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withUploadVoiceAction(chat: Chat, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withUploadVoiceAction(chat: Chat, threadId: MessageThreadId? = chat.id.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chat, UploadVoiceAction, block) + return withAction(chat, UploadVoiceAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withUploadDocumentAction(chat: Chat, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withUploadDocumentAction(chat: Chat, threadId: MessageThreadId? = chat.id.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chat, UploadDocumentAction, block) + return withAction(chat, UploadDocumentAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withFindLocationAction(chat: Chat, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withFindLocationAction(chat: Chat, threadId: MessageThreadId? = chat.id.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chat, FindLocationAction, block) + return withAction(chat, FindLocationAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withRecordVideoNoteAction(chat: Chat, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withRecordVideoNoteAction(chat: Chat, threadId: MessageThreadId? = chat.id.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chat, RecordVideoNoteAction, block) + return withAction(chat, RecordVideoNoteAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withUploadVideoNoteAction(chat: Chat, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withUploadVideoNoteAction(chat: Chat, threadId: MessageThreadId? = chat.id.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chat, UploadVideoNoteAction, block) + return withAction(chat, UploadVideoNoteAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withChooseStickerAction(chat: Chat, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withChooseStickerAction(chat: Chat, threadId: MessageThreadId? = chat.id.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chat, ChooseStickerAction, block) + return withAction(chat, ChooseStickerAction, threadId, block) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendAction.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendAction.kt index 5b9e3396da..6a5762dd31 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendAction.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendAction.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.requests.send +import dev.inmo.tgbotapi.requests.send.abstracts.OptionallyMessageThreadRequest import dev.inmo.tgbotapi.requests.send.abstracts.SendChatMessageRequest import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.actions.BotAction @@ -14,8 +15,10 @@ data class SendAction( @SerialName(chatIdField) override val chatId: ChatIdentifier, @SerialName(actionField) - val action: BotAction -): SendChatMessageRequest { + val action: BotAction, + @SerialName(messageThreadIdField) + override val threadId: MessageThreadId? = chatId.threadId +): SendChatMessageRequest, OptionallyMessageThreadRequest { override fun method(): String = "sendChatAction" override val resultDeserializer: DeserializationStrategy get() = Boolean.serializer()