-
Notifications
You must be signed in to change notification settings - Fork 0
/
Massege.js
66 lines (54 loc) · 2.45 KB
/
Massege.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* Copyright (C) 2020 Yusuf Usta.
Licensed under the GPL-3.0 License;
you may not use this file except in compliance with the License.
WhatsAsena - Yusuf Usta
*/
const {MessageType, Presence, MessageOptions} = require('@adiwajshing/baileys');
const Base = require('./Base');
const ReplyMessage = require('./ReplyMessage');
class Message extends Base {
constructor(client, data) {
super(client);
if (data) this._patch(data);
}
_patch(data) {
this.id = data.key.id === undefined ? undefined : data.key.id;
this.jid = data.key.remoteJid;
this.fromMe = data.key.fromMe;
this.message = data.message.extendedTextMessage === null ? data.message.conversation : data.message.extendedTextMessage.text;
this.unreadCount = data.unreadCount;
this.timestamp = typeof(data.messageTimestamp) === 'object' ? data.messageTimestamp.low : data.messageTimestamp;
this.data = data;
if (data.message.hasOwnProperty('extendedTextMessage') &&
data.message.extendedTextMessage.hasOwnProperty('contextInfo') === true &&
data.message.extendedTextMessage.contextInfo.hasOwnProperty('quotedMessage')) {
this.reply_message = new ReplyMessage(this.client, data.message.extendedTextMessage.contextInfo); } else {
this.reply_message = false;
}
if (data.message.hasOwnProperty('extendedTextMessage') &&
data.message.extendedTextMessage.hasOwnProperty('contextInfo') === true &&
data.message.extendedTextMessage.contextInfo.hasOwnProperty('mentionedJid')) {
this.mention = data.message.extendedTextMessage.contextInfo.mentionedJid;
} else {
this.mention = false;
}
return super._patch(data);
}
async delete() {
return await this.client.deleteMessage(this.jid, {id: this.id, remoteJid: this.jid, fromMe: true})
}
async reply(text) {
var message = await this.client.sendMessage(this.jid, text, MessageType.text);
return new Message(this.client, message)
}
async sendMessage(content, type = MessageType.text, options) {
return await this.client.sendMessage(this.jid, content, type, options)
}
async sendTyping() {
return await this.client.updatePresence(this.jid, Presence.composing) ;
}
async sendRead() {
return await this.client.chatRead(this.jid);
}
};
module.exports = Message;