Back to Whatsapp Web Js

whatsapp

docs/Client.html

1.34.747.2 KB
Original Source

Properties

info

pupBrowser

pupPage

Methods

_muteUnmuteChat(chatId, action, unmuteDateTs)acceptChannelAdminInvite(channelId)acceptGroupV4Invite(inviteInfo)acceptInvite(inviteCode)addOrEditCustomerNote(userId, note)addOrRemoveLabels(labelIds, chatIds)approveGroupMembershipRequests(groupId, options)archiveChat()attachEventListeners()cancelPairingCode()createCallLink(startTime, callType)createChannel(title, options)createGroup(title, participants, options)deleteAddressbookContact(phoneNumber)deleteChannel(channelId)deleteProfilePicture()demoteChannelAdmin(channelId, userId)destroy()getBlockedContacts()getBroadcastById(contactId)getBroadcasts()getChannelByInviteCode(inviteCode)getChannels()getChatById(chatId)getChatLabels(chatId)getChats()getChatsByLabelId(labelId)getCommonGroups(contactId)

getContactById(contactId)getContactDeviceCount(userId)getContactLidAndPhone(userIds)getContacts()getCountryCode(number)getCustomerNote(userId)getFormattedNumber(number)getGroupMembershipRequests(groupId)getInviteInfo(inviteCode)getLabelById(labelId)getLabels()getMessageById(messageId)getNumberId(number)getPinnedMessages(chatId)getPollVotes(messageId)getProfilePicUrl(contactId)getState()getWWebVersion()initialize()inject()isRegisteredUser(id)logout()markChatUnread(chatId)muteChat(chatId, unmuteDate)pinChat()rejectGroupMembershipRequests(groupId, options)requestPairingCode(phoneNumber[, showNotification][, intervalMs])resetState()

revokeChannelAdminInvite(channelId, userId)revokeStatusMessage(messageId)saveOrEditAddressbookContact(phoneNumber, firstName, lastName[, syncToAddressbook])searchChannels(searchOptions)searchMessages(query[, options])sendChannelAdminInvite(chatId, channelId, options)sendMessage(chatId, content[, options])sendPresenceAvailable()sendPresenceUnavailable()sendReaction(messageId, reaction)sendResponseToScheduledEvent(response, eventMessageId)sendSeen(chatId)setAutoDownloadAudio(flag)setAutoDownloadDocuments(flag)setAutoDownloadPhotos(flag)setAutoDownloadVideos(flag)setBackgroundSync(flag)setDisplayName(displayName)setProfilePicture(media)setStatus(status)subscribeToChannel(channelId)syncHistory(chatId)transferChannelOwnership(channelId, newOwnerId, options)unarchiveChat()unmuteChat(chatId)unpinChat()unsubscribeFromChannel(channelId, options)

Events

auth_failureauthenticatedchange_batterychange_statechat_archivedchat_removedcodecontact_changeddisconnectedgroup_admin_changed

group_joingroup_leavegroup_membership_requestgroup_updateincoming_callmedia_uploadedmessagemessage_ackmessage_ciphertextmessage_ciphertext_failed

message_createmessage_editmessage_reactionmessage_revoke_everyonemessage_revoke_meqrreadyvote_update

new Client(options)

Parameters

NameTypeOptionalDescription

options

|

|

|

Client options

Values in options have the following properties:

NameTypeOptionalDescription

authStrategy

|

|

|

Determines how to save and restore sessions. If not set, NoAuth will be used.

| |

webVersion

|

|

|

The version of WhatsApp Web to use. Use options.webVersionCache to configure how the version is retrieved.

| |

webVersionCache

|

|

|

Determines how to retrieve the WhatsApp Web version. Defaults to a local cache (LocalWebCache) that falls back to latest if the requested version is not found.

| |

authTimeoutMs

|

|

|

Timeout for authentication selector in puppeteer

| |

evalOnNewDoc

|

|

|

function to eval on new doc

| |

puppeteer

|

|

|

Puppeteer launch options. View docs here: https://github.com/puppeteer/puppeteer/

| |

qrMaxRetries

|

|

|

How many times should the qrcode be refreshed before giving up

| |

takeoverOnConflict

|

|

|

If another whatsapp web session is detected (another browser), take over the session in the current browser

| |

takeoverTimeoutMs

|

|

|

How much time to wait before taking over the session

| |

userAgent

|

|

|

User agent to use in puppeteer

| |

ffmpegPath

|

|

|

Ffmpeg path to use when formatting videos to webp while sending stickers

| |

bypassCSP

|

|

|

Sets bypassing of page's Content-Security-Policy.

| |

deviceName

|

|

|

Sets the device name of a current linked device., i.e.: 'TEST'.

| |

browserName

|

|

|

Sets the browser name of a current linked device, i.e.: 'Firefox'.

| |

proxyAuthentication

|

|

|

Proxy Authentication object.

|

|

ExtendsEventEmitterFiresClient#event:qrClient#event:authenticatedClient#event:auth_failureClient#event:readyClient#event:messageClient#event:message_ackClient#event:message_createClient#event:message_revoke_meClient#event:message_revoke_everyoneClient#event:message_ciphertextClient#event:message_editClient#event:media_uploadedClient#event:group_joinClient#event:group_leaveClient#event:group_updateClient#event:disconnectedClient#event:change_stateClient#event:contact_changedClient#event:group_admin_changedClient#event:group_membership_requestClient#event:vote_update

Properties

info ClientInfo

Current connection information

pupBrowser puppeteer.Browser

pupPage puppeteer.Page

Methods

async

_muteUnmuteChat(chatId, action, unmuteDateTs) → Promise containing {isMuted: boolean, muteExpiration: number}

Internal method to mute or unmute the chat

Parameters

NameTypeOptionalDescription

chatId

|

string

|

|

ID of the chat that will be muted/unmuted

| |

action

|

string

|

|

The action: 'MUTE' or 'UNMUTE'

| |

unmuteDateTs

|

number

|

|

Timestamp at which the chat will be unmuted

|

Returns

Promise containing {isMuted: boolean, muteExpiration: number}

async

acceptChannelAdminInvite(channelId) → Promise containing boolean

Accepts a channel admin invitation and promotes the current user to a channel admin

Parameter

NameTypeOptionalDescription

channelId

|

string

|

|

The channel ID to accept the admin invitation from

|

Returns

Promise containing boolean

Returns true if the operation completed successfully, false otherwise

async

acceptGroupV4Invite(inviteInfo) → Promise containing Object

Accepts a private invitation to join a group

Parameter

NameTypeOptionalDescription

inviteInfo

|

object

|

|

Invite V4 Info

|

Returns

Promise containing Object

async

acceptInvite(inviteCode) → Promise containing string

Accepts an invitation to join a group

Parameter

NameTypeOptionalDescription

inviteCode

|

string

|

|

Invitation code

|

Returns

Promise containing string

Id of the joined Chat

async

addOrEditCustomerNote(userId, note) → Promise containing void

Add or edit a customer note

Parameters

NameTypeOptionalDescription

userId

|

string

|

|

The ID of a customer to add a note to

| |

note

|

string

|

|

The note to add

|

See alsohttps://faq.whatsapp.com/1433099287594476Returns

Promise containing void

async

addOrRemoveLabels(labelIds, chatIds) → Promise containing void

Change labels in chats

Parameters

NameTypeOptionalDescription

labelIds

|

Array of (number or string)

|

| | |

chatIds

|

Array of string

|

| |

Returns

Promise containing void

async

approveGroupMembershipRequests(groupId, options) → Promise containing Array of MembershipRequestActionResult

Approves membership requests if any

Parameters

NameTypeOptionalDescription

groupId

|

string

|

|

The group ID to get the membership request for

| |

options

|

MembershipRequestActionOptions

|

|

Options for performing a membership request action

|

Returns

Promise containing Array of MembershipRequestActionResult

Returns an array of requester IDs whose membership requests were approved and an error for each requester, if any occurred during the operation. If there are no requests, an empty array will be returned

async

archiveChat() → boolean

Enables and returns the archive state of the Chat

Returns

boolean

async

attachEventListeners()

Attach event listeners to WA Web Private function

Property

NameTypeOptionalDescription

reinject

|

boolean

|

|

is this a reinject?

|

async

cancelPairingCode()

Cancels an active pairing code session and returns to QR code mode

async

Generates a WhatsApp call link (video call or voice call)

Parameters

NameTypeOptionalDescription

startTime

|

Date

|

|

The start time of the call

| |

callType

|

string

|

|

The type of a WhatsApp call link to generate, valid values are: video | voice

|

Returns

Promise containing string

The WhatsApp call link (https://call.whatsapp.com/video/XxXxXxXxXxXxXx) or an empty string if a generation failed.

async

createChannel(title, options) → Promise containing (CreateChannelResult or string)

Creates a new channel

Parameters

NameTypeOptionalDescription

title

|

string

|

|

The channel name

| |

options

|

CreateChannelOptions

|

| |

Returns

Promise containing (CreateChannelResult or string)

Returns an object that handles the result for the channel creation or an error message as a string

async

createGroup(title, participants, options) → Promise containing (CreateGroupResult or string)

Creates a new group

Parameters

NameTypeOptionalDescription

title

|

string

|

|

Group title

| |

participants

|

(string, Contact, Array of (Contact or string), or undefined)

|

|

A single Contact object or an ID as a string or an array of Contact objects or contact IDs to add to the group

| |

options

|

CreateGroupOptions

|

|

An object that handles options for group creation

|

Returns

Promise containing (CreateGroupResult or string)

Object with resulting data or an error message as a string

async

deleteAddressbookContact(phoneNumber) → Promise containing void

Deletes the contact from user's addressbook

Parameter

NameTypeOptionalDescription

phoneNumber

|

string

|

|

The contact's phone number in a format "17182222222", where "1" is a country code

|

Returns

Promise containing void

async

deleteChannel(channelId) → Promise containing boolean

Deletes the channel you created

Parameter

NameTypeOptionalDescription

channelId

|

string

|

|

The ID of a channel to delete

|

Returns

Promise containing boolean

Returns true if the operation completed successfully, false otherwise

async

deleteProfilePicture() → Promise containing boolean

Deletes the current user's profile picture.

Returns

Promise containing boolean

Returns true if the picture was properly deleted.

async

demoteChannelAdmin(channelId, userId) → Promise containing boolean

Demotes a channel admin to a regular subscriber (can be used also for self-demotion)

Parameters

NameTypeOptionalDescription

channelId

|

string

|

|

The channel ID to demote an admin in

| |

userId

|

string

|

|

The user ID to demote

|

Returns

Promise containing boolean

Returns true if the operation completed successfully, false otherwise

async

destroy()

Closes the client

async

getBlockedContacts() → Promise containing Array of Contact

Gets all blocked contacts by host account

Returns

Promise containing Array of Contact

async

getBroadcastById(contactId) → Promise containing Broadcast

Get broadcast instance by current user ID

Parameter

NameTypeOptionalDescription

contactId

|

string

|

| |

Returns

Promise containing Broadcast

async

getBroadcasts() → Promise containing Array of Broadcast

Get all current Broadcast

Returns

Promise containing Array of Broadcast

async

getChannelByInviteCode(inviteCode) → Promise containing Channel

Gets a Channel instance by invite code

Parameter

NameTypeOptionalDescription

inviteCode

|

string

|

|

The code that comes after the 'https://whatsapp.com/channel/'

|

Returns

Promise containing Channel

async

getChannels() → Promise containing Array of Channel

Gets all cached Channel instance

Returns

Promise containing Array of Channel

async

getChatById(chatId) → Promise containing (Chat or Channel)

Gets chat or channel instance by ID

Parameter

NameTypeOptionalDescription

chatId

|

string

|

| |

Returns

Promise containing (Chat or Channel)

async

getChatLabels(chatId) → Promise containing Array of Label

Get all Labels assigned to a chat

Parameter

NameTypeOptionalDescription

chatId

|

string

|

| |

Returns

Promise containing Array of Label

async

getChats() → Promise containing Array of Chat

Get all current chat instances

Returns

Promise containing Array of Chat

async

getChatsByLabelId(labelId) → Promise containing Array of Chat

Get all Chats for a specific Label

Parameter

NameTypeOptionalDescription

labelId

|

string

|

| |

Returns

Promise containing Array of Chat

async

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

NameTypeOptionalDescription

contactId

|

string

|

|

the whatsapp user's ID (_serialized format)

|

Returns

Promise containing Array of WAWebJS.ChatId

async

getContactById(contactId) → Promise containing Contact

Get contact instance by ID

Parameter

NameTypeOptionalDescription

contactId

|

string

|

| |

Returns

Promise containing Contact

async

getContactDeviceCount(userId) → Promise containing number

Get user device count by ID Each WaWeb Connection counts as one device, and the phone (if exists) counts as one So for a non-enterprise user with one WaWeb connection it should return "2"

Parameter

NameTypeOptionalDescription

userId

|

string

|

| |

Returns

Promise containing number

async

getContactLidAndPhone(userIds) → Promise containing Array of {lid: string, pn: string}

Get lid and phone number for multiple users

Parameter

NameTypeOptionalDescription

userIds

|

Array of string

|

|

Array of user IDs

|

Returns

Promise containing Array of {lid: string, pn: string}

async

getContacts() → Promise containing Array of Contact

Get all current contact instances

Returns

Promise containing Array of Contact

async

getCountryCode(number) → Promise containing string

Get the country code of a WhatsApp ID.

Parameter

NameTypeOptionalDescription

number

|

string

|

|

Number or ID

|

Returns

Promise containing string

async

getCustomerNote(userId) → Promise containing {chatId: string, content: string, createdAt: number, id: string, modifiedAt: number, type: string}

Get a customer note

Parameter

NameTypeOptionalDescription

userId

|

string

|

|

The ID of a customer to get a note from

|

See alsohttps://faq.whatsapp.com/1433099287594476Returns

Promise containing {chatId: string, content: string, createdAt: number, id: string, modifiedAt: number, type: string}

async

getFormattedNumber(number) → Promise containing string

Get the formatted number of a WhatsApp ID.

Parameter

NameTypeOptionalDescription

number

|

string

|

|

Number or ID

|

Returns

Promise containing string

async

getGroupMembershipRequests(groupId) → Promise containing Array of GroupMembershipRequest

Gets an array of membership requests

Parameter

NameTypeOptionalDescription

groupId

|

string

|

|

The ID of a group to get membership requests for

|

Returns

Promise containing Array of GroupMembershipRequest

An array of membership requests

async

getInviteInfo(inviteCode) → Promise containing object

Returns an object with information about the invite code's group

Parameter

NameTypeOptionalDescription

inviteCode

|

string

|

| |

Returns

Promise containing object

Invite information

async

getLabelById(labelId) → Promise containing Label

Get Label instance by ID

Parameter

NameTypeOptionalDescription

labelId

|

string

|

| |

Returns

Promise containing Label

async

getLabels() → Promise containing Array of Label

Get all current Labels

Returns

Promise containing Array of Label

async

getMessageById(messageId) → Promise containing Message

Get message by ID

Parameter

NameTypeOptionalDescription

messageId

|

string

|

| |

Returns

Promise containing Message

async

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

NameTypeOptionalDescription

number

|

string

|

|

Number or ID ("@c.us" will be automatically appended if not specified)

|

Returns

Promise containing (Object or null)

async

getPinnedMessages(chatId) → Promise containing Array of Message

Gets instances of all pinned messages in a chat

Parameter

NameTypeOptionalDescription

chatId

|

string

|

|

The chat ID

|

Returns

Promise containing Array of Message

async

getPollVotes(messageId) → Promise containing Array of PollVote

Get Poll Votes

Parameter

NameTypeOptionalDescription

messageId

|

string

|

| |

Returns

Promise containing Array of PollVote

async

getProfilePicUrl(contactId) → Promise containing string

Returns the contact ID's profile picture URL, if privacy settings allow it

Parameter

NameTypeOptionalDescription

contactId

|

string

|

|

the whatsapp user's ID

|

Returns

Promise containing string

async

getState() → WAState

Gets the current connection state for the client

Returns

WAState

async

getWWebVersion() → Promise containing string

Returns the version of WhatsApp Web currently being run

Returns

Promise containing string

async

initialize()

Sets up events and requirements, kicks off authentication request

async

inject()

Injection logic Private function

async

isRegisteredUser(id) → Promise containing Boolean

Check if a given ID is registered in whatsapp

Parameter

NameTypeOptionalDescription

id

|

string

|

|

the whatsapp user's ID

|

Returns

Promise containing Boolean

async

logout()

Logs out the client, closing the current session

async

markChatUnread(chatId)

Mark the Chat as unread

Parameter

NameTypeOptionalDescription

chatId

|

string

|

|

ID of the chat that will be marked as unread

|

async

muteChat(chatId, unmuteDate) → Promise containing {isMuted: boolean, muteExpiration: number}

Mutes this chat forever, unless a date is specified

Parameters

NameTypeOptionalDescription

chatId

|

string

|

|

ID of the chat that will be muted

| |

unmuteDate

|

Date

|

|

Date when the chat will be unmuted, don't provide a value to mute forever

Value can be null.

|

Returns

Promise containing {isMuted: boolean, muteExpiration: number}

async

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.

async

rejectGroupMembershipRequests(groupId, options) → Promise containing Array of MembershipRequestActionResult

Rejects membership requests if any

Parameters

NameTypeOptionalDescription

groupId

|

string

|

|

The group ID to get the membership request for

| |

options

|

MembershipRequestActionOptions

|

|

Options for performing a membership request action

|

Returns

Promise containing Array of MembershipRequestActionResult

Returns an array of requester IDs whose membership requests were rejected and an error for each requester, if any occurred during the operation. If there are no requests, an empty array will be returned

async

requestPairingCode(phoneNumber[, showNotification][, intervalMs]) → Promise containing string

Request authentication via pairing code instead of QR code

Parameters

NameTypeOptionalDescription

phoneNumber

|

string

|

|

Phone number in international, symbol-free format (e.g. 12025550108 for US, 551155501234 for Brazil)

| |

showNotification

|

boolean

|

Yes

|

Show notification to pair on phone number

Defaults to true.

| |

intervalMs

|

number

|

Yes

|

The interval in milliseconds on how frequent to generate pairing code (WhatsApp default to 3 minutes)

Defaults to 180000.

|

Returns

Promise containing string

  • Returns a pairing code in format "ABCDEFGH"

async

resetState()

Force reset of connection state for the client

async

revokeChannelAdminInvite(channelId, userId) → Promise containing boolean

Revokes a channel admin invitation sent to a user by a channel owner

Parameters

NameTypeOptionalDescription

channelId

|

string

|

|

The channel ID an invitation belongs to

| |

userId

|

string

|

|

The user ID the invitation was sent to

|

Returns

Promise containing boolean

Returns true if the operation completed successfully, false otherwise

async

revokeStatusMessage(messageId) → Promise containing void

Revoke current own status messages

Parameter

NameTypeOptionalDescription

messageId

|

string

|

| |

Returns

Promise containing void

async

saveOrEditAddressbookContact(phoneNumber, firstName, lastName[, syncToAddressbook]) → Promise containing void

Save new contact to user's addressbook or edit the existing one

Parameters

NameTypeOptionalDescription

phoneNumber

|

string

|

|

The contact's phone number in a format "17182222222", where "1" is a country code

| |

firstName

|

string

|

| | |

lastName

|

string

|

| | |

syncToAddressbook

|

boolean

|

Yes

|

If set to true, the contact will also be saved to the user's address book on their phone. False by default

Defaults to false.

|

Returns

Promise containing void

async

searchChannels(searchOptions) → Promise containing Array of Channel

Searches for channels based on search criteria, there are some notes:

  1. The method finds only channels you are not subscribed to currently
  2. If you have never been subscribed to a found channel or you have unsubscribed from it with UnsubscribeOptions.deleteLocalModels set to 'true', the lastMessage property of a found channel will be 'null'

Parameters

NameTypeOptionalDescription

searchOptions

|

Object

|

|

Search options

Values in searchOptions have the following properties:

NameTypeOptionalDescription

searchText

|

string

|

Yes

|

Text to search

Defaults to ''.

| |

countryCodes

|

Array of string

|

Yes

|

Array of country codes in 'ISO 3166-1 alpha-2' standart (@see https://en.wikipedia.org/wiki/ISO\_3166-1\_alpha-2) to search for channels created in these countries

Defaults to [your local region].

| |

skipSubscribedNewsletters

|

boolean

|

Yes

|

If true, channels that user is subscribed to won't appear in found channels

Defaults to false.

| |

view

|

number

|

Yes

|

View type, makes sense only when the searchText is empty. Valid values to provide are: 0 for RECOMMENDED channels 1 for TRENDING channels 2 for POPULAR channels 3 for NEW channels

Defaults to 0.

| |

limit

|

number

|

Yes

|

The limit of found channels to be appear in the returnig result

Defaults to 50.

|

|

Returns

Promise containing Array of Channel

Returns an array of Channel objects or an empty array if no channels were found

async

searchMessages(query[, options]) → Promise containing Array of Message

Searches for messages

Parameters

NameTypeOptionalDescription

query

|

string

|

| | |

options

|

Object

|

Yes

|

Values in options have the following properties:

NameTypeOptionalDescription

page

|

number

|

Yes

| | |

limit

|

number

|

Yes

| | |

chatId

|

string

|

Yes

| |

|

Returns

Promise containing Array of Message

async

sendChannelAdminInvite(chatId, channelId, options) → Promise containing boolean

Sends a channel admin invitation to a user, allowing them to become an admin of the channel

Parameters

NameTypeOptionalDescription

chatId

|

string

|

|

The ID of a user to send the channel admin invitation to

| |

channelId

|

string

|

|

The ID of a channel for which the invitation is being sent

| |

options

|

SendChannelAdminInviteOptions

|

| |

Returns

Promise containing boolean

Returns true if an invitation was sent successfully, false otherwise

async

sendMessage(chatId, content[, options]) → Promise containing Message

Send a message to a specific chatId

Parameters

NameTypeOptionalDescription

chatId

|

string

|

| | |

content

|

(string, MessageMedia, Location, Poll, Contact, Array of Contact, Buttons, or List)

|

| | |

options

|

MessageSendOptions

|

Yes

|

Options used when sending the message

|

Returns

Promise containing Message

Message that was just sent

async

sendPresenceAvailable()

Marks the client as online

async

sendPresenceUnavailable()

Marks the client as unavailable

async

sendReaction(messageId, reaction) → Promise

Send an emoji reaction to a specific message

Parameters

NameTypeOptionalDescription

messageId

|

string

|

|

Id of the message to add the reaction.

| |

reaction

|

string

|

|

Emoji to react with. Send an empty string to remove the reaction.

|

Returns

Promise

async

sendResponseToScheduledEvent(response, eventMessageId) → Promise containing boolean

Sends a response to the scheduled event message, indicating whether a user is going to attend the event or not

Parameters

NameTypeOptionalDescription

response

|

number

|

|

The response code to the scheduled event message. Valid values are: 0 for NONE response (removes a previous response) | 1 for GOING | 2 for NOT GOING | 3 for MAYBE going

| |

eventMessageId

|

string

|

|

The scheduled event message ID

|

Returns

Promise containing boolean

async

sendSeen(chatId) → Promise containing boolean

Mark as seen for the Chat

Parameter

NameTypeOptionalDescription

chatId

|

string

|

| |

Returns

Promise containing boolean

result

async

setAutoDownloadAudio(flag)

Setting autoload download audio

Parameter

NameTypeOptionalDescription

flag

|

boolean

|

|

true/false

|

async

setAutoDownloadDocuments(flag)

Setting autoload download documents

Parameter

NameTypeOptionalDescription

flag

|

boolean

|

|

true/false

|

async

setAutoDownloadPhotos(flag)

Setting autoload download photos

Parameter

NameTypeOptionalDescription

flag

|

boolean

|

|

true/false

|

async

setAutoDownloadVideos(flag)

Setting autoload download videos

Parameter

NameTypeOptionalDescription

flag

|

boolean

|

|

true/false

|

async

setBackgroundSync(flag) → Promise containing boolean

Setting background synchronization. NOTE: this action will take effect after you restart the client.

Parameter

NameTypeOptionalDescription

flag

|

boolean

|

|

true/false

|

Returns

Promise containing boolean

async

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

NameTypeOptionalDescription

displayName

|

string

|

|

New display name

|

Returns

Promise containing Boolean

async

setProfilePicture(media) → Promise containing boolean

Sets the current user's profile picture.

Parameter

NameTypeOptionalDescription

media

|

MessageMedia

|

| |

Returns

Promise containing boolean

Returns true if the picture was properly updated.

async

setStatus(status)

Sets the current user's status message

Parameter

NameTypeOptionalDescription

status

|

string

|

|

New status message

|

async

subscribeToChannel(channelId) → Promise containing boolean

Subscribe to channel

Parameter

NameTypeOptionalDescription

channelId

|

string

|

|

The channel ID

|

Returns

Promise containing boolean

Returns true if the operation completed successfully, false otherwise

async

syncHistory(chatId) → Promise containing boolean

Sync chat history conversation

Parameter

NameTypeOptionalDescription

chatId

|

string

|

| |

Returns

Promise containing boolean

True if operation completed successfully, false otherwise.

async

transferChannelOwnership(channelId, newOwnerId, options) → Promise containing boolean

Transfers a channel ownership to another user. Note: the user you are transferring the channel ownership to must be a channel admin.

Parameters

NameTypeOptionalDescription

channelId

|

string

|

| | |

newOwnerId

|

string

|

| | |

options

|

TransferChannelOwnershipOptions

|

| |

Returns

Promise containing boolean

Returns true if the operation completed successfully, false otherwise

async

unarchiveChat() → boolean

Changes and returns the archive state of the Chat

Returns

boolean

async

unmuteChat(chatId) → Promise containing {isMuted: boolean, muteExpiration: number}

Unmutes the Chat

Parameter

NameTypeOptionalDescription

chatId

|

string

|

|

ID of the chat that will be unmuted

|

Returns

Promise containing {isMuted: boolean, muteExpiration: number}

async

unpinChat() → Promise containing boolean

Unpins the Chat

Returns

Promise containing boolean

New pin state

async

unsubscribeFromChannel(channelId, options) → Promise containing boolean

Unsubscribe from channel

Parameters

NameTypeOptionalDescription

channelId

|

string

|

|

The channel ID

| |

options

|

UnsubscribeOptions

|

| |

Returns

Promise containing boolean

Returns true if the operation completed successfully, false otherwise

Events

auth_failure

Emitted when there has been an error while trying to restore an existing session

Parameter

NameTypeOptionalDescription

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

NameTypeOptionalDescription

batteryInfo

|

object

|

|

Values in batteryInfo have the following properties:

NameTypeOptionalDescription

battery

|

number

|

|

The current battery percentage

| |

plugged

|

boolean

|

|

Indicates if the phone is plugged in (true) or not (false)

|

|

Deprecated

change_state

Emitted when the connection state changes

Parameter

NameTypeOptionalDescription

state

|

WAState

|

|

the new connection state

|

chat_archived

Emitted when a chat is archived/unarchived

Parameters

NameTypeOptionalDescription

chat

|

Chat

|

| | |

currState

|

boolean

|

| | |

prevState

|

boolean

|

| |

chat_removed

Emitted when a chat is removed

Parameter

NameTypeOptionalDescription

chat

|

Chat

|

| |

code

Emitted when a pairing code is received

Parameter

NameTypeOptionalDescription

code

|

string

|

|

Code

|

Returns

string

Code that was just received

contact_changed

Emitted when a contact or a group participant changes their phone number.

Parameters

NameTypeOptionalDescription

message

|

Message

|

|

Message with more information about the event.

| |

oldId

|

String

|

|

The user's id (an old one) who changed their phone number and who triggered the notification.

| |

newId

|

String

|

|

The user's new id after the change.

| |

isContact

|

Boolean

|

|

Indicates if a contact or a group participant changed their phone number.

|

disconnected

Emitted when the client has been disconnected

Parameter

NameTypeOptionalDescription

reason

|

(WAState or "LOGOUT")

|

|

reason that caused the disconnect

|

group_admin_changed

Emitted when a current user is promoted to an admin or demoted to a regular user.

Parameter

NameTypeOptionalDescription

notification

|

GroupNotification

|

|

GroupNotification with more information about the action

|

group_join

Emitted when a user joins the chat via invite link or is added by an admin.

Parameter

NameTypeOptionalDescription

notification

|

GroupNotification

|

|

GroupNotification with more information about the action

|

group_leave

Emitted when a user leaves the chat or is removed by an admin.

Parameter

NameTypeOptionalDescription

notification

|

GroupNotification

|

|

GroupNotification with more information about the action

|

group_membership_request

Emitted when some user requested to join the group that has the membership approval mode turned on

Parameters

NameTypeOptionalDescription

notification

|

GroupNotification

|

|

GroupNotification with more information about the action

Values in notification have the following properties:

NameTypeOptionalDescription

chatId

|

string

|

|

The group ID the request was made for

| |

author

|

string

|

|

The user ID that made a request

| |

timestamp

|

number

|

|

The timestamp the request was made at

|

|

group_update

Emitted when group settings are updated, such as subject, description or picture.

Parameter

NameTypeOptionalDescription

notification

|

GroupNotification

|

|

GroupNotification with more information about the action

|

incoming_call

Emitted when a call is received

Parameters

NameTypeOptionalDescription

call

|

object

|

|

Values in call have the following properties:

NameTypeOptionalDescription

id

|

number

|

|

Call id

| |

peerJid

|

string

|

|

Who called

| |

isVideo

|

boolean

|

|

if is video

| |

isGroup

|

boolean

|

|

if is group

| |

canHandleLocally

|

boolean

|

|

if we can handle in waweb

| |

outgoing

|

boolean

|

|

if is outgoing

| |

webClientShouldHandle

|

boolean

|

|

If Waweb should handle

| |

participants

|

object

|

|

Participants

|

|

media_uploaded

Emitted when media has been uploaded for a message sent by the client.

Parameter

NameTypeOptionalDescription

message

|

Message

|

|

The message with media that was uploaded

|

message

Emitted when a new message is received.

Parameter

NameTypeOptionalDescription

message

|

Message

|

|

The message that was received

|

message_ack

Emitted when an ack event occurrs on message type.

Parameters

NameTypeOptionalDescription

message

|

Message

|

|

The message that was affected

| |

ack

|

MessageAck

|

|

The new ACK value

|

message_ciphertext

Emitted when a message is received as ciphertext (not yet decrypted)

Parameter

NameTypeOptionalDescription

message

|

Message

|

| |

message_ciphertext_failed

Emitted when a ciphertext message failed to decrypt after recovery attempt

Parameter

NameTypeOptionalDescription

message

|

Message

|

| |

message_create

Emitted when a new message is created, which may include the current user's own messages.

Parameter

NameTypeOptionalDescription

message

|

Message

|

|

The message that was created

|

message_edit

Emitted when messages are edited

Parameters

NameTypeOptionalDescription

message

|

Message

|

| | |

newBody

|

string

|

| | |

prevBody

|

string

|

| |

message_reaction

Emitted when a reaction is sent, received, updated or removed

Parameters

NameTypeOptionalDescription

reaction

|

object

|

|

Values in reaction have the following properties:

NameTypeOptionalDescription

id

|

object

|

|

Reaction id

| |

orphan

|

number

|

|

Orphan

| |

orphanReason

|

string

|

|

Orphan reason

Value can be null.

| |

timestamp

|

number

|

|

Timestamp

| |

reaction

|

string

|

|

Reaction

| |

read

|

boolean

|

|

Read

| |

msgId

|

object

|

|

Parent message id

| |

senderId

|

string

|

|

Sender id

| |

ack

|

number

|

|

Ack

Value can be null.

|

|

message_revoke_everyone

Emitted when a message is deleted for everyone in the chat.

Parameters

NameTypeOptionalDescription

message

|

Message

|

|

The message that was revoked, in its current state. It will not contain the original message's data.

| |

revoked_msg

|

Message

|

|

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

NameTypeOptionalDescription

message

|

Message

|

|

The message that was revoked

|

qr

Emitted when a QR code is received

Parameter

NameTypeOptionalDescription

qr

|

string

|

|

QR Code

|

ready

Emitted when the client has initialized and is ready to receive messages.

vote_update

Emitted when some poll option is selected or deselected, shows a user's current selected option(s) on the poll