telegram.ext.DictPersistence¶
-
class
telegram.ext.
DictPersistence
(store_user_data=True, store_chat_data=True, user_data_json='', chat_data_json='', conversations_json='')¶ Bases:
telegram.ext.basepersistence.BasePersistence
Using python’s dicts and json for making you bot persistent.
-
store_user_data
¶ Whether user_data should be saved by this persistence class.
Type: bool
-
store_chat_data
¶ Whether chat_data should be saved by this persistence class.
Type: bool
Parameters: - store_user_data (
bool
, optional) – Whether user_data should be saved by this persistence class. Default isTrue
. - store_chat_data (
bool
, optional) – Whether user_data should be saved by this persistence class. Default isTrue
. - user_data_json (
str
, optional) – Json string that will be used to reconstruct user_data on creating this persistence. Default is""
. - chat_data_json (
str
, optional) – Json string that will be used to reconstruct chat_data on creating this persistence. Default is""
. - conversations_json (
str
, optional) – Json string that will be used to reconstruct conversation on creating this persistence. Default is""
.
-
chat_data
¶ The chat_data as a dict
Type: dict
-
chat_data_json
¶ The chat_data serialized as a JSON-string.
Type: str
-
conversations
¶ The conversations as a dict
Type: dict
-
conversations_json
¶ The conversations serialized as a JSON-string.
Type: str
-
get_chat_data
()¶ Returns the chat_data created from the
chat_data_json
or an empty defaultdict.Returns: The restored user data. Return type: defaultdict
-
get_conversations
(name)¶ Returns the conversations created from the
conversations_json
or an empty defaultdict.Returns: The restored user data. Return type: defaultdict
-
get_user_data
()¶ Returns the user_data created from the
user_data_json
or an empty defaultdict.Returns: The restored user data. Return type: defaultdict
-
update_chat_data
(chat_id, data)¶ Will update the chat_data (if changed).
Parameters: - chat_id (
int
) – The chat the data might have been changed for. - data (
dict
) – The :attr:`telegram.ext.dispatcher.chat_data`[chat_id].
- chat_id (
-
update_conversation
(name, key, new_state)¶ Will update the conversations for the given handler.
Parameters: - name (
str
) – The handlers name. - key (
tuple
) – The key the state is changed for. - new_state (
tuple
|any
) – The new state for the given key.
- name (
-
update_user_data
(user_id, data)¶ Will update the user_data (if changed).
Parameters: - user_id (
int
) – The user the data might have been changed for. - data (
dict
) – The :attr:`telegram.ext.dispatcher.user_data`[user_id].
- user_id (
-
user_data
¶ The user_data as a dict
Type: dict
-
user_data_json
¶ The user_data serialized as a JSON-string.
Type: str
-