This library is your quick Map<K, V>
in the Telegram channel. To try it, your bot needs a channel (name or ID) with
full admin rights.
- Don't change the description—the bot stores the keystore file ID there
- After the first setup, you can't change the dictionary's key/value types
You need Gradle, Maven, or another build tool
Also, you need to add Kotlin serialization plugin, for example, in build.gradle.kts
plugins {
kotlin("plugin.serialization") version "2.1.20-Beta2"
}
import com.github.demidko.telegram.TelegramStorage.Constructors.TelegramStorage
@Serializable data class Person(val name: String, val address: String)
fun main() {
val token = "Bot API token here"
val channel = "Telegram channel name here" // or long id
val storage = TelegramStorage<String, Person>(token, channel)
// saved to Telegram channel
storage["Special Government Employee"] = Person("Elon Musk", "Texas")
// restored Person("Elon Musk", "Texas") from channel
val p = storage["Special Government Employee"]!!
}