DeviceStorage

external interface DeviceStorage

This object is used to access the device's local storage.

See https://core.telegram.org/bots/webapps#devicestorage for more information.

Functions

Link copied to clipboard
abstract fun clear(callback: (DeviceStorageErrorMessage?, Boolean?) -> Unit): DeviceStorage

Clears all key-value pairs from the storage.

Link copied to clipboard
suspend fun DeviceStorage.clear(): Boolean

Clears all key-value pairs from the storage. This function suspends until the result is available and returns the result directly or throws an exception if an error occurred.

Link copied to clipboard

Clears all key-value pairs from the storage. This function uses a CompletableDeferred to handle the asynchronous callback and returns a Result object.

Link copied to clipboard
abstract fun getItem(key: String, callback: (DeviceStorageErrorMessage?, String?) -> Unit): DeviceStorage

Retrieves the value associated with a key.

Link copied to clipboard
suspend fun DeviceStorage.getItem(key: String): String?

Retrieves the value associated with a key. This function suspends until the result is available and returns the result directly or throws an exception if an error occurred.

Link copied to clipboard

Retrieves the value associated with a key. This function uses a CompletableDeferred to handle the asynchronous callback and returns a Result object.

Link copied to clipboard
abstract fun removeItem(key: String, callback: (DeviceStorageErrorMessage?, Boolean?) -> Unit): DeviceStorage

Removes the key-value pair associated with a key.

Link copied to clipboard

Removes the key-value pair associated with a key. This function suspends until the result is available and returns the result directly or throws an exception if an error occurred.

Link copied to clipboard

Removes the key-value pair associated with a key. This function uses a CompletableDeferred to handle the asynchronous callback and returns a Result object.

Link copied to clipboard
abstract fun setItem(key: String, value: String, callback: (DeviceStorageErrorMessage?, Boolean?) -> Unit): DeviceStorage

Stores a key-value pair.

Link copied to clipboard
suspend fun DeviceStorage.setItem(key: String, value: String): Boolean

Stores a key-value pair. This function suspends until the result is available and returns the result directly or throws an exception if an error occurred.

Link copied to clipboard

Stores a key-value pair. This function uses a CompletableDeferred to handle the asynchronous callback and returns a Result object.