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.05k stars 3.58k forks source link

SetDescription method doesn't work! #2238

Closed grossialex closed 9 months ago

grossialex commented 1 year ago

Is there an existing issue for this?

Describe the bug

When I try to use setDescription method (https://docs.wwebjs.dev/GroupChat.html#setDescription) doesn't work as expected.

Expected behavior

    it('can change the group description', async function () {
        expect(group.description).to.equal(undefined);
        const res = await group.setDescription('some description');
        expect(res).to.equal(true);
        expect(group.description).to.equal('some description');

        await helper.sleep(1000);

        // reload
        group = await client.getChatById(group.id._serialized); 
        expect(group.description).to.equal('some description');
    });

Steps to Reproduce the Bug or Issue

if (msg.body.startsWith('!desc ')) { // Change the group description let chat = await msg.getChat(); if (chat.isGroup) { let newDescription = msg.body.slice(6);
chat.setDescription(newDescription); } else { msg.reply('This command can only be used in a group!'); }

Relevant Code

No response

Browser Type

Google Chrome

WhatsApp Account Type

WhatsApp Business

Does your WhatsApp account have multidevice enabled?

No, I am not using Multi Device

Environment

OS: Ubuntu 22.04.2 Phone OS: Android 12 whatsapp-web.js version: 1.21.0 WhatsApp Web version: 2.2322.15 node version: 20.1.0

Additional context

No response

PurpShell commented 1 year ago

Does the method not actually change the description or does it simply not update from the client side? I am assuming the former, I'll get working on it.

msalva13 commented 1 year ago

Hello, I am experiencing the same issue here.

This is my code:

// this line is perfectly working, I am using the returned chat const for other methods as well
const chat = await client.getChatById(groupChat.gid._serialized)

// this function is running but never returns, it also won't throw an error
await chat.setDescription(description)

I tried to resolve it myself but failed. However, I figured this in structure GroupChat.js: await this.client.pupPage.evaluate <- it's callback function does not get called for some reason.

async setDescription(description) {
        const success = await this.client.pupPage.evaluate(async (chatId, description) => {
            // this code is not getting executed
            const chatWid = window.Store.WidFactory.createWid(chatId);
            let descId = window.Store.GroupMetadata.get(chatWid).descId;
            try {
                await window.Store.GroupUtils.setGroupDescription(chatWid, description, window.Store.MsgKey.newId(), descId);
                return true;
            } catch (err) {
                if(err.name === "ServerStatusCodeError") return false;
                throw err;
            }
        }, this.id._serialized, description);

        if(!success) return false;
        this.groupMetadata.desc = description;
        return true;
    }
marlon33 commented 1 year ago

the method doesn't work yet, any ideia?

Halphas commented 1 year ago

well if you change await window.Store.GroupUtils.setGroupDescription(chatWid, description, window.Store.MsgKey.newId(), descId); to await window.Store.GroupUtils.setGroupDescription(chatWid, description);

it works but u can never change the description again muhahahahha so i dont know what setGroupDescription is expecting. i see its loaded but i cant find any interface description unfortunatelly

alechkos commented 9 months ago

Fixed in #2295