Skip to content

Latest commit

 

History

History
44 lines (30 loc) · 1.27 KB

README.md

File metadata and controls

44 lines (30 loc) · 1.27 KB

Telegram Storage

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.

Warnings

  • 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

Download

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"
}

Usage example

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"]!!
}