@kangwifi-pro/waliwa 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/helpers/defaults.d.ts +102 -0
- package/dist/helpers/defaults.d.ts.map +1 -0
- package/dist/helpers/defaults.js +175 -0
- package/dist/helpers/defaults.js.map +1 -0
- package/dist/helpers/media.d.ts +123 -0
- package/dist/helpers/media.d.ts.map +1 -0
- package/dist/helpers/media.js +246 -0
- package/dist/helpers/media.js.map +1 -0
- package/dist/helpers/message.d.ts +147 -0
- package/dist/helpers/message.d.ts.map +1 -0
- package/dist/helpers/message.js +322 -0
- package/dist/helpers/message.js.map +1 -0
- package/dist/helpers/sticker.d.ts +112 -0
- package/dist/helpers/sticker.d.ts.map +1 -0
- package/dist/helpers/sticker.js +267 -0
- package/dist/helpers/sticker.js.map +1 -0
- package/dist/index.d.ts +28 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +41 -14
- package/dist/index.js.map +1 -1
- package/package.json +13 -2
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Waliwa - MessageHelper
|
|
3
|
+
*
|
|
4
|
+
* Helper untuk format, parse, dan reply messages dengan mudah.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { MessageHelper } from 'waliwa';
|
|
9
|
+
*
|
|
10
|
+
* // Get text dari message
|
|
11
|
+
* const text = MessageHelper.getText(message);
|
|
12
|
+
*
|
|
13
|
+
* // Check if message has media
|
|
14
|
+
* const hasMedia = MessageHelper.hasMedia(message);
|
|
15
|
+
*
|
|
16
|
+
* // Get sender JID
|
|
17
|
+
* const sender = MessageHelper.getSender(message);
|
|
18
|
+
*
|
|
19
|
+
* // Reply dengan formatting
|
|
20
|
+
* await MessageHelper.reply(sock, message, 'Hello!', { mention: true });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare class MessageHelper {
|
|
24
|
+
/**
|
|
25
|
+
* Extract text dari message (semua jenis text message)
|
|
26
|
+
*/
|
|
27
|
+
static getText(message: any): string;
|
|
28
|
+
/**
|
|
29
|
+
* Check if message contains media
|
|
30
|
+
*/
|
|
31
|
+
static hasMedia(message: any): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Get media type dari message
|
|
34
|
+
*/
|
|
35
|
+
static getMediaType(message: any): string | null;
|
|
36
|
+
/**
|
|
37
|
+
* Get sender JID
|
|
38
|
+
*/
|
|
39
|
+
static getSender(message: any): string;
|
|
40
|
+
/**
|
|
41
|
+
* Get chat JID (where message belongs to)
|
|
42
|
+
*/
|
|
43
|
+
static getChat(message: any): string;
|
|
44
|
+
/**
|
|
45
|
+
* Check if message is from me
|
|
46
|
+
*/
|
|
47
|
+
static isFromMe(message: any): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Check if message is from group
|
|
50
|
+
*/
|
|
51
|
+
static isGroupMessage(message: any): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Check if message is status/broadcast
|
|
54
|
+
*/
|
|
55
|
+
static isStatusMessage(message: any): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Get mentioned users
|
|
58
|
+
*/
|
|
59
|
+
static getMentions(message: any): string[];
|
|
60
|
+
/**
|
|
61
|
+
* Get quoted message (reply target)
|
|
62
|
+
*/
|
|
63
|
+
static getQuoted(message: any): any | null;
|
|
64
|
+
/**
|
|
65
|
+
* Reply to message
|
|
66
|
+
*/
|
|
67
|
+
static reply(sock: any, message: any, text: string, options?: {
|
|
68
|
+
mention?: boolean;
|
|
69
|
+
quoted?: boolean;
|
|
70
|
+
}): Promise<any>;
|
|
71
|
+
/**
|
|
72
|
+
* Send text message
|
|
73
|
+
*/
|
|
74
|
+
static sendText(sock: any, jid: string, text: string, options?: {
|
|
75
|
+
mentions?: string[];
|
|
76
|
+
quoted?: any;
|
|
77
|
+
}): Promise<any>;
|
|
78
|
+
/**
|
|
79
|
+
* Send with mentions
|
|
80
|
+
*/
|
|
81
|
+
static sendWithMentions(sock: any, jid: string, text: string, mentionedJids: string[]): Promise<any>;
|
|
82
|
+
/**
|
|
83
|
+
* Mention all group participants
|
|
84
|
+
*/
|
|
85
|
+
static mentionAll(sock: any, groupJid: string, text?: string): Promise<any>;
|
|
86
|
+
/**
|
|
87
|
+
* Forward message
|
|
88
|
+
*/
|
|
89
|
+
static forward(sock: any, toJid: string, message: any): Promise<any>;
|
|
90
|
+
/**
|
|
91
|
+
* Delete message (for everyone)
|
|
92
|
+
*/
|
|
93
|
+
static delete(sock: any, message: any): Promise<any>;
|
|
94
|
+
/**
|
|
95
|
+
* React to message
|
|
96
|
+
*/
|
|
97
|
+
static react(sock: any, message: any, emoji: string): Promise<any>;
|
|
98
|
+
/**
|
|
99
|
+
* Mark as read
|
|
100
|
+
*/
|
|
101
|
+
static markAsRead(sock: any, key: any): Promise<any>;
|
|
102
|
+
/**
|
|
103
|
+
* Send typing indicator
|
|
104
|
+
*/
|
|
105
|
+
static sendTyping(sock: any, jid: string): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Send recording indicator
|
|
108
|
+
*/
|
|
109
|
+
static sendRecording(sock: any, jid: string): Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* Stop typing/recording indicator
|
|
112
|
+
*/
|
|
113
|
+
static stopTyping(sock: any, jid: string): Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* Format message timestamp
|
|
116
|
+
*/
|
|
117
|
+
static formatTimestamp(timestamp: number): string;
|
|
118
|
+
/**
|
|
119
|
+
* Parse command from message (e.g., "!ping arg1 arg2")
|
|
120
|
+
*/
|
|
121
|
+
static parseCommand(message: any, prefix?: string): {
|
|
122
|
+
command: string;
|
|
123
|
+
args: string[];
|
|
124
|
+
fullText: string;
|
|
125
|
+
} | null;
|
|
126
|
+
/**
|
|
127
|
+
* Check if message is a command
|
|
128
|
+
*/
|
|
129
|
+
static isCommand(message: any, prefix?: string): boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Extract URLs from message text
|
|
132
|
+
*/
|
|
133
|
+
static extractUrls(text: string): string[];
|
|
134
|
+
/**
|
|
135
|
+
* Check if message contains URL
|
|
136
|
+
*/
|
|
137
|
+
static hasUrl(message: any): boolean;
|
|
138
|
+
/**
|
|
139
|
+
* Get message status (pending/sent/delivered/read)
|
|
140
|
+
*/
|
|
141
|
+
static getStatus(message: any): string;
|
|
142
|
+
/**
|
|
143
|
+
* Check if message is empty (no text, no media)
|
|
144
|
+
*/
|
|
145
|
+
static isEmpty(message: any): boolean;
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=message.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../src/helpers/message.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,qBAAa,aAAa;IACxB;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,GAAG,MAAM;IAmBpC;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO;IAatC;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,GAAG,GAAG,MAAM,GAAG,IAAI;IAqBhD;;OAEG;IACH,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,GAAG,GAAG,MAAM;IAStC;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,GAAG,MAAM;IAIpC;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO;IAItC;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO;IAI5C;;OAEG;IACH,MAAM,CAAC,eAAe,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO;IAI7C;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,GAAG,GAAG,MAAM,EAAE;I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escript
|
|
9
|
+
* import { MessageHelper } from 'waliwa';
|
|
10
|
+
*
|
|
11
|
+
* // Get text dari message
|
|
12
|
+
* const text = MessageHelper.getText(message);
|
|
13
|
+
*
|
|
14
|
+
* // Check if message has media
|
|
15
|
+
* const hasMedia = MessageHelper.hasMedia(message);
|
|
16
|
+
*
|
|
17
|
+
* // Get sender JID
|
|
18
|
+
* const sender = MessageHelper.getSender(message);
|
|
19
|
+
*
|
|
20
|
+
* // Reply dengan formatting
|
|
21
|
+
* await MessageHelper.reply(sock, message, 'Hello!', { mention: true });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.MessageHelper = void 0;
|
|
26
|
+
class MessageHelper {
|
|
27
|
+
/**
|
|
28
|
+
* Extract text dari message (semua jenis text message)
|
|
29
|
+
*/
|
|
30
|
+
static getText(message) {
|
|
31
|
+
if (!message?.message)
|
|
32
|
+
return '';
|
|
33
|
+
const msg = message.message;
|
|
34
|
+
return (msg.conversation ||
|
|
35
|
+
msg.extendedTextMessage?.text ||
|
|
36
|
+
msg.imageMessage?.caption ||
|
|
37
|
+
msg.videoMessage?.caption ||
|
|
38
|
+
msg.documentMessage?.caption ||
|
|
39
|
+
msg.audioMessage?.caption ||
|
|
40
|
+
msg.templateMessage?.hydratedTemplate?.hydratedContentText ||
|
|
41
|
+
msg.buttonsMessage?.contentText ||
|
|
42
|
+
msg.listMessage?.description ||
|
|
43
|
+
msg.productMessage?.caption ||
|
|
44
|
+
'');
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Check if message contains media
|
|
48
|
+
*/
|
|
49
|
+
static hasMedia(message) {
|
|
50
|
+
if (!message?.message)
|
|
51
|
+
return false;
|
|
52
|
+
const msg = message.message;
|
|
53
|
+
return !!(msg.imageMessage ||
|
|
54
|
+
msg.videoMessage ||
|
|
55
|
+
msg.audioMessage ||
|
|
56
|
+
msg.documentMessage ||
|
|
57
|
+
msg.stickerMessage ||
|
|
58
|
+
msg.contactsArrayMessage);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get media type dari message
|
|
62
|
+
*/
|
|
63
|
+
static getMediaType(message) {
|
|
64
|
+
if (!message?.message)
|
|
65
|
+
return null;
|
|
66
|
+
const msg = message.message;
|
|
67
|
+
if (msg.imageMessage)
|
|
68
|
+
return 'image';
|
|
69
|
+
if (msg.videoMessage)
|
|
70
|
+
return 'video';
|
|
71
|
+
if (msg.audioMessage)
|
|
72
|
+
return 'audio';
|
|
73
|
+
if (msg.documentMessage)
|
|
74
|
+
return 'document';
|
|
75
|
+
if (msg.stickerMessage)
|
|
76
|
+
return 'sticker';
|
|
77
|
+
if (msg.locationMessage)
|
|
78
|
+
return 'location';
|
|
79
|
+
if (msg.contactMessage)
|
|
80
|
+
return 'contact';
|
|
81
|
+
if (msg.contactsArrayMessage)
|
|
82
|
+
return 'contacts';
|
|
83
|
+
if (msg.liveLocationMessage)
|
|
84
|
+
return 'live_location';
|
|
85
|
+
if (msg.listMessage)
|
|
86
|
+
return 'list';
|
|
87
|
+
if (msg.buttonsMessage)
|
|
88
|
+
return 'buttons';
|
|
89
|
+
if (msg.templateMessage)
|
|
90
|
+
return 'template';
|
|
91
|
+
if (msg.productMessage)
|
|
92
|
+
return 'product';
|
|
93
|
+
if (msg.orderMessage)
|
|
94
|
+
return 'order';
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Get sender JID
|
|
99
|
+
*/
|
|
100
|
+
static getSender(message) {
|
|
101
|
+
return (message.key?.participant ||
|
|
102
|
+
message.key?.remoteJid ||
|
|
103
|
+
message.participant ||
|
|
104
|
+
'');
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Get chat JID (where message belongs to)
|
|
108
|
+
*/
|
|
109
|
+
static getChat(message) {
|
|
110
|
+
return message.key?.remoteJid || '';
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Check if message is from me
|
|
114
|
+
*/
|
|
115
|
+
static isFromMe(message) {
|
|
116
|
+
return message.key?.fromMe === true;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Check if message is from group
|
|
120
|
+
*/
|
|
121
|
+
static isGroupMessage(message) {
|
|
122
|
+
return this.getChat(message).endsWith('@g.us');
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Check if message is status/broadcast
|
|
126
|
+
*/
|
|
127
|
+
static isStatusMessage(message) {
|
|
128
|
+
return this.getChat(message) === 'status@broadcast';
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Get mentioned users
|
|
132
|
+
*/
|
|
133
|
+
static getMentions(message) {
|
|
134
|
+
return (message.message?.extendedTextMessage?.contextInfo?.mentionedJid ||
|
|
135
|
+
message.message?.contextInfo?.mentionedJid ||
|
|
136
|
+
[]);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Get quoted message (reply target)
|
|
140
|
+
*/
|
|
141
|
+
static getQuoted(message) {
|
|
142
|
+
const contextInfo = message.message?.extendedTextMessage?.contextInfo ||
|
|
143
|
+
message.message?.contextInfo;
|
|
144
|
+
if (!contextInfo)
|
|
145
|
+
return null;
|
|
146
|
+
return {
|
|
147
|
+
key: {
|
|
148
|
+
remoteJid: message.key?.remoteJid,
|
|
149
|
+
id: contextInfo.stanzaId,
|
|
150
|
+
participant: contextInfo.participant
|
|
151
|
+
},
|
|
152
|
+
message: contextInfo.quotedMessage
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Reply to message
|
|
157
|
+
*/
|
|
158
|
+
static async reply(sock, message, text, options = {}) {
|
|
159
|
+
const { mention = false, quoted = true } = options;
|
|
160
|
+
const content = { text };
|
|
161
|
+
if (quoted) {
|
|
162
|
+
content.quoted = message;
|
|
163
|
+
}
|
|
164
|
+
if (mention && this.getMentions(message).length > 0) {
|
|
165
|
+
content.mentions = this.getMentions(message);
|
|
166
|
+
}
|
|
167
|
+
return sock.sendMessage(message.key.remoteJid, content);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Send text message
|
|
171
|
+
*/
|
|
172
|
+
static async sendText(sock, jid, text, options = {}) {
|
|
173
|
+
const content = { text };
|
|
174
|
+
if (options.mentions) {
|
|
175
|
+
content.mentions = options.mentions;
|
|
176
|
+
}
|
|
177
|
+
if (options.quoted) {
|
|
178
|
+
content.quoted = options.quoted;
|
|
179
|
+
}
|
|
180
|
+
return sock.sendMessage(jid, content);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Send with mentions
|
|
184
|
+
*/
|
|
185
|
+
static async sendWithMentions(sock, jid, text, mentionedJids) {
|
|
186
|
+
return sock.sendMessage(jid, {
|
|
187
|
+
text,
|
|
188
|
+
mentions: mentionedJids
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Mention all group participants
|
|
193
|
+
*/
|
|
194
|
+
static async mentionAll(sock, groupJid, text = '') {
|
|
195
|
+
const metadata = await sock.groupMetadata(groupJid);
|
|
196
|
+
const mentions = metadata.participants.map((p) => p.id);
|
|
197
|
+
// Build text with @ mentions
|
|
198
|
+
const mentionText = metadata.participants
|
|
199
|
+
.map((p) => `@${p.id.split('@')[0]}`)
|
|
200
|
+
.join(' ');
|
|
201
|
+
return sock.sendMessage(groupJid, {
|
|
202
|
+
text: text || mentionText,
|
|
203
|
+
mentions
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Forward message
|
|
208
|
+
*/
|
|
209
|
+
static async forward(sock, toJid, message) {
|
|
210
|
+
return sock.sendMessage(toJid, message, { quoted: undefined });
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Delete message (for everyone)
|
|
214
|
+
*/
|
|
215
|
+
static async delete(sock, message) {
|
|
216
|
+
return sock.sendMessage(message.key.remoteJid, {
|
|
217
|
+
delete: message.key
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* React to message
|
|
222
|
+
*/
|
|
223
|
+
static async react(sock, message, emoji) {
|
|
224
|
+
return sock.sendMessage(message.key.remoteJid, {
|
|
225
|
+
react: {
|
|
226
|
+
text: emoji,
|
|
227
|
+
key: message.key
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Mark as read
|
|
233
|
+
*/
|
|
234
|
+
static async markAsRead(sock, key) {
|
|
235
|
+
return sock.readMessages([key]);
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Send typing indicator
|
|
239
|
+
*/
|
|
240
|
+
static async sendTyping(sock, jid) {
|
|
241
|
+
await sock.sendPresenceUpdate('composing', jid);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Send recording indicator
|
|
245
|
+
*/
|
|
246
|
+
static async sendRecording(sock, jid) {
|
|
247
|
+
await sock.sendPresenceUpdate('recording', jid);
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Stop typing/recording indicator
|
|
251
|
+
*/
|
|
252
|
+
static async stopTyping(sock, jid) {
|
|
253
|
+
await sock.sendPresenceUpdate('paused', jid);
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Format message timestamp
|
|
257
|
+
*/
|
|
258
|
+
static formatTimestamp(timestamp) {
|
|
259
|
+
const date = new Date(timestamp * 1000);
|
|
260
|
+
const now = new Date();
|
|
261
|
+
const diffMs = now.getTime() - date.getTime();
|
|
262
|
+
const diffMins = Math.floor(diffMs / 60000);
|
|
263
|
+
const diffHours = Math.floor(diffMs / 3600000);
|
|
264
|
+
const diffDays = Math.floor(diffMs / 86400000);
|
|
265
|
+
if (diffMins < 1)
|
|
266
|
+
return 'just now';
|
|
267
|
+
if (diffMins < 60)
|
|
268
|
+
return `${diffMins}m ago`;
|
|
269
|
+
if (diffHours < 24)
|
|
270
|
+
return `${diffHours}h ago`;
|
|
271
|
+
if (diffDays < 7)
|
|
272
|
+
return `${diffDays}d ago`;
|
|
273
|
+
return date.toLocaleDateString();
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Parse command from message (e.g., "!ping arg1 arg2")
|
|
277
|
+
*/
|
|
278
|
+
static parseCommand(message, prefix = '!') {
|
|
279
|
+
const text = this.getText(message);
|
|
280
|
+
if (!text.startsWith(prefix))
|
|
281
|
+
return null;
|
|
282
|
+
const parts = text.slice(prefix.length).split(/\s+/);
|
|
283
|
+
return {
|
|
284
|
+
command: parts[0].toLowerCase(),
|
|
285
|
+
args: parts.slice(1),
|
|
286
|
+
fullText: text
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Check if message is a command
|
|
291
|
+
*/
|
|
292
|
+
static isCommand(message, prefix = '!') {
|
|
293
|
+
return this.getText(message).startsWith(prefix);
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Extract URLs from message text
|
|
297
|
+
*/
|
|
298
|
+
static extractUrls(text) {
|
|
299
|
+
const urlRegex = /(https?:\/\/[^\s]+)/gi;
|
|
300
|
+
return text.match(urlRegex) || [];
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Check if message contains URL
|
|
304
|
+
*/
|
|
305
|
+
static hasUrl(message) {
|
|
306
|
+
return this.extractUrls(this.getText(message)).length > 0;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Get message status (pending/sent/delivered/read)
|
|
310
|
+
*/
|
|
311
|
+
static getStatus(message) {
|
|
312
|
+
return message.status || 'unknown';
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Check if message is empty (no text, no media)
|
|
316
|
+
*/
|
|
317
|
+
static isEmpty(message) {
|
|
318
|
+
return !this.getText(message) && !this.hasMedia(message);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
exports.MessageHelper = MessageHelper;
|
|
322
|
+
//# sourceMappingURL=message.js.map
|
|
@@ -0,0 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CAAC,CAAC;IAC3D,CAAC;CACF;AA9VD,sCA8VC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Waliwa - StickerHelper
|
|
3
|
+
*
|
|
4
|
+
* Helper untuk create stickers dari image/video.
|
|
5
|
+
* Image stickers pakai sharp (convert ke WebP).
|
|
6
|
+
* Video stickers pakai fluent-ffmpeg (convert ke animated WebP).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { StickerHelper } from 'waliwa';
|
|
11
|
+
*
|
|
12
|
+
* // Create sticker dari image
|
|
13
|
+
* const stickerBuffer = await StickerHelper.fromImage(imageBuffer, {
|
|
14
|
+
* pack: 'My Pack',
|
|
15
|
+
* author: 'Me',
|
|
16
|
+
* categories: ['😀', '😎']
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* // Send sticker
|
|
20
|
+
* await sock.sendMessage(jid, { sticker: stickerBuffer });
|
|
21
|
+
*
|
|
22
|
+
* // Create sticker dari text
|
|
23
|
+
* const textSticker = await StickerHelper.fromText('Hello!', {
|
|
24
|
+
* pack: 'My Pack',
|
|
25
|
+
* author: 'Me'
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export interface StickerOptions {
|
|
30
|
+
/** Sticker pack name */
|
|
31
|
+
pack?: string;
|
|
32
|
+
/** Sticker author */
|
|
33
|
+
author?: string;
|
|
34
|
+
/** Emoji categories */
|
|
35
|
+
categories?: string[];
|
|
36
|
+
/** Sticker quality (1-100, default: 80) */
|
|
37
|
+
quality?: number;
|
|
38
|
+
/** Width (default: 512) */
|
|
39
|
+
width?: number;
|
|
40
|
+
/** Height (default: 512) */
|
|
41
|
+
height?: number;
|
|
42
|
+
/** Background color for transparent images (default: transparent) */
|
|
43
|
+
background?: {
|
|
44
|
+
r: number;
|
|
45
|
+
g: number;
|
|
46
|
+
b: number;
|
|
47
|
+
alpha: number;
|
|
48
|
+
};
|
|
49
|
+
/** Fit mode (default: contain) */
|
|
50
|
+
fit?: 'cover' | 'contain' | 'fill';
|
|
51
|
+
}
|
|
52
|
+
export declare class StickerHelper {
|
|
53
|
+
/**
|
|
54
|
+
* Create sticker dari image buffer
|
|
55
|
+
* Converts image to WebP 512x512
|
|
56
|
+
*/
|
|
57
|
+
static fromImage(imageBuffer: Buffer, options?: StickerOptions): Promise<Buffer>;
|
|
58
|
+
/**
|
|
59
|
+
* Create sticker dari video buffer (animated sticker)
|
|
60
|
+
* Converts video to animated WebP
|
|
61
|
+
*/
|
|
62
|
+
static fromVideo(videoBuffer: Buffer, options?: StickerOptions): Promise<Buffer>;
|
|
63
|
+
/**
|
|
64
|
+
* Create sticker dari text
|
|
65
|
+
* Renders text on canvas with background color
|
|
66
|
+
*/
|
|
67
|
+
static fromText(text: string, options?: StickerOptions & {
|
|
68
|
+
color?: string;
|
|
69
|
+
backgroundColor?: string;
|
|
70
|
+
}): Promise<Buffer>;
|
|
71
|
+
/**
|
|
72
|
+
* Create sticker dari file path
|
|
73
|
+
*/
|
|
74
|
+
static fromFile(filePath: string, options?: StickerOptions): Promise<Buffer>;
|
|
75
|
+
/**
|
|
76
|
+
* Create sticker dari URL
|
|
77
|
+
*/
|
|
78
|
+
static fromUrl(url: string, options?: StickerOptions): Promise<Buffer>;
|
|
79
|
+
/**
|
|
80
|
+
* Create sticker dengan metadata (Exif)
|
|
81
|
+
* Adds pack name, author, and categories to WebP
|
|
82
|
+
*/
|
|
83
|
+
static addMetadata(stickerBuffer: Buffer, options: StickerOptions): Promise<Buffer>;
|
|
84
|
+
/**
|
|
85
|
+
* Build Exif metadata for sticker
|
|
86
|
+
*/
|
|
87
|
+
private static buildExif;
|
|
88
|
+
/**
|
|
89
|
+
* Extract sticker metadata (pack name, author)
|
|
90
|
+
*/
|
|
91
|
+
static extractMetadata(stickerBuffer: Buffer): {
|
|
92
|
+
pack?: string;
|
|
93
|
+
author?: string;
|
|
94
|
+
categories?: string[];
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Resize sticker to WA requirements (512x512)
|
|
98
|
+
*/
|
|
99
|
+
static normalize(stickerBuffer: Buffer): Promise<Buffer>;
|
|
100
|
+
/**
|
|
101
|
+
* Check if buffer is valid WebP
|
|
102
|
+
*/
|
|
103
|
+
static isWebP(buffer: Buffer): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Get sticker dimensions
|
|
106
|
+
*/
|
|
107
|
+
static getDimensions(stickerBuffer: Buffer): Promise<{
|
|
108
|
+
width: number;
|
|
109
|
+
height: number;
|
|
110
|
+
}>;
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=sticker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sticker.d.ts","sourceRoot":"","sources":["../../src/helpers/sticker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAYH,MAAM,WAAW,cAAc;IAC7B,wBAAwB;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qBAAqB;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,uBAAuB;IACvB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,2CAA2C;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2BAA2B;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4BAA4B;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qEAAqE;IACrE,UAAU,CAAC,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAChE,kCAAkC;IAClC,GAAG,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;CACpC;AAED,qBAAa,aAAa;IACxB;;;OAGG;WACU,SAAS,CACpB,WAAW,EAAE,MAAM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