wppconnect-team / wppconnect

WPPConnect is an open source project developed by the JavaScript community with the aim of exporting functions from WhatsApp Web to the node, which can be used to support the creation of any interaction, such as customer service, media sending, intelligence recognition based on phrases artificial and many other things, use your imagination
https://wppconnect.io
Other
1.86k stars 330 forks source link

The function addOrRemoveLabels of Whatsapp is no working #2185

Closed kevin-guerrero808 closed 3 months ago

kevin-guerrero808 commented 4 months ago

Description

The function addOrRemoveLabels of Whatsapp is no working that is to say it don't add labels to chats in whatsapp and don't say anything in the response.

Other important thing is that the documentation say it receives two params chatIds and options as strings but the example display that it need to arrays

Documentation from wwppconnect.io:

addOrRemoveLabels

addOrRemoveLabels(chatIds, options): Promise<void>

Add or delete label of chatId

Parameters
Returns Promise

Example

client.addOrRemoveLabels(['[number]@c.us','[number]@c.us'],
[{labelId:'76', type:'add'},{labelId:'75', type:'remove'}]);
//or

Environment

My code example

client.addOrRemoveLabels([message.from], [{labelId:"Pendiente", type:'add'}]).then(response => {
  console.log('Labels added successfully:', response);
}).catch(error => {
  console.error('Error adding labels:', error);
});

The response generated is empty

Expected result

The function must say the correct params and types and the result is to see the labels applied to the chats

icleitoncosta commented 3 months ago

Hi @kevin-guerrero808 you can get the labels id with client.getAllLabels() And pass the id for function that way:

I will fix the docs

{
  "chatIds": [
    "5521[number_replace]@c.us"
  ],
  "options": [
    {
      "labelId": "20",
      "type": "add"
    },
    {
      "labelId": "17",
      "type": "remove"
    }
  ]
}
kevin-guerrero808 commented 3 months ago

Hello @icleitoncosta! I found that I can use client.addOrRemoveLabels with two array arguments, [<chatNumber>] and [{labelId: <id>, type: <add|remove>] and it works, althouth I set ts-ignore becuase the typescript definition expect two strings as arguments.

Code example

// @ts-ignore
client.addOrRemoveLabels([`${message.from}`],[{labelId:'12', type:'add'}]);

I hope that you update the typescript definition and documentation parameters

Thanks!