#Add group participants

6 messages · Page 1 of 1 (latest)

subtle cloud
#

Good evening, everyone, how are you?
I need some help, please.

I'm trying to create a way to add a specific member using the code below, but it just keeps loading and doesn't add the member. Where might I be going wrong?

codes:
app.all("/adicionarMembro", async (req, res) => {
console.log("Route /adicionarMembro accessed");

if (!clientReady) {
return res
.status(503)
.json({
success: false,
message:
"WhatsApp client is not ready. Please try again in a few moments.",
});
}

const groupId = "120363047761604633@g.us";
const memberId = "5535991091052@c.us"; /*553591091052@c.us

try {
console.log("Attempting to fetch the chat");
const chat = await client.getChatById(groupId);
console.log("Chat fetched:", chat.id);

if (chat.isGroup) {
  console.log("Attempting to add participant");
  const result = await chat.addParticipants([memberId]);
  console.log("Add result:", result);
  res.json({
    success: true,
    message: "Member successfully added",
    result,
  });
} else {
  console.log("Chat is not a group");
  res
    .status(400)
    .json({ success: false, message: "The chat is not a group" });
}

} catch (error) {
console.error("Error adding member:", error);
res
.status(500)
.json({
success: false,
message: "Error adding member",
error: error.toString(),
});
}
});
/*end codes/

THIS IS HOW IT LOOKS IN THE CONSOLE LOG:

2024-09-25T02:39:44.548Z - GET /adicionarMembro
Route /adicionarMembro accessed
Attempting to fetch the chat
Chat fetched: {
server: 'g.us',
user: '120363047761604633',
_serialized: '120363047761604633@g.us'
}
Attempting to add participant

fathom sleet
#

cara, eu não sei te ajudar mas sugiro que vc post essa duvida em ingles para que as outras pessoas tmb consigam entender

primal tapir
subtle cloud
subtle cloud