Class: Client
Methods
B() insiders
B(
chatId
,payload
):Promise
<MessageId
>
Use this link to get the correct license.
Buttons are broken for the foreseeable future. Please DO NOT get a license solely for access to buttons. They are no longer reliable due to recent changes at WA.
Use a raw payload within your open-wa session
Parameters
• chatId: ChatId
• payload
returns: MessageId
Returns
Promise
<MessageId
>
Example
If there is a code block, then both TypeDoc and VSCode will treat text outside of the code block as regular text.
await B('44123456789@c.us', {
test: 1
})
acceptGroupJoinRequest()
acceptGroupJoinRequest(
messageId
):Promise
<boolean
>
Accepts a request from a recipient to join a group. Takes the message ID of the request message.
Parameters
• messageId: MessageId
Returns
Promise
<boolean
>
addLabel()
addLabel(
label
,chatId
):Promise
<boolean
>
Adds label from chat, message or contact. Only for business accounts.
Parameters
• label: string
• chatId: ChatId
Returns
Promise
<boolean
>
addParticipant()
addParticipant(
groupId
,participantId
):Promise
<boolean
>
Add participant to Group
If not a group chat, returns NOT_A_GROUP_CHAT
.
If the chat does not exist, returns GROUP_DOES_NOT_EXIST
If the participantId does not exist in the contacts, returns NOT_A_CONTACT
If the host account is not an administrator, returns INSUFFICIENT_PERMISSIONS
Parameters
• groupId: GroupChatId
• participantId: ContactId
| ContactId
[]
Returns
Promise
<boolean
>
approveGroupJoinRequest()
approveGroupJoinRequest(
groupChatId
,contactId
):Promise
<string
|boolean
>
Approves a group join request
Parameters
• groupChatId: GroupChatId
The group chat id
• contactId: ContactId
The contact id of the person who is requesting to join the group
Returns
Promise
<string
| boolean
>
Promise<boolean>
archiveChat()
archiveChat(
id
,archive
):Promise
<boolean
>
Parameters
• id: ChatId
The id of the conversation
• archive: boolean
boolean true => archive, false => unarchive
Returns
Promise
<boolean
>
boolean true: worked, false: didnt work (probably already in desired state)
autoReject()
autoReject(
message
?):Promise
<boolean
>
Automatically reject calls on the host account device. Please note that the device that is calling you will continue to ring.
Update: Due to the nature of MD, the host account will continue ringing.
Parameters
• message?: string
optional message to send to the calling account when their call is detected and rejected
Returns
Promise
<boolean
>
awaitMessages()
awaitMessages(
c
,filter
,options
?):Promise
<Collection
<string
,Message
>>
[FROM DISCORDJS] Similar to createMessageCollector but in promise form. Resolves with a collection of messages that pass the specified filter.
Parameters
The Mesasge/Chat or Chat Id to base this message colletor on
• filter: CollectorFilter
<[Message
]>
The filter function to use
• options?: AwaitMessagesOptions
= {}
Optional options to pass to the internal collector
Returns
Promise
<Collection
<string
, Message
>>
Example
// Await !vote messages
const filter = m => m.body.startsWith('!vote');
// Errors: ['time'] treats ending because of the time limit as an error
channel.awaitMessages(filter, { max: 4, time: 60000, errors: ['time'] })
.then(collected => console.log(collected.size))
.catch(collected => console.log(`After a minute, only ${collected.size} out of 4 voted.`));
checkNumberStatus()
checkNumberStatus(
contactId
):Promise
<NumberCheck
>
Checks if a number is a valid WA number
Parameters
• contactId: ContactId
Returns
Promise
<NumberCheck
>
checkReadReceipts() insiders
checkReadReceipts(
contactId
):Promise
<string
|boolean
>
Use this link to get the correct license.
Check if a recipient has read receipts on.
This will only work if you have chats sent back and forth between you and the contact 1-1.
Parameters
• contactId: ContactId
The Id of the contact with which you have an existing conversation with messages already.
Returns
Promise
<string
| boolean
>
Promise<string | boolean>
true or false or a string with an explaintaion of why it wasn't able to determine the read receipts.
clearAllChats()
clearAllChats(
ts
?):Promise
<boolean
>
Clears all chats of all messages. This does not delete chats. Please be careful with this as it will remove all messages from whatsapp web and the host device. This feature is great for privacy focussed bots.
Parameters
• ts?: number
number A chat that has had a message after ts (epoch timestamp) will not be cleared.
Returns
Promise
<boolean
>
clearChat()
clearChat(
chatId
):Promise
<boolean
>
Delete all messages from the chat.
Parameters
• chatId: ChatId
Returns
Promise
<boolean
>
boolean
contactBlock()
contactBlock(
id
):Promise
<boolean
>
Block contact
Parameters
• id: ContactId
Returns
Promise
<boolean
>
contactUnblock()
contactUnblock(
id
):Promise
<boolean
>
Unblock contact
Parameters
• id: ContactId
Returns
Promise
<boolean
>
createCommunity() insiders
createCommunity(
communityName
,communitySubject
,icon
,existingGroups
,newGroups
?):Promise
<`${number}@g.us`>
Use this link to get the correct license.
Create a new community
Parameters
• communityName: string
The community name
• communitySubject: string
• icon: DataURL
DataURL of a 1:1 ratio jpeg for the community icon
• existingGroups: GroupChatId
[] = []
An array of existing group IDs, that are not already part of a community, to add to this new community.
• newGroups?: NewCommunityGroup
[]
An array of new group objects that
Returns
Promise
<`${number}@g.us`>
createGroup()
createGroup(
groupName
,contacts
):Promise
<GroupChatCreationResponse
>
Create a group and add contacts to it
Parameters
• groupName: string
group name: 'New group'
• contacts: ContactId
| ContactId
[]
Returns
Promise
<GroupChatCreationResponse
>
createLabel() insiders
createLabel(
label
):Promise
<string
|boolean
>
Use this link to get the correct license.
Adds label from chat, message or contact. Only for business accounts.
Parameters
• label: string
Returns
Promise
<string
| boolean
>
false
if something went wrong, or the id (usually a number as a string) of the new label (for example "58"
)
createMessageCollector()
createMessageCollector(
c
,filter
,options
):MessageCollector
Returns a new message collector for the chat which is related to the first parameter c
Parameters
The Mesasge/Chat or Chat Id to base this message colletor on
• filter: CollectorFilter
<[Message
]>
A function that consumes a [Message] and returns a boolean which determines whether or not the message shall be collected.
• options: CollectorOptions
The options for the collector. For example, how long the collector shall run for, how many messages it should collect, how long between messages before timing out, etc.
Returns
createNewProduct() insiders
createNewProduct(
name
,price
,currency
,images
,description
,url
?,internalId
?,isHidden
?):Promise
<Product
>
Use this link to get the correct license.
Add a product to your catalog
Parameters
• name: string
The name of the product
• price: number
The price of the product
• currency: string
The 3-letter currenct code for the product
• images: string
[]
An array of dataurl or base64 strings of product images, the first image will be used as the main image. At least one image is required.
• description: string
optional, the description of the product
• url?: string
The url of the product for more information
• internalId?: string
The internal/backoffice id of the product
• isHidden?: boolean
Whether or not the product is shown publicly in your catalog
Returns
Promise
<Product
>
product object
cutChatCache()
cutChatCache():
Promise
<object
>
This simple function halves the amount of chats in your session message cache. This does not delete messages off your phone. If over a day you've processed 4000 messages this will possibly result in 4000 messages being present in your session.
Calling this method will cut the message cache as much as possible, reducing the memory usage of your process.
You should use this in conjunction with getAmountOfLoadedMessages
to intelligently control the session message cache.
Returns
Promise
<object
>
after
after:
object
after.chats
chats:
number
after.msgs
msgs:
number
before
before:
object
before.chats
chats:
number
before.msgs
msgs:
number
cutMsgCache()
cutMsgCache():
Promise
<number
>
This simple function halves the amount of messages in your session message cache. This does not delete messages off your phone. If over a day you've processed 4000 messages this will possibly result in 4000 messages being present in your session.
Calling this method will cut the message cache to 2000 messages, therefore reducing the memory usage of your process.
You should use this in conjunction with getAmountOfLoadedMessages
to intelligently control the session message cache.
Returns
Promise
<number
>
darkMode()
darkMode(
activate
):Promise
<boolean
>
Start dark mode [NOW GENERALLY AVAILABLE]
Parameters
• activate: boolean
true to activate dark mode, false to deactivate
Returns
Promise
<boolean
>
decryptMedia()
decryptMedia(
message
):Promise
<DataURL
>
Decrypts a media message.
Parameters
• message: MessageId
| Message
This can be the serialized [[MessageId]] or the whole [[Message]] object. It is advised to just use the serialized message ID.
Returns
Promise
<DataURL
>
Promise<[[DataURL]]>
deleteAllStatus()
deleteAllStatus():
Promise
<boolean
>
Alias for deleteStory
Returns
Promise
<boolean
>
deleteAllStories() restricted
deleteAllStories():
Promise
<boolean
>
Use this link to get the correct license.
Deletes all your existing stories.
Returns
Promise
<boolean
>
boolean. True if it worked.
deleteChat()
deleteChat(
chatId
):Promise
<boolean
>
Delete the conversation from your WA
Parameters
• chatId: ChatId
Returns
Promise
<boolean
>
boolean
deleteMessage()
deleteMessage(
chatId
,messageId
,onlyLocal
):Promise
<void
>
Deletes message of given message id
Parameters
• chatId: ChatId
The chat id from which to delete the message.
• messageId: MessageId
| MessageId
[]
The specific message id of the message to be deleted
• onlyLocal: boolean
= false
If it should only delete locally (message remains on the other recipienct's phone). Defaults to false.
Returns
Promise
<void
>
nothing
deleteStaleChats()
deleteStaleChats(
startingFrom
?):Promise
<boolean
>
Deletes chats from a certain index (default 1000). E.g if this startingFrom param is 100
then all chats from index 100
onwards will be deleted.
Parameters
• startingFrom?: number
the chat index to start from. Please do not set this to anything less than 10 @default: 1000
Returns
Promise
<boolean
>
deleteStatus()
deleteStatus(
statusesToDelete
):Promise
<boolean
>
Alias for deleteStory
Parameters
• statusesToDelete: string
| string
[]
Returns
Promise
<boolean
>
deleteStory() restricted
deleteStory(
statusesToDelete
):Promise
<boolean
>
Use this link to get the correct license.
Consumes a list of id strings of stories to delete.
Parameters
• statusesToDelete: string
| string
[]
string [] | string an array of ids of stories to delete.
Returns
Promise
<boolean
>
boolean. True if it worked.
demoteParticipant()
demoteParticipant(
groupId
,participantId
):Promise
<boolean
>
Demote Admin of Group
If not a group chat, returns NOT_A_GROUP_CHAT
.
If the chat does not exist, returns GROUP_DOES_NOT_EXIST
If the participantId does not exist in the group chat, returns NOT_A_PARTICIPANT
If the host account is not an administrator, returns INSUFFICIENT_PERMISSIONS
Parameters
• groupId: GroupChatId
• participantId: ContactId
| ContactId
[]
Returns
Promise
<boolean
>
download()
download(
url
,optionsOverride
):Promise
<DataURL
>
A convinience method to download the [[DataURL]] of a file
Parameters
• url: string
The url
• optionsOverride: any
= {}
You can use this to override the axios request config
Returns
Promise
<DataURL
>
Promise<DataURL>
downloadFileWithCredentials()
downloadFileWithCredentials(
url
):Promise
<Base64
>
Download via the browsers authenticated session via URL.
Parameters
• url: string
Returns
Promise
<Base64
>
base64 string (non-data url)
downloadProfilePicFromMessage()
downloadProfilePicFromMessage(
message
):Promise
<Base64
>
Download profile pics from the message object.
const filename = `profilepic_${message.from}.jpeg`;
const data = await client.downloadProfilePicFromMessage(message);
const dataUri = `data:image/jpeg;base64,${data}`;
fs.writeFile(filename, mData, 'base64', function(err) {
if (err) {
return console.log(err);
}
console.log('The file was saved!');
});
Parameters
• message: Message
Returns
Promise
<Base64
>
editMessage()
editMessage(
messageId
,text
):Promise
<boolean
|MessageId
>
NOTE: This is experimental, most accounts do not have access to this feature in their apps.
Edit an existing message
Parameters
• messageId: MessageId
The message ID to edit
• text: Content
The new text content
Returns
Promise
<boolean
| MessageId
>
editProduct() insiders
editProduct(
productId
,name
?,price
?,currency
?,images
?,description
?,url
?,internalId
?,isHidden
?):Promise
<Product
>
Use this link to get the correct license.
Edit a product in your catalog
Parameters
• productId: string
The catalog ID of the product
• name?: string
The name of the product
• price?: number
The price of the product
• currency?: string
The 3-letter currenct code for the product
• images?: DataURL
[]
An array of dataurl or base64 strings of product images, the first image will be used as the main image. At least one image is required.
• description?: string
optional, the description of the product
• url?: string
The url of the product for more information
• internalId?: string
The internal/backoffice id of the product
• isHidden?: boolean
Whether or not the product is shown publicly in your catalog
Returns
Promise
<Product
>
product object
emitUnreadMessages()
emitUnreadMessages():
Promise
<MessageId
[]>
Fires all unread messages to the onMessage listener. Make sure to call this AFTER setting your listeners.
Returns
Promise
<MessageId
[]>
array of message IDs