Chat references

Managers

class whalesong.managers.chat.ChatCollectionManager(driver, manager_path='')

Bases: whalesong.managers.BaseCollectionManager

Parameters:
__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
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_first()

Get first item in collection.

Return type:Result[+MODEL_TYPE]
Returns:Model object.
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_item_result_class()
Return type:Result[+MODEL_TYPE]
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_last()

Get last item in collection.

Return type:Result[+MODEL_TYPE]
Returns:Model object.
get_length()

Get collection items count.

Return type:Result[int]
Returns:Items count
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

get_active()

Returns chat selected.

Return type:Result[Chat]
Returns:Chat object
resync_messages()

Resynchronize messages.

Return type:Result[None]
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:
  • name (str) – Group’s name
  • contact_ids (List[str]) – List of contact identifier to invite.
  • picture (Optional[BytesIO]) – JPG image.
Return type:

Result[Chat]

Returns:

Chat object.

forward_messages_to_chats(message_ids, chat_ids)

Forward messages.

Return type:Result[dict]
Returns:Operation result.
class whalesong.managers.chat.ChatManager(driver, manager_path='')

Bases: whalesong.managers.BaseModelManager

Chat manager. It allows manage a chat.

msgs

MessageCollectionManager

Chat’s message collection manager.

msg_load_state

MsgLoadStateManager

Chat’s message load state manager.

metadata:

GroupMetadataManager

Chat’s group metadata manager.

contact

ContactManager

Chat’s contact manager.

live_location

LiveLocationManager

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
MODEL_CLASS

alias of Chat

send_text(text, quoted_msg_id=None, mentions=None, link_desc=None)

Send text message to current chat.

Parameters:
  • text (str) – Message to send.
  • quoted_msg_id (Optional[str]) – Quoted message’s identifier.
  • mentions (Optional[List[str]]) – List of user ids mentioned.
  • link_desc – Link description.
Return type:

Result[str]

Returns:

New message’s identifier

send_contact(contact_id, quoted_msg_id=None)

Send contact to current chat.

Parameters:
  • contact_id (str) – Contact identifier to send.
  • quoted_msg_id (Optional[str]) – Quoted message’s identifier.
Return type:

Result[str]

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:
  • contact_name (str) – Contact’s name.
  • phone_number (str) – Contact’s phone number.
  • quoted_msg_id (Optional[str]) – Quoted message’s identifier.
Return type:

Result[str]

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:

Result[str]

Returns:

New message’s identifier

leave_group()

Leave current chat group.

Warning

Only available on group chats.

Return type:Result[None]
delete_chat()

Delete chat.

Return type:Result[None]
send_seen()

Mark chat as seen.

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 string
Return 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

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:
  • field_path (list or None.) – field path. It allows * as wildcard.
  • stop_first (bool) – Stop iteration on first value looked up. Default: False.
Returns:

A list of values or None it was a invalid path.

Return type:

list or None

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 id: str [READ ONLY]

StringIdField field [READ ONLY]

property duration: timedelta

TimedeltaField field

property participants: List of Participant

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
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_model()

Get model object

Return type:Result[+MODEL_TYPE]
Returns:Model object
get_model_result_class()
Return type:Result[+MODEL_TYPE]
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
mark_composing()

Set “typing…” message for 2.5 seconds.

Return type:Result[None]
Returns:None
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]
mark_recording()

Set “recording audio…” message.

Return type:Result[None]
Returns:None
mark_paused()

Unset “typing…” or “recording audio…” message.

Return type:Result[None]
Returns:None
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.
archive()

Archive chat.

Return type:Result[bool]
Returns:Operation result.
unarchive()

Unarchive chat.

Return type:Result[bool]
Returns:Operation result.
pin()

Pin chat.

Return type:Result[bool]
Returns:Operation result.
unpin()

Unpin chat.

Return type:Result[bool]
Returns:Operation result.
set_group_description(description)

Set group description.

Return type:Result[bool]
Returns:Operation result.
star_messages(message_ids)

Star messages.

Return type:Result[bool]
Returns:Operation result.
unstar_messages(message_ids)

Unstar messages.

Return type:Result[bool]
Returns:Operation result.
send_not_spam()

Send not spam report.

Return type:Result[bool]
Returns:Operation result.
send_spam_report()

Send spam report.

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:
__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
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_model()

Get model object

Return type:Result[+MODEL_TYPE]
Returns:Model object
get_model_result_class()
Return type:Result[+MODEL_TYPE]
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]

Models

Model whalesong.managers.chat.Chat(data=None, flat=False, *args, **kwargs)

Bases: whalesong.models.BaseModel

Chat model.

property name: str

Chat title.

property pin: int

Pin type (¿?)

property archive: bool
Default value:False

Whether chat is archived or not.

property contact: Contact

Contact object.

property kind: str

¿?

property mute: Mute

Mute information.

property id: str [READ ONLY]

StringIdField field [READ ONLY]

property lastMessageTs: datetime

DateTimeField field

Aliases:
  • last_message_ts
  • t
property unreadCount: int

IntegerField field

Aliases:
  • unread_count
property changeNumberNewJid: str

StringIdField field

Aliases:
  • change_number_new_jid
property changeNumberOldJid: str

StringIdField field

Aliases:
  • change_number_old_jid
property groupMetadata: GroupMetadata

ModelField field (whalesong.managers.group_metadata.GroupMetadata)

Aliases:
  • group_metadata
property isAnnounceGrpRestrict: bool
Default value:False

BooleanField field

Aliases:
  • is_announce_grp_restrict
property isGroup: bool
Default value:False

BooleanField field

Aliases:
  • is_group
property isReadOnly: bool
Default value:False

BooleanField field

Aliases:
  • is_read_only
property lastReceivedKey: str

StringIdField field

Aliases:
  • last_received_key
property modifyTag: str

StringIdField field

Aliases:
  • modify_tag
property muteExpiration: int

IntegerField field

Aliases:
  • mute_expiration
property notSpam: bool
Default value:False

BooleanField field

Aliases:
  • not_spam
Model whalesong.managers.chat.MsgLoadState(data=None, flat=False, *args, **kwargs)

Bases: whalesong.models.BaseModel

property id: str [READ ONLY]

StringIdField field [READ ONLY]

property contextLoaded: bool
Default value:False

BooleanField field

Aliases:
  • context_loaded
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 isLoadingRecentMsgs: bool
Default value:False

BooleanField field

Aliases:
  • is_loading_recent_msgs
property noEarlierMsgs: bool
Default value:False

BooleanField field

Aliases:
  • no_earlier_msgs