#TypeError: whatsappClient.promoteParticipants is not a function

5 messages · Page 1 of 1 (latest)

lyric cobalt
#

Hello,

I am trying to create a group and assign an admin to it, but I am getting an error indicating that the official method either does not exist or is not functioning.

Attached is my code and more information about my problem.

Thank you,
Alex

#

Code:

export const createWhatsAppGroup = async (req, res) => {
  const { groupName, participants, adminNumber } = req.body;
  if (!groupName || !participants || !Array.isArray(participants) || participants.length < 1) {
    return res.status(400).json({ message: "Group name and at least one participant are required" });
  }

  for (const participant of participants) {
    if (!isValidPhoneNumber(participant)) {
      return res.status(400).json({ message: `Invalid phone number format: ${participant}` });
    }
  }

  if (adminNumber && !isValidPhoneNumber(adminNumber)) {
    return res.status(400).json({ message: "Invalid admin number format" });
  }

  if (!whatsappClient.info || !whatsappClient.info.wid) {
    return res.status(500).json({ message: "WhatsApp client is not ready" });
  }

  try {
    const formattedParticipants = participants.map(p => `${p}@c.us`);
    const group = await whatsappClient.createGroup(groupName, formattedParticipants);
    const groupId = group.gid._serialized;

    if (adminNumber) {
      const adminJid = `${adminNumber}@c.us`;
      if (!formattedParticipants.includes(adminJid)) {
        return res.status(400).json({ message: "Admin number must be one of the participants" });
      }
      const result = await whatsappClient.promoteParticipants(groupId, [adminJid]);
      if (result.status !== 200) {
        return res.status(500).json({ message: "Failed to promote participant to admin" });
      }
    }

    res.status(200).json({ message: "Group created successfully", groupId });
  } catch (error) {
    console.error('Failed to create WhatsApp group or assign admin:', error);
    res.status(500).json({ message: "Failed to create WhatsApp group or assign admin" });
  }
};
#

Version "whatsapp-web.js": "github:pedroslopez/whatsapp-web.js#webpack-exodus",

lyric cobalt
#

Hello, any news for this theme? Thanks very much

silent axle
#

Hello, please open an issue on GH if no one has regarding a broken function.