#Group Chat

5 messages · Page 1 of 1 (latest)

frosty fable
#

I am trying to send a message to a group using below code. The code works fine, however dont see message in the group.

const { Client } = require('whatsapp-web.js');
const qrcode = require('qrcode-terminal');

// Initialize the client
const client = new Client();

// Generate QR code and display it
client.on('qr', qr => {
qrcode.generate(qr, { small: true });
console.log('Scan the QR code with your WhatsApp mobile app');
});

// Handle successful authentication
client.on('authenticated', () => {
console.log('Authenticated');
});

// Connect to WhatsApp Web
client.initialize().catch(error => {
console.error('Connection error:', error);
});

// Event listener for successful connection
client.on('ready', () => {
console.log('Connected to WhatsApp Web');

// Now you can perform actions such as sending messages
// For example, sending a message to a group
const groupId = 'group_id';
const message = 'Hello, group!';
client.sendMessage(groupId, message).then(() => {
console.log('Message sent successfully');
// Disconnect from WhatsApp Web
client.destroy().then(() => {
console.log('Disconnected from WhatsApp Web');
});
}).catch(error => {
console.error('Failed to send message:', error);
// Disconnect from WhatsApp Web
client.destroy().then(() => {
console.log('Disconnected from WhatsApp Web');
});
});
});

// Event listener for connection errors
client.on('auth_failure', () => {
console.error('Authentication failure. Please check your credentials or session file.');
});
client.on('disconnected', reason => {
console.log('Disconnected from WhatsApp Web:', reason);
});

late flare
#

group id should be with @g.us

frosty fable
#

Didn't wanted to share with the community, hence mentioned gorup_id as quoted. Yes, using @g.us as group id. Problem is everything goes well, but couldn't see message in the group. See the log below.

"Scan the QR code with your WhatsApp mobile app
Authenticated
Connected to WhatsApp Web
Message sent successfully
Disconnected from WhatsApp Web"

late flare
#

it error form the library i think