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.59k forks source link

Send Message To Group Not Send #3248

Closed BCIGRA closed 3 weeks ago

BCIGRA commented 3 weeks ago

Is there an existing issue for this?

Describe the bug

The message is not sent to the group with ID xxxxxxxxxxxxxxx@g.us. Although the system displays the message as "sent," it does not actually get delivered in WhatsApp.

// Send message Group group with ID xxxxxxxxxxxxxxx@g.us.
Message {
  _data: {
    id: {
      fromMe: true,
      remote: 'xxxxxxxxxxxxxxxxxxxx@g.us',
      id: '3EB0BE22C74D2E8ABA2B84',
      participant: [Object],
      _serialized: 'true_xxxxxxxxxxxxxxxxxxxx@g.us_3EB0BE22C74D2E8ABA2B84_xxxxxxxxxxxxxxxxxxxx@c.us'
    },
    viewed: false,
    body: 'test',
    type: 'chat',
    t: 1724084304,
    from: {
      server: 'c.us',
      user: 'xxxxxxxxxxxxxxxxxxxx',
      _serialized: 'xxxxxxxxxxxxxxxxxxxx@c.us'
    },
    to: {
      server: 'g.us',
      user: 'xxxxxxxxxxxxxxxxxxxx',
      _serialized: 'xxxxxxxxxxxxxxxxxxxx@g.us'
    },
    ack: 0,
    isNewMsg: true,
    star: false,
    kicNotified: false,
    isFromTemplate: false,
    pollInvalidated: false,
    isSentCagPollCreation: false,
    latestEditMsgKey: null,
    latestEditSenderTimestampMs: null,
    mentionedJidList: [],
    groupMentions: [],
    isEventCanceled: false,
    eventInvalidated: false,
    isVcardOverMmsDocument: false,
    isForwarded: false,
    labels: [],
    hasReaction: false,
    productHeaderImageRejected: false,
    lastPlaybackProgress: 0,
    isDynamicReplyButtonsMsg: false,
    isCarouselCard: false,
    parentMsgId: null,
    isMdHistoryMsg: false,
    stickerSentTs: 0,
    isAvatar: false,
    lastUpdateFromServerTs: 0,
    invokedBotWid: null,
    bizBotType: null,
    botResponseTargetId: null,
    botPluginType: null,
    botPluginReferenceIndex: null,
    botPluginSearchProvider: null,
    botPluginSearchUrl: null,
    botPluginSearchQuery: null,
    botPluginMaybeParent: false,
    botReelPluginThumbnailCdnUrl: null,
    botMsgBodyType: null,
    requiresDirectConnection: null,
    bizContentPlaceholderType: null,
    hostedBizEncStateMismatch: false,
    senderOrRecipientAccountTypeHosted: false,
    placeholderCreatedWhenAccountIsHosted: false,
    links: []
  },
  mediaKey: undefined,
  id: {
    fromMe: true,
    remote: 'xxxxxxxxxxxxxxxxxxxx@g.us',
    id: '3EB0BE22C74D2E8ABA2B84',
    participant: {
      server: 'c.us',
      user: 'xxxxxxxxxxxxxx',
      _serialized: 'xxxxxxxxxxxxxxxxxxxx@c.us'
    },
    _serialized: 'true_xxxxxxxxxxxxxxxxxxxx@g.us_3EB0BE22C74D2E8ABA2B84_xxxxxxxxxxxxxx@c.us'
  },
  ack: 0,
  hasMedia: false,
  body: 'test',
  type: 'chat',
  timestamp: 1724084304,
  from: 'xxxxxxxxxxxxxx@c.us',
  to: 'xxxxxxxxxxxxxxxxxxxx@g.us',
  author: undefined,
  deviceType: 'android',
  isForwarded: false,
  forwardingScore: 0,
  isStatus: false,
  isStarred: false,
  broadcast: undefined,
  fromMe: true,
  hasQuotedMsg: false,
  hasReaction: false,
  duration: undefined,
  location: undefined,
  vCards: [],
  inviteV4: undefined,
  mentionedIds: [],
  groupMentions: [],
  orderId: undefined,
  token: undefined,
  isGif: false,
  isEphemeral: undefined,
  links: []
}

// Send message Group group with ID xxxxxxxxxxxxx-xxxxxxxxxxxxxxx@g.us.
Message {
  _data: {
    id: {
      fromMe: true,
      remote: 'xxxxxxxxxxxxx-xxxxxxxxxxxxxxx@g.us',
      id: '3EB0943FCA856B16343DB6',
      participant: [Object],
      _serialized: 'true_xxxxxxxxxxxxx-xxxxxxxxxxxxxxx@g.us_3EB0943FCA856B16343DB6_xxxxxxxxxxxxx@c.us'
    },
    viewed: false,
    body: 'Mantap',
    type: 'chat',
    t: 1724085242,
    from: {
      server: 'c.us',
      user: 'xxxxxxxxxxxxx',
      _serialized: 'xxxxxxxxxxxxx@c.us'
    },
    to: {
      server: 'g.us',
      user: 'xxxxxxxxxxxxx-xxxxxxxxxxxxxxx',
      _serialized: 'xxxxxxxxxxxxx-xxxxxxxxxxxxxxx@g.us'
    },
    ack: 0,
    isNewMsg: true,
    star: false,
    kicNotified: false,
    isFromTemplate: false,
    pollInvalidated: false,
    isSentCagPollCreation: false,
    latestEditMsgKey: null,
    latestEditSenderTimestampMs: null,
    mentionedJidList: [],
    groupMentions: [],
    isEventCanceled: false,
    eventInvalidated: false,
    isVcardOverMmsDocument: false,
    isForwarded: false,
    labels: [],
    hasReaction: false,
    productHeaderImageRejected: false,
    lastPlaybackProgress: 0,
    isDynamicReplyButtonsMsg: false,
    isCarouselCard: false,
    parentMsgId: null,
    isMdHistoryMsg: false,
    stickerSentTs: 0,
    isAvatar: false,
    lastUpdateFromServerTs: 0,
    invokedBotWid: null,
    bizBotType: null,
    botResponseTargetId: null,
    botPluginType: null,
    botPluginReferenceIndex: null,
    botPluginSearchProvider: null,
    botPluginSearchUrl: null,
    botPluginSearchQuery: null,
    botPluginMaybeParent: false,
    botReelPluginThumbnailCdnUrl: null,
    botMsgBodyType: null,
    requiresDirectConnection: null,
    bizContentPlaceholderType: null,
    hostedBizEncStateMismatch: false,
    senderOrRecipientAccountTypeHosted: false,
    placeholderCreatedWhenAccountIsHosted: false,
    links: []
  },
  mediaKey: undefined,
  id: {
    fromMe: true,
    remote: 'xxxxxxxxxxxxx-xxxxxxxxxxxxxxx@g.us',
    id: '3EB0943FCA856B16343DB6',
    participant: {
      server: 'c.us',
      user: 'xxxxxxxxxxxxx',
      _serialized: 'xxxxxxxxxxxxx@c.us'
    },
    _serialized: 'true_xxxxxxxxxxxxx-xxxxxxxxxxxxxxx@g.us_3EB0943FCA856B16343DB6_xxxxxxxxxxxxx@c.us'
  },
  ack: 0,
  hasMedia: false,
  body: 'Mantap',
  type: 'chat',
  timestamp: 1724085242,
  from: 'xxxxxxxxxxxxx@c.us',
  to: 'xxxxxxxxxxxxx-xxxxxxxxxxxxxxx@g.us',
  author: undefined,
  deviceType: 'android',
  isForwarded: false,
  forwardingScore: 0,
  isStatus: false,
  isStarred: false,
  broadcast: undefined,
  fromMe: true,
  hasQuotedMsg: false,
  hasReaction: false,
  duration: undefined,
  location: undefined,
  vCards: [],
  inviteV4: undefined,
  mentionedIds: [],
  groupMentions: [],
  orderId: undefined,
  token: undefined,
  isGif: false,
  isEphemeral: undefined,
  links: []
}

Expected behavior

I hope this problem can be resolved

Steps to Reproduce the Bug or Issue

// POST -> https://silver-space-xxxxxxxxxxxxx-3000.app.github.dev/api/v1.0/sendgroup/62xxxxxxx/1203xxxxx
// payload: {"message":"halo","groupName":"Group WEB"}
// Response: {
//    "status": "success",
//    "message": "Message successfully sent to group xxxxxxxxxxxxx@g.us"
// }

// note: We can get a successful send response but the reality is that on WhatsApp it wasn't sent

Relevant Code

export const sendGroup = async (req: Request, res: Response) => {
    const { sessionID, groupID } = req.params;
    const { message } = req.body;

    if (!groupID || !message) {
        return res.status(400).json({ status: 'error', message: 'Please enter a valid groupID and message' });
    }

    const sessionClient = SessionClient.getClient(sessionID);
    if (!sessionClient) {
        return res.status(500).json({ status: 'error', message: 'Client not found' });
    }

    const client = sessionClient.getWhatsAppClient();

  try {
        // Mengirim pesan ke grup jika grup valid
        const response = await client.sendMessage(groupID + '@g.us', message);
        console.log('Message Response:', response);

        if (response.id.fromMe) {
            res.json({ status: 'success', message: `Message successfully sent to group ${groupID + '@g.us'}` });
        } else {
            res.status(500).json({ status: 'error', message: `Message not sent from this client to group ${groupID + '@g.us'}` });
        }
    } catch (error) {
        console.error('Grup tidak ditemukan atau tidak valid:', error);
        return res.status(400).json({ status: 'error', message: 'Grup tidak ditemukan atau tidak valid' });
    }
};

Browser Type

Google Chrome

WhatsApp Account Type

WhatsApp Business

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

OS: Ubuntu 22 Phone OS: Android whatsapp-web.js version: v1.25.0 WhatsApp Web version: 2.3000.1015783013 Node.js Version: v20.15.1

Additional context

Send Message To Group

Message sent successfully to xxxxxxxxxxx-1630427396@g.us. Message failed to send to XXXXXXXXXXXXXXXX@g.us.

BCIGRA commented 3 weeks ago

I've identified the issue. It seems that the problem was due to the group having fewer than 5 members, which prevented messages from being sent. When I created a group with more than 5 members, the messages were successfully delivered.

Thank you, and I apologize for any inconvenience.