mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-21 21:19:16 +00:00
[+] New message_create event that is fired on all message creations.
A new property "fromMe" has also been added to messages. Close #8
This commit is contained in:
@@ -84,6 +84,13 @@ client.on('message', async msg => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
client.on('message_create', (msg) => {
|
||||||
|
// Fired on all message creations, including your own
|
||||||
|
if(msg.fromMe) {
|
||||||
|
// do stuff here
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
client.on('disconnected', () => {
|
client.on('disconnected', () => {
|
||||||
console.log('Client was logged out');
|
console.log('Client was logged out');
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -107,8 +107,11 @@ class Client extends EventEmitter {
|
|||||||
|
|
||||||
// Register events
|
// Register events
|
||||||
await page.exposeFunction('onAddMessageEvent', msg => {
|
await page.exposeFunction('onAddMessageEvent', msg => {
|
||||||
|
const message = new Message(this, msg);
|
||||||
|
this.emit(Events.MESSAGE_CREATE, message);
|
||||||
|
|
||||||
if (msg.id.fromMe || !msg.isNewMsg) return;
|
if (msg.id.fromMe || !msg.isNewMsg) return;
|
||||||
this.emit(Events.MESSAGE_CREATE, new Message(this, msg));
|
this.emit(Events.MESSAGE_RECEIVED, message);
|
||||||
});
|
});
|
||||||
|
|
||||||
await page.exposeFunction('onConnectionChangedEvent', (conn, connected) => {
|
await page.exposeFunction('onConnectionChangedEvent', (conn, connected) => {
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ class Message extends Base {
|
|||||||
this.author = data.author;
|
this.author = data.author;
|
||||||
this.isForwarded = data.isForwarded;
|
this.isForwarded = data.isForwarded;
|
||||||
this.broadcast = data.broadcast;
|
this.broadcast = data.broadcast;
|
||||||
|
this.fromMe = data.id.fromMe;
|
||||||
|
|
||||||
return super._patch(data);
|
return super._patch(data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ exports.Events = {
|
|||||||
AUTHENTICATED: 'authenticated',
|
AUTHENTICATED: 'authenticated',
|
||||||
AUTHENTICATION_FAILURE: 'auth_failure',
|
AUTHENTICATION_FAILURE: 'auth_failure',
|
||||||
READY: 'ready',
|
READY: 'ready',
|
||||||
MESSAGE_CREATE: 'message',
|
MESSAGE_RECEIVED: 'message',
|
||||||
|
MESSAGE_CREATE: 'message_create',
|
||||||
QR_RECEIVED: 'qr',
|
QR_RECEIVED: 'qr',
|
||||||
DISCONNECTED: 'disconnected'
|
DISCONNECTED: 'disconnected'
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user