pedroslopez / whatsapp-web.js

A WhatsApp client library for NodeJS that connects through the WhatsApp Web browser app
https://wwebjs.dev
Apache License 2.0
15.58k stars 3.72k forks source link

Label hexColor property is aways undefined #2992

Open douglasnoas opened 7 months ago

douglasnoas commented 7 months ago

Is there an existing issue for this?

Describe the bug

var labels = await client.getLabels();
labels[0].hexColor //undefined

whatsapp is now using colorIndex

Expected behavior

label.hexColor should not be undefined

Steps to Reproduce the Bug or Issue

Just use client.getLabels to get a Label[] list

Relevant Code

No response

Browser Type

Chromium

WhatsApp Account Type

WhatsApp Business

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

anywhere

Additional context

suggestion fix for Label.js adding a local color table

'use strict';

const Base = require('./Base');
// eslint-disable-next-line no-unused-vars
const Chat = require('./Chat');

const Colors = [
    "#ff9485",
    "#64c4ff",
    "#ffd429",
    "#dfaef0",
    "#99b6c1",
    "#55ccb3",
    "#ff9dff",
    "#d3a91d",
    "#6d7cce",
    "#d7e752",
    "#00d0e2",
    "#ffc5c7",
    "#93ceac",
    "#f74848",
    "#00a0f2",
    "#83e422",
    "#ffaf04",
    "#b5ebff",
    "#9ba6ff",
    "#9368cf"
]

/**
 * WhatsApp Business Label information
 */
class Label extends Base {
    /**
     * @param {Base} client
     * @param {object} labelData
     */
    constructor(client, labelData){
        super(client);

        if(labelData) this._patch(labelData);
    }

    _patch(labelData){
        /**
         * Label ID
         * @type {string}
         */
        this.id = labelData.id;

        /**
         * Label name
         * @type {string}
         */
        this.name = labelData.name;

        /**
         * Label hex color
         * @type {string}
         */
        this.hexColor = Colors[labelData.colorIndex];
    }
    /**
     * Get all chats that have been assigned this Label
     * @returns {Promise<Array<Chat>>}
     */
    async getChats(){
        return this.client.getChatsByLabelId(this.id);
    }

}

module.exports = Label;
N0N4M3BNS commented 1 week ago

no update about this bug?