Skip to content

TelegramData

Moris Doratiotto edited this page Aug 26, 2021 · 4 revisions

Overview

A TelegramData object is the only object your custom functions need to have.
When you define a function, there will always be a single required parameter, a TelegramData instance.
With all the parameters (specified below) you will have access to every Telegram data you will need.

Doc

Attributes

  • autoconv: Autoconv instance.
  • update,context: Telegram update and context.
  • telegram_id: Telegram ID of the user.
  • udata: context.user_data of the user.
  • sdata: data for every state of the user.
  • message: message info, if possibile, of the user.
  • exception: last Python exception occurred.
  • users: list of current authorized users.

Functions

Save

Usage example: tdata.py

# save key:values in context.user_data, works as Dict.update
TelegramData.save(
    *args,
    **kwargs
)

Add

Usage example: tdata.py

# add a value to an existing key in context.user_data
TelegramData.add(
    key: str,
    value: Any
) → Any
  • key: key in context.user_data dictionary
  • value: value to add to the corresponding value in dictionary (need to be compatible with + operator)
  • It returns the value after the operation

Get or Set

Usage example: tdata.py

TelegramData.get_or_set(
    key: str,
    set_value: Any
) → Any
  • key: key in context.user_data dictionary
  • set_value: value to set if key doesn't exist in dictionary
  • It returns the value in dictionary after the operation
Clone this wiki locally