Welcome to WebWhatsAPI’s documentation!

This package is used to provide a python interface for interacting with WhatsAPP Web to send and recieve Whatsapp messages.

Indices and tables

Documentation for the Code

Driver

WebWhatsAPI module

exception webwhatsapi.ChatNotFoundError[source]
exception webwhatsapi.ContactNotFoundError[source]
class webwhatsapi.WhatsAPIDriver(client='firefox', username='API', proxy=None, command_executor=None, loadstyles=False, profile=None, headless=False, autoconnect=True, logger=None, extra_params=None, chrome_options=None)[source]
This is our main driver objects.

Note

Runs its own instance of selenium

chat_send_seen(chat_id)[source]

Send a seen to a chat given its ID

Parameters:chat_id (str) – Chat ID
close()[source]

Closes the selenium instance

contact_get_common_groups(contact_id)[source]

Returns groups common between a user and the contact with given id.

Returns:Contact or Error
Return type:Contact
delete_chat(chat_id)[source]

Delete a chat

Parameters:chat_id – id of chat
Returns:
get_all_chat_ids()[source]

Fetches all chat ids

Returns:List of chat ids
Return type:list[str]
get_all_chats()[source]

Fetches all chats

Returns:List of chats
Return type:list[Chat]
get_all_message_ids_in_chat(chat, include_me=False, include_notifications=False)[source]

Fetches message ids in chat

Parameters:
  • include_me (bool or None) – Include user’s messages
  • include_notifications (bool or None) – Include events happening on chat
Returns:

List of message ids in chat

Return type:

list[str]

get_all_messages_in_chat(chat, include_me=False, include_notifications=False)[source]

Fetches messages in chat

Parameters:
  • include_me (bool or None) – Include user’s messages
  • include_notifications (bool or None) – Include events happening on chat
Returns:

List of messages in chat

Return type:

list[Message]

get_battery_level()[source]

Check the battery level of device

Returns:int: Battery level
get_chat_from_id(chat_id)[source]

Fetches a chat given its ID

Parameters:chat_id (str) – Chat ID
Returns:Chat or Error
Return type:Chat
get_chat_from_phone_number(number)[source]

Gets chat by phone number Number format should be as it appears in Whatsapp ID For example, for the number: +972-51-234-5678 This function would receive: 972512345678

Parameters:number – Phone number
Returns:Chat
Return type:Chat
get_contact_from_id(contact_id)[source]

Fetches a contact given its ID

Parameters:contact_id (str) – Contact ID
Returns:Contact or Error
Return type:Contact
get_contacts()[source]

Fetches list of all contacts This will return chats with people from the address book only Use get_all_chats for all chats

Returns:List of contacts
Return type:list[Contact]
get_message_by_id(message_id)[source]

Fetch a message

Parameters:message_id (str) – Message ID
Returns:Message or False
Return type:Message
get_my_contacts()[source]

Fetches list of added contacts

Returns:List of contacts
Return type:list[Contact]
get_qr(filename=None)[source]

Get pairing QR code from client

get_status()[source]

Returns status of the driver

Returns:Status
Return type:WhatsAPIDriverStatus
get_unread(include_me=False, include_notifications=False, use_unread_count=False)[source]

Fetches unread messages

Parameters:
  • include_me (bool or None) – Include user’s messages
  • include_notifications (bool or None) – Include events happening on chat
  • use_unread_count (bool) – If set uses chat’s ‘unreadCount’ attribute to fetch last n messages from chat
Returns:

List of unread messages grouped by chats

Return type:

list[MessageGroup]

get_unread_messages_in_chat(id, include_me=False, include_notifications=False)[source]

I fetch unread messages from an asked chat.

Parameters:
  • id (str) – chat id
  • include_me (bool) – if user’s messages are to be included
  • include_notifications (bool) – if events happening on chat are to be included
Returns:

list of unread messages from asked chat

Return type:

list

is_logged_in()[source]

Returns if user is logged. Can be used if non-block needed for wait_for_login

leave_group(chat_id)[source]

Leave a group

Parameters:chat_id – id of group
Returns:
mark_default_unread_messages()[source]

Look for the latest unreplied messages received and mark them as unread.

save_firefox_profile(remove_old=False)[source]

Function to save the firefox profile to the permanant one

send_message_to_id(recipient, message)[source]

Send a message to a chat given its ID

Parameters:
  • recipient (str) – Chat ID
  • message (str) – Plain-text message to be sent.
wait_for_login(timeout=90)[source]

Waits for the QR to go away

exception webwhatsapi.WhatsAPIException[source]

Objects

class webwhatsapi.objects.contact.Contact(js_obj, driver=None)[source]

Class which represents a Contact on user’s phone

get_chat(*args)
get_common_groups(*args)
get_safe_name()[source]
Returns:String used for representation of the Contact
Return type:String
class webwhatsapi.objects.chat.BroadcastChat(js_obj, driver=None)[source]
class webwhatsapi.objects.chat.Chat(js_obj, driver=None)[source]
get_messages(include_me=False, include_notifications=False)[source]
get_unread_messages(include_me=False, include_notifications=False)[source]

I fetch unread messages.

Parameters:
  • include_me (bool) – if user’s messages are to be included
  • include_notifications (bool) – if events happening on chat are to be included
Returns:

list of unread messages

Return type:

list

load_all_earlier_messages()[source]
load_earlier_messages()[source]
load_earlier_messages_till(last)[source]

Triggers loading of messages till a specific point in time

Parameters:last (datetime) – Datetime object for the last message to be loaded
Returns:Nothing
Return type:None
send_message(*args)
send_seen(*args)
class webwhatsapi.objects.chat.GroupChat(js_obj, driver=None)[source]
get_admins(*args)
get_participants(*args)
get_participants_ids(*args)
class webwhatsapi.objects.chat.UserChat(js_obj, driver=None)[source]
webwhatsapi.objects.chat.factory_chat(js_obj, driver=None)[source]

Factory function for creating appropriate object given selenium JS object

class webwhatsapi.objects.message.GeoMessage(js_obj, driver=None)[source]
class webwhatsapi.objects.message.MMSMessage(js_obj, driver=None)[source]

Represents MMS messages

Example of an MMS message: “ptt” (push to talk), voice memo

class webwhatsapi.objects.message.MediaMessage(js_obj, driver=None)[source]
crypt_keys = {'document': '576861747341707020446f63756d656e74204b657973', 'image': '576861747341707020496d616765204b657973', 'ptt': '576861747341707020417564696f204b657973', 'video': '576861747341707020566964656f204b657973'}
save_media(path)[source]
class webwhatsapi.objects.message.Message(js_obj, driver=None)[source]
class webwhatsapi.objects.message.MessageGroup(chat, messages)[source]
class webwhatsapi.objects.message.NotificationMessage(js_obj, driver=None)[source]
class webwhatsapi.objects.message.VCardMessage(js_obj, driver=None)[source]
webwhatsapi.objects.message.factory_message(js_obj, driver)[source]

Factory function for creating appropriate object given selenium JS object

webwhatsapi.objects.message.getContacts(x, driver)[source]