Chat references¶
Managers¶
-
class
whalesong.managers.chat.
ChatCollectionManager
(driver, manager_path='')¶ Bases:
whalesong.managers.BaseCollectionManager
Parameters: - driver (
BaseWhalesongDriver
) – Whalesong driver - manager_path (
str
) – Manager prefix path.
-
__getitem__
(name)¶ Get a submanager. It could be a explicit submanager or contained model manager.
Parameters: name ( str
) – Field where submanager was stored.Return type: Union
[BaseManager
, ~MODEL_MANAGER_TYPE]
-
__getattr__
(name)¶ Get a submanager. It could be a explicit submanager or contained model manager.
Parameters: name ( str
) – Field where submanager was stored.Return type: Union
[BaseManager
, ~MODEL_MANAGER_TYPE]
-
add_submanager
(name, submanager)¶ Add a submanager.
Parameters: - name (
str
) – Field where manager will be stored. - submanager (
BaseManager
) – Submanager
- name (
-
find_item_by_id
(item_id)¶ Find model by identifier. If item is not in collection it will try to load it.
Parameters: item_id ( str
) – Model identifier.Return type: Result
[+MODEL_TYPE]Returns: Model object.
-
get_commands
()¶ Get manager available static commands.
Return type: Result
[List
[str
]]Returns: Manager static commands.
-
get_item_by_id
(item_id)¶ Get model by identifier.
Parameters: item_id ( str
) – Model identifier.Return type: Result
[+MODEL_TYPE]Returns: Model object.
-
get_items
()¶ Get all items on collection.
Return type: IteratorResult
[+MODEL_TYPE]Returns: Async iterator
-
get_iterator_result_class
()¶ Return type: IteratorResult
[+MODEL_TYPE]
-
get_monitor_result_class
()¶ Return type: MonitorResult
[+MODEL_TYPE]
-
get_submanager
(name)¶ Get a submanager. It could be a explicit submanager or contained model manager.
Parameters: name ( str
) – Field where submanager was stored.Return type: Union
[BaseManager
, ~MODEL_MANAGER_TYPE]
-
monitor_add
()¶ Monitor add item collection. Iterate each time a item is added to collection.
Return type: MonitorResult
[+MODEL_TYPE]Returns: Model object iterator
-
monitor_change
()¶ Monitor change item collection. Iterate each time a item change in collection.
Return type: MonitorResult
[+MODEL_TYPE]Returns: Model object iterator
-
monitor_field
(field)¶ Monitor item’s field change. Iterate each time a field changed in any item of collection.
Return type: MonitorResult
[Dict
[str
,Any
]]Returns: Model object iterator
-
monitor_remove
()¶ Monitor remove item collection. Iterate each time a item is removed from collection.
Return type: MonitorResult
[+MODEL_TYPE]Returns: Model object iterator
-
remove_item_by_id
(item_id)¶ Remove item by identifier.
Parameters: item_id ( str
) – Model identifier.Return type: Result
[None
]
-
remove_submanager
(name)¶ Remove a submanager.
Parameters: name ( str
) – Field where submanager was stored.Return type: Result
[~T]
-
MODEL_MANAGER_CLASS
¶ alias of
ChatManager
-
ensure_chat_with_contact
(contact_id)¶ Ensure there is a chat with a given contact. If it does not exist it will be created.
Parameters: contact_id ( str
) – Contact’s identifier.Return type: Result
[Chat
]Returns: Chat object
-
create_group
(name, contact_ids, picture=None, picture_preview=None)¶ Create a new chat group.
Parameters: Return type: Returns: Chat object.
- driver (
-
class
whalesong.managers.chat.
ChatManager
(driver, manager_path='')¶ Bases:
whalesong.managers.BaseModelManager
Chat manager. It allows manage a chat.
-
msgs
¶ -
Chat’s message collection manager.
-
msg_load_state
¶ -
Chat’s message load state manager.
-
metadata:
GroupMetadataManager
Chat’s group metadata manager.
-
contact
¶ -
Chat’s contact manager.
-
live_location
¶ -
Live location manager. You should call to
find_live_location()
before use it.
-
__getitem__
(name)¶ Get a submanager.
Parameters: name ( str
) – Field where submanager was stored.Return type: BaseManager
-
__getattr__
(name)¶ Get a submanager.
Parameters: name ( str
) – Field where submanager was stored.Return type: BaseManager
-
send_text
(text, quoted_msg_id=None, mentions=None, link_desc=None)¶ Send text message to current chat.
Parameters: Return type: Returns: New message’s identifier
-
send_contact
(contact_id, quoted_msg_id=None)¶ Send contact to current chat.
Parameters: Return type: Returns: New message’s identifier
-
send_contact_phone
(contact_name, phone_number, quoted_msg_id=None)¶ Send contact to current chat using contact name and phone number.
Parameters: Return type: Returns: New message’s identifier
-
send_media
(media_data, content_type=None, filename=None, caption=None, quoted_msg_id=None, mentions=None)¶ Send media file to current chat.
Parameters: - media_data (
BytesIO
) – io.ByteIO - content_type (
Optional
[str
]) – File content type. It is used by Whatsapp to known how to render it. - filename (
Optional
[str
]) – File name. - caption (
Optional
[str
]) – Media caption. - quoted_msg_id (
Optional
[str
]) – Quoted message’s identifier. - mentions (
Optional
[List
[str
]]) – List of user ids mentioned.
Return type: Returns: New message’s identifier
- media_data (
-
leave_group
()¶ Leave current chat group.
Warning
Only available on group chats.
Return type: Result
[None
]
-
load_earlier_messages
()¶ Load earlier messages.
Tip
You should monitor chat messages in order to get new messages loaded.
async for msg in driver.chat[chat_id].msgs.monitor_add(): print(msg)
Return type: Result
[None
]
-
load_all_earlier_messages
()¶ Load ALL earlier messages.
Tip
You should monitor chat messages in order to get new messages loaded. And perhaps you should remove them after process in order to save memory.
async for msg in driver.chat[chat_id].msgs.monitor_add(): print(msg) await driver.chat[chat_id].msgs.remove_item_by_id(item.id)
Return type: Result
[None
]
-
set_subject
(subject)¶ Set group subject/title.
Parameters: subject ( str
) – New group subject/title stringReturn type: Result
[None
]Returns: None
-
Model
LiveLocation
(data=None, flat=False, *args, **kwargs)¶ Bases:
whalesong.models.BaseModel
Live location model.
-
clear
()¶ Clears all the data in the object, keeping original data
-
clear_all
()¶ Clears all the data in the object
-
clear_modified_data
()¶ Clears only the modified data
-
copy
()¶ Creates a copy of model
-
delete_attr_by_path
(field_path)¶ It deletes fields looked up by field path. Field path is dot-formatted string path:
parent_field.child_field
.Parameters: field_path (str) – field path. It allows *
as wildcard.
-
delete_field_value
(name)¶ Mark this field to be deleted
-
export_data
()¶ Get the results with the modified_data
-
export_deleted_fields
()¶ Resturns a list with any deleted fields form original data. In tree models, deleted fields on children will be appended.
-
export_modifications
()¶ Returns model modifications.
-
export_modified_data
()¶ Get the modified data
-
export_original_data
()¶ Get the original data
-
flat_data
()¶ Pass all the data from modified_data to original_data
-
get_1st_attr_by_path
(field_path, **kwargs)¶ It returns first value looked up by field path. Field path is dot-formatted string path:
parent_field.child_field
.Parameters: - field_path (str) – field path. It allows
*
as wildcard. - default – Default value if field does not exist.
If it is not defined
AttributeError
exception will be raised.
Returns: value
- field_path (str) – field path. It allows
-
get_attrs_by_path
(field_path, stop_first=False)¶ It returns list of values looked up by field path. Field path is dot-formatted string path:
parent_field.child_field
.Parameters: Returns: A list of values or None it was a invalid path.
Return type: list
orNone
-
get_default_data
()¶ Returns a dictionary with default data.
Returns: dict
-
get_field_obj
(name)¶
-
get_field_value
(name)¶ Get the field value from the modified data or the original one
-
get_fields
()¶ Returns used fields of model
-
get_original_field_value
(name)¶ Returns original field value or None
-
get_parent
()¶ Returns parent model
-
get_read_only
()¶ Returns whether model could be modified or not
-
get_real_name
(name)¶
-
get_structure
()¶ Returns a dictionary with model field objects.
Returns: dict
-
import_data
(data)¶ Set the fields established in data to the instance
-
import_deleted_fields
(data)¶ Set data fields to deleted
-
is_locked
()¶ Returns whether model is locked
-
is_modified
()¶ Returns whether model is modified or not
-
is_modified_field
(name)¶ Returns whether a field is modified or not
-
lock
()¶ Lock model to avoid modification on read only fields
-
reset_attr_by_path
(field_path)¶ It restores original values for fields looked up by field path. Field path is dot-formatted string path:
parent_field.child_field
.Parameters: field_path (str) – field path. It allows *
as wildcard.
-
reset_field_value
(name)¶ Resets value of a field
-
set_field_value
(name, value)¶ Set the value to the field modified_data
-
set_parent
(value)¶ Sets parent model
-
set_read_only
(value)¶ Sets whether model could be modified or not
-
unlock
()¶ Unlock model to be able to write even it’s read only
-
property
participants
: List ofParticipant
¶ Array of ModelField field (
whalesong.managers.live_location.Participant
)
-
-
add_submanager
(name, submanager)¶ Add a submanager.
Parameters: - name (
str
) – Field where manager will be stored. - submanager (
BaseManager
) – Submanager
- name (
-
get_commands
()¶ Get manager available static commands.
Return type: Result
[List
[str
]]Returns: Manager static commands.
-
get_field_monitor_result_class
(field)¶ Return type: MonitorResult
[Dict
[str
,Any
]]
-
get_monitor_result_class
()¶ Return type: MonitorResult
[+MODEL_TYPE]
-
get_submanager
(name)¶ Get a submanager.
Parameters: name ( str
) – Field where submanager was stored.Return type: BaseManager
-
map_model
(data)¶ Return type: +MODEL_TYPE
-
monitor_field
(field)¶ Monitor any change on a model’s field.
Parameters: field ( str
) – Field to monitor.Return type: MonitorResult
[Dict
[str
,Any
]]Returns: Model monitor
-
monitor_model
()¶ Monitor any change on model.
Return type: MonitorResult
[+MODEL_TYPE]Returns: Model monitor
-
remove_submanager
(name)¶ Remove a submanager.
Parameters: name ( str
) – Field where submanager was stored.Return type: Result
[~T]
-
can_archive
()¶ Check whether chat could be archived.
Return type: Result
[bool
]Returns: Whether chat could be archived.
-
can_send
()¶ Check whether current user could send message in chat.
Return type: Result
[bool
]Returns: Whether current user could send message in chat.
-
can_pin
()¶ Check whether chat could be pinned.
Return type: Result
[bool
]Returns: Whether chat could be pinned.
-
set_group_description
(description)¶ Set group description.
Return type: Result
[bool
]Returns: Operation result.
-
find_live_location
()¶ It find chat’s live location. If it does not exist it will be created.
Return type: Result
[LiveLocation
]Returns: Live location.
-
-
class
whalesong.managers.chat.
MsgLoadStateManager
(driver, manager_path='')¶ Bases:
whalesong.managers.BaseModelManager
Message load state manager
Parameters: - driver (
BaseWhalesongDriver
) – Whalesong driver - manager_path (
str
) – Manager prefix path.
-
__getitem__
(name)¶ Get a submanager.
Parameters: name ( str
) – Field where submanager was stored.Return type: BaseManager
-
__getattr__
(name)¶ Get a submanager.
Parameters: name ( str
) – Field where submanager was stored.Return type: BaseManager
-
MODEL_CLASS
¶ alias of
MsgLoadState
-
add_submanager
(name, submanager)¶ Add a submanager.
Parameters: - name (
str
) – Field where manager will be stored. - submanager (
BaseManager
) – Submanager
- name (
-
get_commands
()¶ Get manager available static commands.
Return type: Result
[List
[str
]]Returns: Manager static commands.
-
get_field_monitor_result_class
(field)¶ Return type: MonitorResult
[Dict
[str
,Any
]]
-
get_monitor_result_class
()¶ Return type: MonitorResult
[+MODEL_TYPE]
-
get_submanager
(name)¶ Get a submanager.
Parameters: name ( str
) – Field where submanager was stored.Return type: BaseManager
-
map_model
(data)¶ Return type: +MODEL_TYPE
-
monitor_field
(field)¶ Monitor any change on a model’s field.
Parameters: field ( str
) – Field to monitor.Return type: MonitorResult
[Dict
[str
,Any
]]Returns: Model monitor
-
monitor_model
()¶ Monitor any change on model.
Return type: MonitorResult
[+MODEL_TYPE]Returns: Model monitor
- driver (
Models¶
-
Model
whalesong.managers.chat.
Chat
(data=None, flat=False, *args, **kwargs)¶ Bases:
whalesong.models.BaseModel
Chat model.
-
property
groupMetadata
:GroupMetadata
¶ ModelField field (
whalesong.managers.group_metadata.GroupMetadata
)Aliases: - group_metadata
-
property
-
Model
whalesong.managers.chat.
MsgLoadState
(data=None, flat=False, *args, **kwargs)¶ Bases:
whalesong.models.BaseModel
-
property
isLoadingAroundMsgs
:bool
¶ Default value: False BooleanField field
Aliases: - is_loading_around_msgs
-
property
isLoadingEarlierMsgs
:bool
¶ Default value: False BooleanField field
Aliases: - is_loading_earlier_msgs
-
property