@vinzsocket/baileys 3.0.10 → 3.0.15
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/lib/Socket/dugong.d.ts +205 -0
- package/lib/Socket/dugong.js +415 -0
- package/lib/Socket/index.d.ts +1 -0
- package/lib/Socket/messages-send.d.ts +2 -0
- package/lib/Socket/messages-send.js +44 -1
- package/lib/Utils/index.d.ts +1 -0
- package/lib/Utils/index.js +1 -0
- package/lib/Utils/mention.d.ts +14 -0
- package/lib/Utils/mention.js +138 -0
- package/package.json +1 -1
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import type { proto } from '../../WAProto/index.js';
|
|
2
|
+
|
|
3
|
+
export type WAMediaUploadFunction = (stream: Buffer | NodeJS.ReadableStream, options?: {
|
|
4
|
+
fileEncSha256?: Buffer;
|
|
5
|
+
mediaType?: string;
|
|
6
|
+
newsletter?: boolean;
|
|
7
|
+
}) => Promise<{
|
|
8
|
+
url: string;
|
|
9
|
+
directPath: string;
|
|
10
|
+
}>;
|
|
11
|
+
|
|
12
|
+
export interface WAMessageContentGenerationOptions {
|
|
13
|
+
upload?: WAMediaUploadFunction;
|
|
14
|
+
mediaCache?: any;
|
|
15
|
+
options?: any;
|
|
16
|
+
logger?: any;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ExtendedMessageUtils {
|
|
20
|
+
prepareWAMessageMedia: (media: any, options: WAMessageContentGenerationOptions) => Promise<any>;
|
|
21
|
+
generateWAMessageContent: (content: any, options: WAMessageContentGenerationOptions) => Promise<any>;
|
|
22
|
+
generateWAMessageFromContent: (jid: string, content: any, options?: any) => any;
|
|
23
|
+
generateWAMessage: (jid: string, content: any, options?: any) => Promise<any>;
|
|
24
|
+
generateMessageID: () => string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface StickerMessage {
|
|
28
|
+
url: string;
|
|
29
|
+
fileSha256: Buffer | string;
|
|
30
|
+
fileEncSha256: Buffer | string;
|
|
31
|
+
mediaKey: Buffer | string;
|
|
32
|
+
mimetype: string;
|
|
33
|
+
directPath: string;
|
|
34
|
+
fileLength: number | string;
|
|
35
|
+
mediaKeyTimestamp: number | string;
|
|
36
|
+
isAnimated?: boolean;
|
|
37
|
+
stickerSentTs?: number | string;
|
|
38
|
+
isAvatar?: boolean;
|
|
39
|
+
isAiSticker?: boolean;
|
|
40
|
+
isLottie?: boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface PaymentMessage {
|
|
44
|
+
amount: number;
|
|
45
|
+
currency?: string;
|
|
46
|
+
from?: string;
|
|
47
|
+
expiry?: number;
|
|
48
|
+
sticker?: { stickerMessage: StickerMessage };
|
|
49
|
+
note?: string;
|
|
50
|
+
background?: {
|
|
51
|
+
id?: string;
|
|
52
|
+
fileLength?: string;
|
|
53
|
+
width?: number;
|
|
54
|
+
height?: number;
|
|
55
|
+
mimetype?: string;
|
|
56
|
+
placeholderArgb?: number;
|
|
57
|
+
textArgb?: number;
|
|
58
|
+
subtextArgb?: number;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface ProductMessage {
|
|
63
|
+
title: string;
|
|
64
|
+
description: string;
|
|
65
|
+
thumbnail: Buffer | { url: string };
|
|
66
|
+
productId: string;
|
|
67
|
+
retailerId: string;
|
|
68
|
+
url: string;
|
|
69
|
+
body?: string;
|
|
70
|
+
footer?: string;
|
|
71
|
+
buttons?: proto.Message.InteractiveMessage.INativeFlowButton[];
|
|
72
|
+
priceAmount1000?: number | null;
|
|
73
|
+
currencyCode?: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface ExternalAdReply {
|
|
77
|
+
title?: string;
|
|
78
|
+
body?: string;
|
|
79
|
+
mediaType?: number;
|
|
80
|
+
thumbnailUrl?: string;
|
|
81
|
+
mediaUrl?: string;
|
|
82
|
+
sourceUrl?: string;
|
|
83
|
+
showAdAttribution?: boolean;
|
|
84
|
+
renderLargerThumbnail?: boolean;
|
|
85
|
+
[key: string]: any;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface InteractiveMessage {
|
|
89
|
+
header?: string;
|
|
90
|
+
title: string;
|
|
91
|
+
footer?: string;
|
|
92
|
+
thumbnail?: string | Buffer | { url: string };
|
|
93
|
+
image?: string | Buffer | { url: string };
|
|
94
|
+
video?: string | Buffer | { url: string };
|
|
95
|
+
document?: string | Buffer | { url: string };
|
|
96
|
+
mimetype?: string;
|
|
97
|
+
fileName?: string;
|
|
98
|
+
jpegThumbnail?: string | Buffer | { url: string };
|
|
99
|
+
contextInfo?: {
|
|
100
|
+
mentionedJid?: string[];
|
|
101
|
+
forwardingScore?: number;
|
|
102
|
+
isForwarded?: boolean;
|
|
103
|
+
externalAdReply?: ExternalAdReply;
|
|
104
|
+
[key: string]: any;
|
|
105
|
+
};
|
|
106
|
+
externalAdReply?: ExternalAdReply;
|
|
107
|
+
buttons?: proto.Message.InteractiveMessage.INativeFlowButton[];
|
|
108
|
+
nativeFlowMessage?: {
|
|
109
|
+
messageParamsJson?: string;
|
|
110
|
+
buttons?: proto.Message.InteractiveMessage.INativeFlowButton[];
|
|
111
|
+
[key: string]: any;
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface AlbumItem {
|
|
116
|
+
image?: string | Buffer | { url: string; caption?: string };
|
|
117
|
+
video?: string | Buffer | { url: string; caption?: string };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface EventMessageLocation {
|
|
121
|
+
degreesLatitude: number;
|
|
122
|
+
degreesLongitude: number;
|
|
123
|
+
name: string;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface EventMessage {
|
|
127
|
+
isCanceled?: boolean;
|
|
128
|
+
name: string;
|
|
129
|
+
description: string;
|
|
130
|
+
location?: EventMessageLocation;
|
|
131
|
+
joinLink?: string;
|
|
132
|
+
startTime?: string | number;
|
|
133
|
+
endTime?: string | number;
|
|
134
|
+
extraGuestsAllowed?: boolean;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export interface PollVote {
|
|
138
|
+
optionName: string;
|
|
139
|
+
optionVoteCount: string | number;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export interface PollResultMessage {
|
|
143
|
+
name: string;
|
|
144
|
+
pollVotes: PollVote[];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export interface GroupStatusMessage {
|
|
148
|
+
message?: any;
|
|
149
|
+
image?: string | Buffer | { url: string };
|
|
150
|
+
video?: string | Buffer | { url: string };
|
|
151
|
+
text?: string;
|
|
152
|
+
caption?: string;
|
|
153
|
+
document?: string | Buffer | { url: string };
|
|
154
|
+
[key: string]: any;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export interface ExtendedMessageContent {
|
|
158
|
+
requestPaymentMessage?: PaymentMessage;
|
|
159
|
+
productMessage?: ProductMessage;
|
|
160
|
+
interactiveMessage?: InteractiveMessage;
|
|
161
|
+
albumMessage?: AlbumItem[];
|
|
162
|
+
eventMessage?: EventMessage;
|
|
163
|
+
pollResultMessage?: PollResultMessage;
|
|
164
|
+
groupStatusMessage?: GroupStatusMessage;
|
|
165
|
+
sender?: string;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export type ExtendedMessageType = 'PAYMENT' | 'PRODUCT' | 'INTERACTIVE' | 'ALBUM' | 'EVENT' | 'POLL_RESULT' | 'GROUP_STORY';
|
|
169
|
+
|
|
170
|
+
export declare class ExtendedMessageBuilder {
|
|
171
|
+
utils: ExtendedMessageUtils;
|
|
172
|
+
relayMessage: (jid: string, content: any, options?: any) => Promise<any>;
|
|
173
|
+
waUploadToServer: WAMediaUploadFunction;
|
|
174
|
+
bail: {
|
|
175
|
+
generateWAMessageContent: ExtendedMessageUtils['generateWAMessageContent'];
|
|
176
|
+
generateMessageID: () => string;
|
|
177
|
+
getContentType: (msg: any) => string;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
constructor(utils: ExtendedMessageUtils, waUploadToServer: WAMediaUploadFunction, relayMessageFn: (jid: string, content: any, options?: any) => Promise<any>);
|
|
181
|
+
|
|
182
|
+
detectType(content: ExtendedMessageContent): ExtendedMessageType | null;
|
|
183
|
+
|
|
184
|
+
handlePayment(content: { requestPaymentMessage: PaymentMessage }, quoted?: proto.IWebMessageInfo | null): Promise<{
|
|
185
|
+
requestPaymentMessage: proto.Message.RequestPaymentMessage;
|
|
186
|
+
}>;
|
|
187
|
+
|
|
188
|
+
handleProduct(content: { productMessage: ProductMessage }, jid: string, quoted?: proto.IWebMessageInfo | null): Promise<{
|
|
189
|
+
viewOnceMessage: { message: { interactiveMessage: any } };
|
|
190
|
+
}>;
|
|
191
|
+
|
|
192
|
+
handleInteractive(content: { interactiveMessage: InteractiveMessage }, jid: string, quoted?: proto.IWebMessageInfo | null, options?: { mentions?: string[] }): Promise<{
|
|
193
|
+
interactiveMessage: any;
|
|
194
|
+
}>;
|
|
195
|
+
|
|
196
|
+
handleAlbum(content: { albumMessage: AlbumItem[] }, jid: string, quoted?: proto.IWebMessageInfo | null): Promise<any>;
|
|
197
|
+
|
|
198
|
+
handleEvent(content: { eventMessage: EventMessage }, jid: string, quoted?: proto.IWebMessageInfo | null): Promise<any>;
|
|
199
|
+
|
|
200
|
+
handlePollResult(content: { pollResultMessage: PollResultMessage }, jid: string, quoted?: proto.IWebMessageInfo | null): Promise<any>;
|
|
201
|
+
|
|
202
|
+
handleGroupStory(content: { groupStatusMessage: GroupStatusMessage }, jid: string, quoted?: proto.IWebMessageInfo | null): Promise<any>;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export default ExtendedMessageBuilder;
|
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
// dugong.js — extended message builders
|
|
2
|
+
// Handles: Request Payment, Product, Interactive (buttons/native flow/external ad reply/
|
|
3
|
+
// document+thumbnail), Album, Event, Poll Result, Group Status V2 (group story).
|
|
4
|
+
// Ported from baileys-lily (Socket/dugong.js), adapted to ESM for Harps-Baileys.
|
|
5
|
+
|
|
6
|
+
import { randomBytes } from 'crypto';
|
|
7
|
+
import { proto } from '../../WAProto/index.js';
|
|
8
|
+
import { normalizeMentions } from '../Utils/mention.js';
|
|
9
|
+
|
|
10
|
+
export class ExtendedMessageBuilder {
|
|
11
|
+
constructor(utils, waUploadToServer, relayMessageFn) {
|
|
12
|
+
this.utils = utils;
|
|
13
|
+
this.relayMessage = relayMessageFn;
|
|
14
|
+
this.waUploadToServer = waUploadToServer;
|
|
15
|
+
|
|
16
|
+
this.bail = {
|
|
17
|
+
generateWAMessageContent: this.utils.generateWAMessageContent,
|
|
18
|
+
generateMessageID: this.utils.generateMessageID,
|
|
19
|
+
getContentType: (msg) => Object.keys(msg.message || {})[0]
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
detectType(content) {
|
|
24
|
+
if (content.requestPaymentMessage) return 'PAYMENT';
|
|
25
|
+
if (content.productMessage) return 'PRODUCT';
|
|
26
|
+
if (content.interactiveMessage) return 'INTERACTIVE';
|
|
27
|
+
if (content.albumMessage) return 'ALBUM';
|
|
28
|
+
if (content.eventMessage) return 'EVENT';
|
|
29
|
+
if (content.pollResultMessage) return 'POLL_RESULT';
|
|
30
|
+
if (content.groupStatusMessage) return 'GROUP_STORY';
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Request Payment — tagihan pembayaran + sticker/note & background */
|
|
35
|
+
async handlePayment(content, quoted) {
|
|
36
|
+
const data = content.requestPaymentMessage;
|
|
37
|
+
let notes = {};
|
|
38
|
+
|
|
39
|
+
if (data.sticker?.stickerMessage) {
|
|
40
|
+
notes = {
|
|
41
|
+
stickerMessage: {
|
|
42
|
+
...data.sticker.stickerMessage,
|
|
43
|
+
contextInfo: {
|
|
44
|
+
stanzaId: quoted?.key?.id,
|
|
45
|
+
participant: quoted?.key?.participant || content.sender,
|
|
46
|
+
quotedMessage: quoted?.message
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
} else if (data.note) {
|
|
51
|
+
notes = {
|
|
52
|
+
extendedTextMessage: {
|
|
53
|
+
text: data.note,
|
|
54
|
+
contextInfo: {
|
|
55
|
+
stanzaId: quoted?.key?.id,
|
|
56
|
+
participant: quoted?.key?.participant || content.sender,
|
|
57
|
+
quotedMessage: quoted?.message
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
requestPaymentMessage: proto.Message.RequestPaymentMessage.fromObject({
|
|
65
|
+
expiryTimestamp: data.expiry || 0,
|
|
66
|
+
amount1000: data.amount || 0,
|
|
67
|
+
currencyCodeIso4217: data.currency || 'IDR',
|
|
68
|
+
requestFrom: data.from || '0@s.whatsapp.net',
|
|
69
|
+
noteMessage: notes,
|
|
70
|
+
background: data.background ?? {
|
|
71
|
+
id: 'DEFAULT',
|
|
72
|
+
placeholderArgb: 0xFFF0F0F0
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Product Message — katalog produk */
|
|
79
|
+
async handleProduct(content, jid, quoted) {
|
|
80
|
+
const {
|
|
81
|
+
title,
|
|
82
|
+
description,
|
|
83
|
+
thumbnail,
|
|
84
|
+
productId,
|
|
85
|
+
retailerId,
|
|
86
|
+
url,
|
|
87
|
+
body = '',
|
|
88
|
+
footer = '',
|
|
89
|
+
buttons = [],
|
|
90
|
+
priceAmount1000 = null,
|
|
91
|
+
currencyCode = 'IDR'
|
|
92
|
+
} = content.productMessage;
|
|
93
|
+
|
|
94
|
+
let productImage;
|
|
95
|
+
|
|
96
|
+
if (Buffer.isBuffer(thumbnail)) {
|
|
97
|
+
const { imageMessage } = await this.utils.generateWAMessageContent(
|
|
98
|
+
{ image: thumbnail },
|
|
99
|
+
{ upload: this.waUploadToServer }
|
|
100
|
+
);
|
|
101
|
+
productImage = imageMessage;
|
|
102
|
+
} else if (typeof thumbnail === 'object' && thumbnail?.url) {
|
|
103
|
+
const { imageMessage } = await this.utils.generateWAMessageContent(
|
|
104
|
+
{ image: { url: thumbnail.url } },
|
|
105
|
+
{ upload: this.waUploadToServer }
|
|
106
|
+
);
|
|
107
|
+
productImage = imageMessage;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
viewOnceMessage: {
|
|
112
|
+
message: {
|
|
113
|
+
interactiveMessage: {
|
|
114
|
+
body: { text: body },
|
|
115
|
+
footer: { text: footer },
|
|
116
|
+
header: {
|
|
117
|
+
title,
|
|
118
|
+
hasMediaAttachment: true,
|
|
119
|
+
productMessage: {
|
|
120
|
+
product: {
|
|
121
|
+
productImage,
|
|
122
|
+
productId,
|
|
123
|
+
title,
|
|
124
|
+
description,
|
|
125
|
+
currencyCode,
|
|
126
|
+
priceAmount1000,
|
|
127
|
+
retailerId,
|
|
128
|
+
url,
|
|
129
|
+
productImageCount: 1
|
|
130
|
+
},
|
|
131
|
+
businessOwnerJid: '0@s.whatsapp.net'
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
nativeFlowMessage: { buttons }
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Interactive Message — button, copy code, native flow, bottom sheet,
|
|
143
|
+
* limited time offer, document+thumbnail, external ad reply.
|
|
144
|
+
*/
|
|
145
|
+
async handleInteractive(content, jid, quoted, options = {}) {
|
|
146
|
+
const {
|
|
147
|
+
title,
|
|
148
|
+
footer,
|
|
149
|
+
thumbnail,
|
|
150
|
+
image,
|
|
151
|
+
video,
|
|
152
|
+
document,
|
|
153
|
+
mimetype,
|
|
154
|
+
fileName,
|
|
155
|
+
jpegThumbnail,
|
|
156
|
+
contextInfo = {},
|
|
157
|
+
externalAdReply,
|
|
158
|
+
buttons = [],
|
|
159
|
+
nativeFlowMessage,
|
|
160
|
+
header
|
|
161
|
+
} = content.interactiveMessage;
|
|
162
|
+
|
|
163
|
+
let media = null;
|
|
164
|
+
|
|
165
|
+
// Media handling (image, video, document)
|
|
166
|
+
if (thumbnail || image) {
|
|
167
|
+
const imgSource = thumbnail || image;
|
|
168
|
+
const imgObj = typeof imgSource === 'object' && imgSource.url ? { url: imgSource.url } : imgSource;
|
|
169
|
+
media = await this.utils.prepareWAMessageMedia(
|
|
170
|
+
{ image: imgObj },
|
|
171
|
+
{ upload: this.waUploadToServer }
|
|
172
|
+
);
|
|
173
|
+
} else if (video) {
|
|
174
|
+
const vidObj = typeof video === 'object' && video.url ? { url: video.url } : video;
|
|
175
|
+
media = await this.utils.prepareWAMessageMedia(
|
|
176
|
+
{ video: vidObj },
|
|
177
|
+
{ upload: this.waUploadToServer }
|
|
178
|
+
);
|
|
179
|
+
} else if (document) {
|
|
180
|
+
// Document + Thumbnail: kirim PDF/dokumen dengan preview
|
|
181
|
+
let documentPayload = { document };
|
|
182
|
+
if (jpegThumbnail) {
|
|
183
|
+
documentPayload.jpegThumbnail = typeof jpegThumbnail === 'object' && jpegThumbnail.url
|
|
184
|
+
? { url: jpegThumbnail.url }
|
|
185
|
+
: jpegThumbnail;
|
|
186
|
+
}
|
|
187
|
+
media = await this.utils.prepareWAMessageMedia(
|
|
188
|
+
documentPayload,
|
|
189
|
+
{ upload: this.waUploadToServer }
|
|
190
|
+
);
|
|
191
|
+
if (fileName && media.documentMessage) media.documentMessage.fileName = fileName;
|
|
192
|
+
if (mimetype && media.documentMessage) media.documentMessage.mimetype = mimetype;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Build interactive message
|
|
196
|
+
let interactiveMessage = {
|
|
197
|
+
body: { text: title || '' },
|
|
198
|
+
footer: { text: footer || '' }
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
// Buttons / nativeFlowMessage (button, copy code, native flow, bottom sheet, limited time offer)
|
|
202
|
+
if (buttons && buttons.length > 0) {
|
|
203
|
+
interactiveMessage.nativeFlowMessage = { buttons };
|
|
204
|
+
if (nativeFlowMessage) {
|
|
205
|
+
interactiveMessage.nativeFlowMessage = {
|
|
206
|
+
...interactiveMessage.nativeFlowMessage,
|
|
207
|
+
...nativeFlowMessage
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
} else if (nativeFlowMessage) {
|
|
211
|
+
interactiveMessage.nativeFlowMessage = nativeFlowMessage;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Header with media
|
|
215
|
+
if (media) {
|
|
216
|
+
interactiveMessage.header = {
|
|
217
|
+
title: header || '',
|
|
218
|
+
hasMediaAttachment: true,
|
|
219
|
+
...media
|
|
220
|
+
};
|
|
221
|
+
} else {
|
|
222
|
+
interactiveMessage.header = {
|
|
223
|
+
title: header || '',
|
|
224
|
+
hasMediaAttachment: false
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// contextInfo (mentions + external ad reply)
|
|
229
|
+
let finalContextInfo = {
|
|
230
|
+
forwardingScore: contextInfo.forwardingScore || 0,
|
|
231
|
+
isForwarded: contextInfo.isForwarded || false,
|
|
232
|
+
...contextInfo,
|
|
233
|
+
mentionedJid: normalizeMentions(contextInfo.mentionedJid || options.mentions || [])
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
if (externalAdReply) {
|
|
237
|
+
// External Ad Reply — pesan dengan thumbnail eksternal
|
|
238
|
+
finalContextInfo.externalAdReply = {
|
|
239
|
+
title: externalAdReply.title || '',
|
|
240
|
+
body: externalAdReply.body || '',
|
|
241
|
+
mediaType: externalAdReply.mediaType || 1,
|
|
242
|
+
thumbnailUrl: externalAdReply.thumbnailUrl || '',
|
|
243
|
+
mediaUrl: externalAdReply.mediaUrl || '',
|
|
244
|
+
sourceUrl: externalAdReply.sourceUrl || '',
|
|
245
|
+
showAdAttribution: externalAdReply.showAdAttribution || false,
|
|
246
|
+
renderLargerThumbnail: externalAdReply.renderLargerThumbnail || false,
|
|
247
|
+
...externalAdReply
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (finalContextInfo.mentionedJid && !Array.isArray(finalContextInfo.mentionedJid)) {
|
|
252
|
+
finalContextInfo.mentionedJid = [finalContextInfo.mentionedJid];
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (Object.keys(finalContextInfo).length > 0) {
|
|
256
|
+
interactiveMessage.contextInfo = finalContextInfo;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return { interactiveMessage };
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** Album Message — kirim banyak foto/video sekaligus */
|
|
263
|
+
async handleAlbum(content, jid, quoted) {
|
|
264
|
+
const array = content.albumMessage;
|
|
265
|
+
const album = await this.utils.generateWAMessageFromContent(jid, {
|
|
266
|
+
messageContextInfo: {
|
|
267
|
+
messageSecret: randomBytes(32)
|
|
268
|
+
},
|
|
269
|
+
albumMessage: {
|
|
270
|
+
expectedImageCount: array.filter((a) => Object.prototype.hasOwnProperty.call(a, 'image')).length,
|
|
271
|
+
expectedVideoCount: array.filter((a) => Object.prototype.hasOwnProperty.call(a, 'video')).length
|
|
272
|
+
}
|
|
273
|
+
}, {
|
|
274
|
+
userJid: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net',
|
|
275
|
+
quoted,
|
|
276
|
+
upload: this.waUploadToServer
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
await this.relayMessage(jid, album.message, {
|
|
280
|
+
messageId: album.key.id
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
for (const item of array) {
|
|
284
|
+
const img = await this.utils.generateWAMessage(jid, item, {
|
|
285
|
+
upload: this.waUploadToServer
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
img.message.messageContextInfo = {
|
|
289
|
+
messageSecret: randomBytes(32),
|
|
290
|
+
messageAssociation: {
|
|
291
|
+
associationType: 1,
|
|
292
|
+
parentMessageKey: album.key
|
|
293
|
+
},
|
|
294
|
+
participant: jid,
|
|
295
|
+
forwardingScore: 0,
|
|
296
|
+
isForwarded: false
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
await this.relayMessage(jid, img.message, {
|
|
300
|
+
messageId: img.key.id,
|
|
301
|
+
quoted: {
|
|
302
|
+
key: {
|
|
303
|
+
remoteJid: album.key.remoteJid,
|
|
304
|
+
id: album.key.id,
|
|
305
|
+
fromMe: true,
|
|
306
|
+
participant: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net'
|
|
307
|
+
},
|
|
308
|
+
message: album.message
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
return album;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** Event Message — undangan acara dengan lokasi & waktu */
|
|
316
|
+
async handleEvent(content, jid, quoted) {
|
|
317
|
+
const eventData = content.eventMessage;
|
|
318
|
+
|
|
319
|
+
const msg = await this.utils.generateWAMessageFromContent(jid, {
|
|
320
|
+
viewOnceMessage: {
|
|
321
|
+
message: {
|
|
322
|
+
messageContextInfo: {
|
|
323
|
+
deviceListMetadata: {},
|
|
324
|
+
deviceListMetadataVersion: 2,
|
|
325
|
+
messageSecret: randomBytes(32),
|
|
326
|
+
supportPayload: JSON.stringify({
|
|
327
|
+
version: 2,
|
|
328
|
+
is_ai_message: true,
|
|
329
|
+
should_show_system_message: true,
|
|
330
|
+
ticket_id: randomBytes(16).toString('hex')
|
|
331
|
+
})
|
|
332
|
+
},
|
|
333
|
+
eventMessage: {
|
|
334
|
+
contextInfo: {
|
|
335
|
+
mentionedJid: [jid],
|
|
336
|
+
participant: jid,
|
|
337
|
+
remoteJid: 'status@broadcast'
|
|
338
|
+
},
|
|
339
|
+
isCanceled: eventData.isCanceled || false,
|
|
340
|
+
name: eventData.name,
|
|
341
|
+
description: eventData.description,
|
|
342
|
+
location: eventData.location || {
|
|
343
|
+
degreesLatitude: 0,
|
|
344
|
+
degreesLongitude: 0,
|
|
345
|
+
name: 'Location'
|
|
346
|
+
},
|
|
347
|
+
joinLink: eventData.joinLink || '',
|
|
348
|
+
startTime: typeof eventData.startTime === 'string' ? parseInt(eventData.startTime, 10) : eventData.startTime || Date.now(),
|
|
349
|
+
endTime: typeof eventData.endTime === 'string' ? parseInt(eventData.endTime, 10) : eventData.endTime || Date.now() + 3600000,
|
|
350
|
+
extraGuestsAllowed: eventData.extraGuestsAllowed !== false
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}, { quoted });
|
|
355
|
+
|
|
356
|
+
await this.relayMessage(jid, msg.message, {
|
|
357
|
+
messageId: msg.key.id
|
|
358
|
+
});
|
|
359
|
+
return msg;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/** Poll Result Message — tampilkan hasil polling */
|
|
363
|
+
async handlePollResult(content, jid, quoted) {
|
|
364
|
+
const pollData = content.pollResultMessage;
|
|
365
|
+
|
|
366
|
+
const msg = await this.utils.generateWAMessageFromContent(jid, {
|
|
367
|
+
pollResultSnapshotMessage: {
|
|
368
|
+
name: pollData.name,
|
|
369
|
+
pollVotes: pollData.pollVotes.map(vote => ({
|
|
370
|
+
optionName: vote.optionName,
|
|
371
|
+
optionVoteCount: typeof vote.optionVoteCount === 'number'
|
|
372
|
+
? vote.optionVoteCount.toString()
|
|
373
|
+
: vote.optionVoteCount
|
|
374
|
+
}))
|
|
375
|
+
}
|
|
376
|
+
}, {
|
|
377
|
+
userJid: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net',
|
|
378
|
+
quoted
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
await this.relayMessage(jid, msg.message, {
|
|
382
|
+
messageId: msg.key.id
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
return msg;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/** Group Status V2 — status di grup */
|
|
389
|
+
async handleGroupStory(content, jid, quoted) {
|
|
390
|
+
const storyData = content.groupStatusMessage;
|
|
391
|
+
let waMsgContent;
|
|
392
|
+
|
|
393
|
+
if (storyData.message) {
|
|
394
|
+
waMsgContent = storyData;
|
|
395
|
+
} else {
|
|
396
|
+
waMsgContent = await this.bail.generateWAMessageContent(storyData, {
|
|
397
|
+
upload: this.waUploadToServer
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
const msg = {
|
|
402
|
+
message: {
|
|
403
|
+
groupStatusMessageV2: {
|
|
404
|
+
message: waMsgContent.message || waMsgContent
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
return await this.relayMessage(jid, msg.message, {
|
|
410
|
+
messageId: this.bail.generateMessageID()
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
export default ExtendedMessageBuilder;
|
package/lib/Socket/index.d.ts
CHANGED
|
@@ -80,6 +80,7 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
|
|
|
80
80
|
refreshMediaConn: (forceGet?: boolean) => Promise<import("../index.js").MediaConnInfo>;
|
|
81
81
|
getMediaHost: () => string;
|
|
82
82
|
waUploadToServer: import("../index.js").WAMediaUploadFunction;
|
|
83
|
+
extendedMessages: import("./dugong.js").ExtendedMessageBuilder;
|
|
83
84
|
fetchPrivacySettings: (force?: boolean) => Promise<{
|
|
84
85
|
[_: string]: string;
|
|
85
86
|
}>;
|
|
@@ -5,6 +5,7 @@ import type { AnyMessageContent, MediaConnInfo, MessageReceiptType, MessageRelay
|
|
|
5
5
|
import { MessageRetryManager } from '../Utils/index.js';
|
|
6
6
|
import { type BinaryNode, type JidWithDevice } from '../WABinary/index.js';
|
|
7
7
|
import { USyncQuery } from '../WAUSync/index.js';
|
|
8
|
+
import { ExtendedMessageBuilder } from './dugong.js';
|
|
8
9
|
export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
9
10
|
userDevicesCache: import("../Types/index.js").PossiblyExtendedCacheStore | NodeCache<JidWithDevice[]>;
|
|
10
11
|
devicesMutex: {
|
|
@@ -19,6 +20,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
19
20
|
refreshMediaConn: (forceGet?: boolean) => Promise<MediaConnInfo>;
|
|
20
21
|
getMediaHost: () => string;
|
|
21
22
|
waUploadToServer: import("../Types/index.js").WAMediaUploadFunction;
|
|
23
|
+
extendedMessages: ExtendedMessageBuilder;
|
|
22
24
|
fetchPrivacySettings: (force?: boolean) => Promise<{
|
|
23
25
|
[_: string]: string;
|
|
24
26
|
}>;
|
|
@@ -2,13 +2,14 @@ import NodeCache from '@cacheable/node-cache';
|
|
|
2
2
|
import { Boom } from '@hapi/boom';
|
|
3
3
|
import { proto } from '../../WAProto/index.js';
|
|
4
4
|
import { DEFAULT_CACHE_TTLS, WA_DEFAULT_EPHEMERAL } from '../Defaults/index.js';
|
|
5
|
-
import { aggregateMessageKeysNotFromMe, assertMediaContent, assertMeId, bindWaitForEvent, decryptMediaRetryData, DEF_MEDIA_HOST, encodeNewsletterMessage, encodeSignedDeviceIdentity, encodeWAMessage, encryptMediaRetryRequest, extractDeviceJids, generateMessageIDV2, generateParticipantHashV2, generateWAMessage, getStatusCodeForMediaRetry, getUrlFromDirectPath, getWAUploadToServer, MessageRetryManager, normalizeMessageContent, parseAndInjectE2ESessions, unixTimestampSeconds } from '../Utils/index.js';
|
|
5
|
+
import { aggregateMessageKeysNotFromMe, assertMediaContent, assertMeId, bindWaitForEvent, decryptMediaRetryData, DEF_MEDIA_HOST, encodeNewsletterMessage, encodeSignedDeviceIdentity, encodeWAMessage, encryptMediaRetryRequest, extractDeviceJids, generateMessageID, generateMessageIDV2, generateParticipantHashV2, generateWAMessage, generateWAMessageContent, generateWAMessageFromContent, getStatusCodeForMediaRetry, getUrlFromDirectPath, getWAUploadToServer, MessageRetryManager, normalizeMessageContent, parseAndInjectE2ESessions, prepareWAMessageMedia, unixTimestampSeconds } from '../Utils/index.js';
|
|
6
6
|
import { getUrlInfo } from '../Utils/link-preview.js';
|
|
7
7
|
import { makeKeyedMutex, makeMutex } from '../Utils/make-mutex.js';
|
|
8
8
|
import { getMessageReportingToken, shouldIncludeReportingToken } from '../Utils/reporting-utils.js';
|
|
9
9
|
import { buildMergedTcTokenIndexWrite, isTcTokenExpired, resolveIssuanceJid, resolveTcTokenJid, shouldSendNewTcToken, storeTcTokensFromIqResult } from '../Utils/tc-token-utils.js';
|
|
10
10
|
import { areJidsSameUser, getBinaryNodeChild, getBinaryNodeChildren, isHostedLidUser, isHostedPnUser, isJidBot, isJidGroup, isJidMetaAI, isLidUser, isPnUser, jidDecode, jidEncode, jidNormalizedUser, PSA_WID, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
11
11
|
import { USyncQuery, USyncUser } from '../WAUSync/index.js';
|
|
12
|
+
import { ExtendedMessageBuilder } from './dugong.js';
|
|
12
13
|
import { makeNewsletterSocket } from './newsletter.js';
|
|
13
14
|
export const makeMessagesSocket = (config) => {
|
|
14
15
|
const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: httpRequestOptions, patchMessageBeforeSending, cachedGroupMetadata, enableRecentMessageCache, maxMsgRetryCount } = config;
|
|
@@ -978,6 +979,13 @@ export const makeMessagesSocket = (config) => {
|
|
|
978
979
|
return result;
|
|
979
980
|
};
|
|
980
981
|
const waUploadToServer = getWAUploadToServer(config, refreshMediaConn);
|
|
982
|
+
const extendedMessages = new ExtendedMessageBuilder({
|
|
983
|
+
generateWAMessageContent,
|
|
984
|
+
generateMessageID,
|
|
985
|
+
generateWAMessage,
|
|
986
|
+
generateWAMessageFromContent,
|
|
987
|
+
prepareWAMessageMedia
|
|
988
|
+
}, waUploadToServer, relayMessage);
|
|
981
989
|
const waitForMsgMediaUpdate = bindWaitForEvent(ev, 'messages.media-update');
|
|
982
990
|
registerSocketEndHandler(() => {
|
|
983
991
|
if (!config.userDevicesCache && userDevicesCache.close) {
|
|
@@ -1002,6 +1010,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
1002
1010
|
// Function (not getter) so the spread in chats.ts preserves the live closure binding.
|
|
1003
1011
|
getMediaHost: () => mediaHost,
|
|
1004
1012
|
waUploadToServer,
|
|
1013
|
+
extendedMessages,
|
|
1005
1014
|
fetchPrivacySettings,
|
|
1006
1015
|
sendPeerDataOperationMessage,
|
|
1007
1016
|
createParticipantNodes,
|
|
@@ -1065,6 +1074,40 @@ export const makeMessagesSocket = (config) => {
|
|
|
1065
1074
|
await groupToggleEphemeral(jid, value);
|
|
1066
1075
|
}
|
|
1067
1076
|
else {
|
|
1077
|
+
const { quoted } = options;
|
|
1078
|
+
const extendedType = extendedMessages.detectType(content);
|
|
1079
|
+
if (extendedType) {
|
|
1080
|
+
switch (extendedType) {
|
|
1081
|
+
case 'PAYMENT': {
|
|
1082
|
+
const paymentContent = await extendedMessages.handlePayment(content, quoted);
|
|
1083
|
+
return await relayMessage(jid, paymentContent, {
|
|
1084
|
+
messageId: generateMessageID()
|
|
1085
|
+
});
|
|
1086
|
+
}
|
|
1087
|
+
case 'PRODUCT': {
|
|
1088
|
+
const productContent = await extendedMessages.handleProduct(content, jid, quoted);
|
|
1089
|
+
const productMsg = await generateWAMessageFromContent(jid, productContent, { quoted });
|
|
1090
|
+
return await relayMessage(jid, productMsg.message, {
|
|
1091
|
+
messageId: productMsg.key.id
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1094
|
+
case 'INTERACTIVE': {
|
|
1095
|
+
const interactiveContent = await extendedMessages.handleInteractive(content, jid, quoted, options);
|
|
1096
|
+
const interactiveMsg = await generateWAMessageFromContent(jid, interactiveContent, { quoted });
|
|
1097
|
+
return await relayMessage(jid, interactiveMsg.message, {
|
|
1098
|
+
messageId: interactiveMsg.key.id
|
|
1099
|
+
});
|
|
1100
|
+
}
|
|
1101
|
+
case 'ALBUM':
|
|
1102
|
+
return await extendedMessages.handleAlbum(content, jid, quoted);
|
|
1103
|
+
case 'EVENT':
|
|
1104
|
+
return await extendedMessages.handleEvent(content, jid, quoted);
|
|
1105
|
+
case 'POLL_RESULT':
|
|
1106
|
+
return await extendedMessages.handlePollResult(content, jid, quoted);
|
|
1107
|
+
case 'GROUP_STORY':
|
|
1108
|
+
return await extendedMessages.handleGroupStory(content, jid, quoted);
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1068
1111
|
const fullMsg = await generateWAMessage(jid, content, {
|
|
1069
1112
|
logger,
|
|
1070
1113
|
userJid,
|
package/lib/Utils/index.d.ts
CHANGED
package/lib/Utils/index.js
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare function normalizeMentions(mentions: string | string[] | null | undefined): string[];
|
|
2
|
+
export declare function applyMentions(msg: any, mentions: string | string[] | null | undefined, contextInfo?: any): any;
|
|
3
|
+
export declare function buildTagAllText(participants: Array<{
|
|
4
|
+
jid?: string;
|
|
5
|
+
id: string;
|
|
6
|
+
phoneNumber?: string;
|
|
7
|
+
}>, options?: {
|
|
8
|
+
getDisplayName?: (jid: string) => string | undefined;
|
|
9
|
+
header?: string;
|
|
10
|
+
footer?: string;
|
|
11
|
+
}): {
|
|
12
|
+
text: string;
|
|
13
|
+
mentions: string[];
|
|
14
|
+
};
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// mention.js
|
|
2
|
+
// Mention helper utilities, used by Socket/dugong.js extended message builders.
|
|
3
|
+
// Ported from baileys-lily, adapted to ESM for Harps-Baileys.
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Normalize mentions to proper JID format
|
|
7
|
+
* @param {string|string[]|null|undefined} mentions
|
|
8
|
+
* @returns {string[]}
|
|
9
|
+
*/
|
|
10
|
+
const mentionCache = new Map();
|
|
11
|
+
|
|
12
|
+
export function normalizeMentions(mentions) {
|
|
13
|
+
const cacheKey = JSON.stringify(mentions);
|
|
14
|
+
if (mentionCache.has(cacheKey)) {
|
|
15
|
+
return mentionCache.get(cacheKey);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (!mentions) return [];
|
|
19
|
+
if (!Array.isArray(mentions)) mentions = [mentions];
|
|
20
|
+
|
|
21
|
+
const result = mentions
|
|
22
|
+
.map(jid => {
|
|
23
|
+
if (typeof jid !== 'string') return null;
|
|
24
|
+
jid = jid.trim();
|
|
25
|
+
if (!jid) return null;
|
|
26
|
+
|
|
27
|
+
// Already has @s.whatsapp.net or @lid
|
|
28
|
+
if (jid.includes('@s.whatsapp.net') || jid.includes('@lid')) {
|
|
29
|
+
return jid;
|
|
30
|
+
}
|
|
31
|
+
// Has @ but not complete
|
|
32
|
+
if (jid.includes('@')) {
|
|
33
|
+
return jid;
|
|
34
|
+
}
|
|
35
|
+
// Plain number
|
|
36
|
+
return jid + '@s.whatsapp.net';
|
|
37
|
+
})
|
|
38
|
+
.filter(Boolean);
|
|
39
|
+
|
|
40
|
+
mentionCache.set(cacheKey, result);
|
|
41
|
+
// Simple cache size limit
|
|
42
|
+
if (mentionCache.size > 1000) mentionCache.clear();
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Apply mentions into a message object (used by Socket/dugong.js extended handlers)
|
|
48
|
+
* @param {object} msg - The message content object
|
|
49
|
+
* @param {string|string[]|null} mentions
|
|
50
|
+
* @param {object} contextInfo - Optional contextInfo to also update
|
|
51
|
+
* @returns {object} msg
|
|
52
|
+
*/
|
|
53
|
+
export function applyMentions(msg, mentions, contextInfo = {}) {
|
|
54
|
+
const normalized = normalizeMentions(mentions);
|
|
55
|
+
if (normalized.length === 0) return msg;
|
|
56
|
+
|
|
57
|
+
// messageContextInfo
|
|
58
|
+
if (!msg.messageContextInfo) msg.messageContextInfo = {};
|
|
59
|
+
if (!msg.messageContextInfo.mentionedJid) msg.messageContextInfo.mentionedJid = [];
|
|
60
|
+
|
|
61
|
+
const existing = new Set(msg.messageContextInfo.mentionedJid);
|
|
62
|
+
for (const jid of normalized) {
|
|
63
|
+
if (!existing.has(jid)) {
|
|
64
|
+
msg.messageContextInfo.mentionedJid.push(jid);
|
|
65
|
+
existing.add(jid);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// contextInfo
|
|
70
|
+
if (contextInfo && typeof contextInfo === 'object') {
|
|
71
|
+
if (!contextInfo.mentionedJid) contextInfo.mentionedJid = [];
|
|
72
|
+
for (const jid of normalized) {
|
|
73
|
+
if (!contextInfo.mentionedJid.includes(jid)) {
|
|
74
|
+
contextInfo.mentionedJid.push(jid);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Extra for interactiveMessage
|
|
80
|
+
if (msg.interactiveMessage?.contextInfo) {
|
|
81
|
+
if (!msg.interactiveMessage.contextInfo.mentionedJid) {
|
|
82
|
+
msg.interactiveMessage.contextInfo.mentionedJid = [];
|
|
83
|
+
}
|
|
84
|
+
for (const jid of normalized) {
|
|
85
|
+
if (!msg.interactiveMessage.contextInfo.mentionedJid.includes(jid)) {
|
|
86
|
+
msg.interactiveMessage.contextInfo.mentionedJid.push(jid);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return msg;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Build a "tag all" text block + mentionedJid list from a group's participants,
|
|
96
|
+
* the way you'd get from sock.groupMetadata(jid).participants
|
|
97
|
+
*
|
|
98
|
+
* Handles the WhatsApp "LID" privacy rollout correctly: when a participant's
|
|
99
|
+
* phone number was NOT disclosed by WhatsApp (group addressingMode = 'lid' and
|
|
100
|
+
* no phone_number attr came back), we do NOT print the raw LID digits as if
|
|
101
|
+
* they were a phone number (e.g. "@206244447002720") since that's meaningless
|
|
102
|
+
* to humans. Instead we fall back to the member's display name if you have one
|
|
103
|
+
* (e.g. from your contact store / pushName cache), or a generic label.
|
|
104
|
+
*
|
|
105
|
+
* @param {Array<object>} participants - group.participants from groupMetadata()
|
|
106
|
+
* @param {object} [options]
|
|
107
|
+
* @param {(jid: string) => string|undefined} [options.getDisplayName] - optional lookup (e.g. store.contacts[jid]?.notify)
|
|
108
|
+
* @param {string} [options.header] - text placed above the list
|
|
109
|
+
* @param {string} [options.footer] - text placed below the list
|
|
110
|
+
* @returns {{ text: string, mentions: string[] }}
|
|
111
|
+
*/
|
|
112
|
+
export function buildTagAllText(participants, options = {}) {
|
|
113
|
+
const { getDisplayName, header = '', footer = '' } = options;
|
|
114
|
+
const lines = [];
|
|
115
|
+
const mentions = [];
|
|
116
|
+
|
|
117
|
+
for (const p of participants || []) {
|
|
118
|
+
// Prefer a real phone-number JID when WhatsApp actually disclosed one.
|
|
119
|
+
const realJid = p.jid && p.jid.endsWith('@s.whatsapp.net')
|
|
120
|
+
? p.jid
|
|
121
|
+
: (p.phoneNumber ? (p.phoneNumber.includes('@') ? p.phoneNumber : `${p.phoneNumber}@s.whatsapp.net`) : null);
|
|
122
|
+
const mentionJid = realJid || p.id; // what we actually tag/ping (lid is fine for this)
|
|
123
|
+
|
|
124
|
+
mentions.push(mentionJid);
|
|
125
|
+
|
|
126
|
+
if (realJid) {
|
|
127
|
+
// We know the real phone number — safe & useful to show it.
|
|
128
|
+
lines.push(`@${realJid.split('@')[0]}`);
|
|
129
|
+
} else {
|
|
130
|
+
// LID-only participant: don't print fake-looking digits.
|
|
131
|
+
const name = typeof getDisplayName === 'function' ? getDisplayName(p.id) : null;
|
|
132
|
+
lines.push(name ? `@${name}` : '@Member');
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const body = [header, lines.join('\n'), footer].filter(Boolean).join('\n\n');
|
|
137
|
+
return { text: body, mentions };
|
|
138
|
+
}
|