feat: pin/unpin messages (#2692)
* feat: add Message.pin and Message.unpin methods * feat: added usage example * docs: clarifications
This commit is contained in:
parent
2100853727
commit
8d683a668b
4 changed files with 56 additions and 1 deletions
23
example.js
23
example.js
|
|
@ -376,14 +376,35 @@ client.on('message', async msg => {
|
|||
requesterIds: ['number1@c.us', 'number2@c.us'],
|
||||
sleep: null
|
||||
});
|
||||
} else {
|
||||
/**
|
||||
* Pins a message in a chat, a method takes a number in seconds for the message to be pinned.
|
||||
* WhatsApp default values for duration to pass to the method are:
|
||||
* 1. 86400 for 24 hours
|
||||
* 2. 604800 for 7 days
|
||||
* 3. 2592000 for 30 days
|
||||
* You can pass your own value:
|
||||
*/
|
||||
const result = await msg.pin(60); // Will pin a message for 1 minute
|
||||
console.log(result); // True if the operation completed successfully, false otherwise
|
||||
}
|
||||
});
|
||||
|
||||
client.on('message_create', (msg) => {
|
||||
client.on('message_create', async (msg) => {
|
||||
// Fired on all message creations, including your own
|
||||
if (msg.fromMe) {
|
||||
// do stuff here
|
||||
}
|
||||
|
||||
// Unpins a message
|
||||
if (msg.fromMe && msg.body.startsWith('!unpin')) {
|
||||
const pinnedMsg = await msg.getQuotedMessage();
|
||||
if (pinnedMsg) {
|
||||
// Will unpin a message
|
||||
const result = await pinnedMsg.unpin();
|
||||
console.log(result); // True if the operation completed successfully, false otherwise
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
client.on('message_ciphertext', (msg) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue