Client
Source: Client.
Starting point for interacting with the WhatsApp Web API
Property
Methods
new Client(options)
Parameters
Name | Type | Optional | Description | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
|
|
Client options Values in
|
- Extends
- EventEmitter
- Fires
- Client#event:qr
- Client#event:authenticated
- Client#event:auth_failure
- Client#event:ready
- Client#event:message
- Client#event:message_ack
- Client#event:message_create
- Client#event:message_revoke_me
- Client#event:message_revoke_everyone
- Client#event:media_uploaded
- Client#event:group_join
- Client#event:group_leave
- Client#event:group_update
- Client#event:disconnected
- Client#event:change_state
Property
info ClientInfo
Current connection information
Methods
acceptGroupV4Invite(inviteInfo) → Promise containing Object
Accepts a private invitation to join a group
Parameter
Name | Type | Optional | Description |
---|---|---|---|
inviteInfo |
object |
|
Invite V4 Info |
- Returns
-
Promise containing Object
acceptInvite(inviteCode) → Promise containing string
Accepts an invitation to join a group
Parameter
Name | Type | Optional | Description |
---|---|---|---|
inviteCode |
string |
|
Invitation code |
- Returns
-
Promise containing string
Id of the joined Chat
archiveChat() → boolean
Enables and returns the archive state of the Chat
- Returns
-
boolean
createGroup(name, participants) → (Object, string, or Object with string properties)
Create a new group
Parameters
Name | Type | Optional | Description |
---|---|---|---|
name |
string |
|
group title |
participants |
Array of (Contact or string) |
|
an array of Contacts or contact IDs to add to the group |
- Returns
-
Object
createRes
-
string
createRes.gid - ID for the group that was just created
-
Object with string properties
createRes.missingParticipants - participants that were not added to the group. Keys represent the ID for participant that was not added and its value is a status code that represents the reason why participant could not be added. This is usually 403 if the user's privacy settings don't allow you to add them to groups.
destroy()
Closes the client
getBlockedContacts() → Promise containing Array of Contact
Gets all blocked contacts by host account
- Returns
-
Promise containing Array of Contact
getChatById(chatId) → Promise containing Chat
Get chat instance by ID
Parameter
Name | Type | Optional | Description |
---|---|---|---|
chatId |
string |
|
- Returns
-
Promise containing Chat
getChatLabels(chatId) → Promise containing Array of Label
Get all Labels assigned to a chat
Parameter
Name | Type | Optional | Description |
---|---|---|---|
chatId |
string |
|
- Returns
-
Promise containing Array of Label
getChats() → Promise containing Array of Chat
Get all current chat instances
- Returns
-
Promise containing Array of Chat
getChatsByLabelId(labelId) → Promise containing Array of Chat
Get all Chats for a specific Label
Parameter
Name | Type | Optional | Description |
---|---|---|---|
labelId |
string |
|
- Returns
-
Promise containing Array of Chat
getCommonGroups(contactId) → Promise containing Array of WAWebJS.ChatId
Gets the Contact's common groups with you. Returns empty array if you don't have any common group.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
contactId |
string |
|
the whatsapp user's ID (_serialized format) |
- Returns
-
Promise containing Array of WAWebJS.ChatId
getContactById(contactId) → Promise containing Contact
Get contact instance by ID
Parameter
Name | Type | Optional | Description |
---|---|---|---|
contactId |
string |
|
- Returns
-
Promise containing Contact
getContacts() → Promise containing Array of Contact
Get all current contact instances
- Returns
-
Promise containing Array of Contact
getCountryCode(number) → Promise containing string
Get the country code of a WhatsApp ID.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
number |
string |
|
Number or ID |
- Returns
-
Promise containing string
getFormattedNumber(number) → Promise containing string
Get the formatted number of a WhatsApp ID.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
number |
string |
|
Number or ID |
- Returns
-
Promise containing string
getInviteInfo(inviteCode) → Promise containing object
Returns an object with information about the invite code's group
Parameter
Name | Type | Optional | Description |
---|---|---|---|
inviteCode |
string |
|
- Returns
-
Promise containing object
Invite information
getLabelById(labelId) → Promise containing Label
Get Label instance by ID
Parameter
Name | Type | Optional | Description |
---|---|---|---|
labelId |
string |
|
- Returns
-
Promise containing Label
getLabels() → Promise containing Array of Label
Get all current Labels
- Returns
-
Promise containing Array of Label
getNumberId(number) → Promise containing (Object or null)
Get the registered WhatsApp ID for a number. Will return null if the number is not registered on WhatsApp.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
number |
string |
|
Number or ID ("@c.us" will be automatically appended if not specified) |
- Returns
-
Promise containing (Object or null)
getProfilePicUrl(contactId) → Promise containing string
Returns the contact ID's profile picture URL, if privacy settings allow it
Parameter
Name | Type | Optional | Description |
---|---|---|---|
contactId |
string |
|
the whatsapp user's ID |
- Returns
-
Promise containing string
getState() → WAState
Gets the current connection state for the client
- Returns
getWWebVersion() → Promise containing string
Returns the version of WhatsApp Web currently being run
- Returns
-
Promise containing string
initialize()
Sets up events and requirements, kicks off authentication request
isRegisteredUser(id) → Promise containing Boolean
Check if a given ID is registered in whatsapp
Parameter
Name | Type | Optional | Description |
---|---|---|---|
id |
string |
|
the whatsapp user's ID |
- Returns
-
Promise containing Boolean
logout()
Logs out the client, closing the current session
markChatUnread(chatId)
Mark the Chat as unread
Parameter
Name | Type | Optional | Description |
---|---|---|---|
chatId |
string |
|
ID of the chat that will be marked as unread |
muteChat(chatId, unmuteDate)
Mutes this chat forever, unless a date is specified
Parameters
Name | Type | Optional | Description |
---|---|---|---|
chatId |
string |
|
ID of the chat that will be muted |
unmuteDate |
Date |
|
Date when the chat will be unmuted, leave as is to mute forever Value can be null. |
pinChat() → Promise containing boolean
Pins the Chat
- Returns
-
Promise containing boolean
New pin state. Could be false if the max number of pinned chats was reached.
resetState()
Force reset of connection state for the client
searchMessages(query[, options]) → Promise containing Array of Message
Searches for messages
Parameters
Name | Type | Optional | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
query |
string |
|
|||||||||||||||||
options |
Object |
Yes |
Values in
|
- Returns
-
Promise containing Array of Message
sendMessage(chatId, content[, options]) → Promise containing Message
Send a message to a specific chatId
Parameters
Name | Type | Optional | Description |
---|---|---|---|
chatId |
string |
|
|
content |
(string, MessageMedia, Location, Contact, Array of Contact, Buttons, or List) |
|
|
options |
Yes |
Options used when sending the message |
- Returns
-
Promise containing Message
Message that was just sent
sendPresenceAvailable()
Marks the client as online
sendPresenceUnavailable()
Marks the client as unavailable
sendSeen(chatId) → Promise containing boolean
Mark as seen for the Chat
Parameter
Name | Type | Optional | Description |
---|---|---|---|
chatId |
string |
|
- Returns
-
Promise containing boolean
result
setDisplayName(displayName) → Promise containing Boolean
Sets the current user's display name. This is the name shown to WhatsApp users that have not added you as a contact beside your number in groups and in your profile.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
displayName |
string |
|
New display name |
- Returns
-
Promise containing Boolean
setStatus(status)
Sets the current user's status message
Parameter
Name | Type | Optional | Description |
---|---|---|---|
status |
string |
|
New status message |
unarchiveChat() → boolean
Changes and returns the archive state of the Chat
- Returns
-
boolean
unmuteChat(chatId)
Unmutes the Chat
Parameter
Name | Type | Optional | Description |
---|---|---|---|
chatId |
string |
|
ID of the chat that will be unmuted |
unpinChat() → Promise containing boolean
Unpins the Chat
- Returns
-
Promise containing boolean
New pin state
Events
auth_failure
Emitted when there has been an error while trying to restore an existing session
Parameter
Name | Type | Optional | Description |
---|---|---|---|
message |
string |
|
authenticated
Emitted when authentication is successful
change_battery
Emitted when the battery percentage for the attached device changes. Will not be sent if using multi-device.
Parameters
Name | Type | Optional | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
batteryInfo |
object |
|
Values in
|
- Deprecated
change_state
Emitted when the connection state changes
Parameter
Name | Type | Optional | Description |
---|---|---|---|
state |
|
the new connection state |
disconnected
Emitted when the client has been disconnected
Parameter
Name | Type | Optional | Description |
---|---|---|---|
reason |
(WAState or "NAVIGATION") |
|
reason that caused the disconnect |
group_join
Emitted when a user joins the chat via invite link or is added by an admin.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
notification |
|
GroupNotification with more information about the action |
group_leave
Emitted when a user leaves the chat or is removed by an admin.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
notification |
|
GroupNotification with more information about the action |
group_update
Emitted when group settings are updated, such as subject, description or picture.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
notification |
|
GroupNotification with more information about the action |
incoming_call
Emitted when a call is received
Parameters
Name | Type | Optional | Description | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
call |
object |
|
Values in
|
media_uploaded
Emitted when media has been uploaded for a message sent by the client.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
message |
|
The message with media that was uploaded |
message
Emitted when a new message is received.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
message |
|
The message that was received |
message_ack
Emitted when an ack event occurrs on message type.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
message |
|
The message that was affected |
|
ack |
|
The new ACK value |
message_create
Emitted when a new message is created, which may include the current user's own messages.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
message |
|
The message that was created |
message_revoke_everyone
Emitted when a message is deleted for everyone in the chat.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
message |
|
The message that was revoked, in its current state. It will not contain the original message's data. |
|
revoked_msg |
|
The message that was revoked, before it was revoked. It will contain the message's original data. Note that due to the way this data is captured, it may be possible that this param will be undefined. Value can be null. |
message_revoke_me
Emitted when a message is deleted by the current user.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
message |
|
The message that was revoked |
qr
Emitted when a QR code is received
Parameter
Name | Type | Optional | Description |
---|---|---|---|
qr |
string |
|
QR Code |
ready
Emitted when the client has initialized and is ready to receive messages.