1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-06-02 16:05:28 +00:00
tgbotapi/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/actions/BotAction.kt

117 lines
3.4 KiB
Kotlin
Raw Normal View History

2018-12-26 08:07:24 +00:00
package com.github.insanusmokrassar.TelegramBotAPI.types.actions
import kotlinx.serialization.*
2020-08-18 06:50:11 +00:00
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
2018-12-26 08:07:24 +00:00
2020-05-11 14:44:03 +00:00
/**
* Use BotAction objects realisations to notify user about bot actions
*/
2018-12-26 08:07:24 +00:00
@Serializable(BotActionSerializer::class)
sealed class BotAction {
abstract val actionName: String
}
@Serializer(BotAction::class)
2019-11-29 06:25:22 +00:00
internal object BotActionSerializer: KSerializer<BotAction> {
2020-03-22 07:37:01 +00:00
override fun serialize(encoder: Encoder, value: BotAction) {
encoder.encodeString(value.actionName)
2018-12-26 08:07:24 +00:00
}
2019-02-21 06:21:33 +00:00
override fun deserialize(decoder: Decoder): BotAction {
2019-11-29 06:25:22 +00:00
return when (val actionName = decoder.decodeString()) {
TypingAction.actionName -> TypingAction
UploadPhotoAction.actionName -> UploadPhotoAction
RecordVideoAction.actionName -> RecordVideoAction
UploadVideoAction.actionName -> UploadVideoAction
RecordAudioAction.actionName -> RecordAudioAction
UploadAudioAction.actionName -> UploadAudioAction
UploadDocumentAction.actionName -> UploadDocumentAction
FindLocationAction.actionName -> FindLocationAction
2020-02-06 17:06:29 +00:00
RecordVideoNoteAction.actionName -> RecordVideoNoteAction
UploadVideoNoteAction.actionName -> UploadVideoNoteAction
2019-11-29 06:25:22 +00:00
else -> throw IllegalStateException("Unknown action type: $actionName")
}
2018-12-26 08:07:24 +00:00
}
}
/**
2020-05-11 14:44:03 +00:00
* Will notify user that bot is "typing" something
2018-12-26 08:07:24 +00:00
*/
@Serializable(BotActionSerializer::class)
object TypingAction : BotAction() {
override val actionName: String = "typing"
}
2020-05-11 14:44:03 +00:00
/**
* Will notify user that bot is uploading some photo
*/
2018-12-26 08:07:24 +00:00
@Serializable(BotActionSerializer::class)
object UploadPhotoAction : BotAction() {
override val actionName: String = "upload_photo"
}
2020-05-11 14:44:03 +00:00
/**
* Will notify user that bot is recording some video
*/
2018-12-26 08:07:24 +00:00
@Serializable(BotActionSerializer::class)
object RecordVideoAction : BotAction() {
override val actionName: String = "record_video"
}
2020-05-11 14:44:03 +00:00
/**
* Will notify user that bot is uploading some photo
*/
2018-12-26 08:07:24 +00:00
@Serializable(BotActionSerializer::class)
object UploadVideoAction : BotAction() {
override val actionName: String = "upload_video"
}
2020-05-11 14:44:03 +00:00
/**
* Will notify user that bot is recording some audio
*/
2018-12-26 08:07:24 +00:00
@Serializable(BotActionSerializer::class)
object RecordAudioAction : BotAction() {
override val actionName: String = "record_audio"
}
2020-05-11 14:44:03 +00:00
/**
* Will notify user that bot is uploading some audio
*/
2018-12-26 08:07:24 +00:00
@Serializable(BotActionSerializer::class)
object UploadAudioAction : BotAction() {
override val actionName: String = "upload_audio"
}
2020-05-11 14:44:03 +00:00
/**
* Will notify user that bot is uploading some document
*/
2018-12-26 08:07:24 +00:00
@Serializable(BotActionSerializer::class)
object UploadDocumentAction : BotAction() {
override val actionName: String = "upload_document"
}
2020-05-11 14:44:03 +00:00
/**
* Will notify user that bot is trying to find location
*/
2018-12-26 08:07:24 +00:00
@Serializable(BotActionSerializer::class)
object FindLocationAction : BotAction() {
override val actionName: String = "find_location"
}
2020-02-06 17:06:29 +00:00
2020-05-11 14:44:03 +00:00
/**
* Will notify user that bot is recording video note
*/
2020-02-06 17:06:29 +00:00
@Serializable(BotActionSerializer::class)
object RecordVideoNoteAction : BotAction() {
override val actionName: String = "record_video_note"
}
2020-05-11 14:44:03 +00:00
/**
* Will notify user that bot is uploading video note
*/
2020-02-06 17:06:29 +00:00
@Serializable(BotActionSerializer::class)
object UploadVideoNoteAction : BotAction() {
override val actionName: String = "upload_video_note"
}