Store Coder

class telegram_bot_discussion.ext.coder.store_coder.KeyValueStorageInterface[source]

Bases: ABC

KeyValueStorageInterface is interface for external storage where custom values of Params are stored.

abstractmethod static autogenerate_primary_key()[source]
abstractmethod get(key)[source]
Return type:

Any

Parameters:

key (str)

abstractmethod add(value)[source]
Return type:

str

Parameters:

value (Any)

class telegram_bot_discussion.ext.coder.store_coder.StoreCoder(secret, db)[source]

Bases: CoderInterface

StoreCoder StoreCoder serializes data and saves its value in an external storage with unique primary key. The primary key is stored in the Button. For deserialization, the data is got from the external storage by primary key.

So there are no any limits for callback query data (long strings, complex multi params, redundant big json and etc.).

Parameters:
secret: str

Secret string is used for making digital signature of data.

Type:

str

db: KeyValueStorageInterface

external storage where custom values of Params are stored.

Type:

KeyValueStorageInterface

serialize(*args)[source]
Return type:

str

Parameters:

args (Any)

deserialize(data)[source]
Return type:

List[Any]

Parameters:

data (str)

get_signature(chat_id, serialized_data, sender_id)[source]
Return type:

str

Parameters:
  • chat_id (int)

  • serialized_data (str)

  • sender_id (int)

sign(signature, serialized_data)[source]
Return type:

str

Parameters:
  • signature (str)

  • serialized_data (str)

extract_signature_and_serialized_data(signed_serialized_data)[source]
Return type:

Tuple[str, str]

Parameters:

signed_serialized_data (str)

extract_signature_and_deserialized_data(signed_serialized_data)[source]
Return type:

Tuple[str, List[Any]]

Parameters:

signed_serialized_data (str)