fixo-baileys 1.0.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/LICENSE +21 -0
- package/README.md +431 -0
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +5479 -0
- package/WAProto/fix-imports.js +85 -0
- package/WAProto/index.d.ts +14017 -0
- package/WAProto/index.js +97691 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/index.js +129 -0
- package/lib/Signal/Group/ciphertext-message.js +12 -0
- package/lib/Signal/Group/group-session-builder.js +30 -0
- package/lib/Signal/Group/group_cipher.js +82 -0
- package/lib/Signal/Group/index.js +12 -0
- package/lib/Signal/Group/keyhelper.js +18 -0
- package/lib/Signal/Group/sender-chain-key.js +26 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
- package/lib/Signal/Group/sender-key-message.js +66 -0
- package/lib/Signal/Group/sender-key-name.js +48 -0
- package/lib/Signal/Group/sender-key-record.js +41 -0
- package/lib/Signal/Group/sender-key-state.js +84 -0
- package/lib/Signal/Group/sender-message-key.js +26 -0
- package/lib/Signal/libsignal.js +431 -0
- package/lib/Signal/lid-mapping.js +277 -0
- package/lib/Socket/Client/index.js +3 -0
- package/lib/Socket/Client/types.js +11 -0
- package/lib/Socket/Client/websocket.js +54 -0
- package/lib/Socket/business.js +379 -0
- package/lib/Socket/chats.js +1198 -0
- package/lib/Socket/communities.js +431 -0
- package/lib/Socket/groups.js +347 -0
- package/lib/Socket/index.js +12 -0
- package/lib/Socket/messages-recv.js +1772 -0
- package/lib/Socket/messages-send.js +1408 -0
- package/lib/Socket/mex.js +42 -0
- package/lib/Socket/newsletter.js +419 -0
- package/lib/Socket/socket.js +999 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +8 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.js +25 -0
- package/lib/Types/LabelAssociation.js +7 -0
- package/lib/Types/Message.js +11 -0
- package/lib/Types/Mex.js +37 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +3 -0
- package/lib/Types/State.js +56 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +26 -0
- package/lib/Types/temp +1 -0
- package/lib/Utils/auth-utils.js +302 -0
- package/lib/Utils/browser-utils.js +29 -0
- package/lib/Utils/business.js +231 -0
- package/lib/Utils/chat-utils.js +872 -0
- package/lib/Utils/companion-reg-client-utils.js +35 -0
- package/lib/Utils/crypto.js +118 -0
- package/lib/Utils/decode-wa-message.js +317 -0
- package/lib/Utils/event-buffer.js +622 -0
- package/lib/Utils/generics.js +393 -0
- package/lib/Utils/history.js +134 -0
- package/lib/Utils/identity-change-handler.js +50 -0
- package/lib/Utils/index.js +22 -0
- package/lib/Utils/link-preview.js +85 -0
- package/lib/Utils/logger.js +3 -0
- package/lib/Utils/lt-hash.js +8 -0
- package/lib/Utils/make-mutex.js +33 -0
- package/lib/Utils/message-retry-manager.js +265 -0
- package/lib/Utils/messages-media.js +795 -0
- package/lib/Utils/messages.js +1056 -0
- package/lib/Utils/noise-handler.js +201 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/pre-key-manager.js +106 -0
- package/lib/Utils/process-message.js +630 -0
- package/lib/Utils/reporting-utils.js +258 -0
- package/lib/Utils/signal.js +201 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/sync-action-utils.js +49 -0
- package/lib/Utils/tc-token-utils.js +164 -0
- package/lib/Utils/use-multi-file-auth-state.js +121 -0
- package/lib/Utils/validate-connection.js +210 -0
- package/lib/WABinary/constants.js +1301 -0
- package/lib/WABinary/decode.js +262 -0
- package/lib/WABinary/encode.js +220 -0
- package/lib/WABinary/generic-utils.js +113 -0
- package/lib/WABinary/index.js +6 -0
- package/lib/WABinary/jid-utils.js +96 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.js +10 -0
- package/lib/WAM/constants.js +22853 -0
- package/lib/WAM/encode.js +150 -0
- package/lib/WAM/index.js +4 -0
- package/lib/WAM/temp +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +52 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +54 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
- package/lib/WAUSync/Protocols/index.js +6 -0
- package/lib/WAUSync/USyncQuery.js +98 -0
- package/lib/WAUSync/USyncUser.js +31 -0
- package/lib/WAUSync/index.js +4 -0
- package/lib/index.js +11 -0
- package/package.json +79 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
import { getBinaryNodeChild, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
3
|
+
const wMexQuery = (variables, queryId, query, generateMessageTag) => {
|
|
4
|
+
return query({
|
|
5
|
+
tag: 'iq',
|
|
6
|
+
attrs: {
|
|
7
|
+
id: generateMessageTag(),
|
|
8
|
+
type: 'get',
|
|
9
|
+
to: S_WHATSAPP_NET,
|
|
10
|
+
xmlns: 'w:mex'
|
|
11
|
+
},
|
|
12
|
+
content: [
|
|
13
|
+
{
|
|
14
|
+
tag: 'query',
|
|
15
|
+
attrs: { query_id: queryId },
|
|
16
|
+
content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
export const executeWMexQuery = async (variables, queryId, dataPath, query, generateMessageTag) => {
|
|
22
|
+
const result = await wMexQuery(variables, queryId, query, generateMessageTag);
|
|
23
|
+
const child = getBinaryNodeChild(result, 'result');
|
|
24
|
+
if (child?.content) {
|
|
25
|
+
const data = JSON.parse(child.content.toString());
|
|
26
|
+
if (data.errors && data.errors.length > 0) {
|
|
27
|
+
const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ');
|
|
28
|
+
const firstError = data.errors[0];
|
|
29
|
+
const errorCode = firstError.extensions?.error_code || 400;
|
|
30
|
+
throw new Boom(`GraphQL server error: ${errorMessages}`, { statusCode: errorCode, data: firstError });
|
|
31
|
+
}
|
|
32
|
+
const response = dataPath ? data?.data?.[dataPath] : data?.data;
|
|
33
|
+
if (typeof response !== 'undefined') {
|
|
34
|
+
return response;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const action = (dataPath || '').startsWith('xwa2_')
|
|
38
|
+
? dataPath.substring(5).replace(/_/g, ' ')
|
|
39
|
+
: dataPath?.replace(/_/g, ' ');
|
|
40
|
+
throw new Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result });
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=mex.js.map
|
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
import { QueryIds, XWAPaths } from '../Types/index.js';
|
|
2
|
+
import { generateProfilePicture } from '../Utils/messages-media.js';
|
|
3
|
+
import { getBinaryNodeChild } from '../WABinary/index.js';
|
|
4
|
+
import { makeGroupsSocket } from './groups.js';
|
|
5
|
+
import { executeWMexQuery as genericExecuteWMexQuery } from './mex.js';
|
|
6
|
+
|
|
7
|
+
const parseNewsletterCreateResponse = (response) => {
|
|
8
|
+
const { id, thread_metadata: thread, viewer_metadata: viewer } = response;
|
|
9
|
+
return {
|
|
10
|
+
id,
|
|
11
|
+
owner: undefined,
|
|
12
|
+
name: thread.name.text,
|
|
13
|
+
creation_time: parseInt(thread.creation_time, 10),
|
|
14
|
+
description: thread.description.text,
|
|
15
|
+
invite: thread.invite,
|
|
16
|
+
subscribers: parseInt(thread.subscribers_count, 10),
|
|
17
|
+
verification: thread.verification,
|
|
18
|
+
picture: {
|
|
19
|
+
id: thread.picture.id,
|
|
20
|
+
directPath: thread.picture.direct_path
|
|
21
|
+
},
|
|
22
|
+
mute_state: viewer.mute
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const parseNewsletterMetadata = (result) => {
|
|
27
|
+
if (typeof result !== 'object' || result === null) return null;
|
|
28
|
+
if ('id' in result && typeof result.id === 'string') return result;
|
|
29
|
+
if (
|
|
30
|
+
'result' in result &&
|
|
31
|
+
typeof result.result === 'object' &&
|
|
32
|
+
result.result !== null &&
|
|
33
|
+
'id' in result.result
|
|
34
|
+
) {
|
|
35
|
+
return result.result;
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const makeNewsletterSocket = (config) => {
|
|
41
|
+
const sock = makeGroupsSocket(config);
|
|
42
|
+
const { query, generateMessageTag } = sock;
|
|
43
|
+
|
|
44
|
+
const executeWMexQuery = (variables, queryId, dataPath) => {
|
|
45
|
+
return genericExecuteWMexQuery(variables, queryId, dataPath, query, generateMessageTag);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const newsletterUpdate = async (jid, updates) => {
|
|
49
|
+
const variables = {
|
|
50
|
+
newsletter_id: jid,
|
|
51
|
+
updates: { ...updates, settings: null }
|
|
52
|
+
};
|
|
53
|
+
return executeWMexQuery(variables, QueryIds.UPDATE_METADATA, 'xwa2_newsletter_update');
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const _sendNewsletterNode = async (jid, encodedBytes, msgId, extraAttrs = {}) => {
|
|
57
|
+
const stanza = {
|
|
58
|
+
tag: 'message',
|
|
59
|
+
attrs: {
|
|
60
|
+
to: jid,
|
|
61
|
+
id: msgId,
|
|
62
|
+
type: 'text',
|
|
63
|
+
...extraAttrs
|
|
64
|
+
},
|
|
65
|
+
content: [
|
|
66
|
+
{
|
|
67
|
+
tag: 'plaintext',
|
|
68
|
+
attrs: {},
|
|
69
|
+
content: encodedBytes
|
|
70
|
+
}
|
|
71
|
+
]
|
|
72
|
+
};
|
|
73
|
+
await query(stanza);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// Unified send function for all newsletter message types
|
|
77
|
+
const newsletterSend = async (jid, content, waUploadToServer, options = {}) => {
|
|
78
|
+
const { encodeNewsletterMessage, generateMessageIDV2, prepareWAMessageMedia } =
|
|
79
|
+
await import('../Utils/index.js');
|
|
80
|
+
|
|
81
|
+
const msgId = options.messageId || generateMessageIDV2(sock.user?.id);
|
|
82
|
+
|
|
83
|
+
let encoded;
|
|
84
|
+
let resultMessage;
|
|
85
|
+
|
|
86
|
+
// Handle different content types
|
|
87
|
+
if (typeof content === 'string') {
|
|
88
|
+
// Simple text message
|
|
89
|
+
const message = { conversation: content };
|
|
90
|
+
encoded = encodeNewsletterMessage(message);
|
|
91
|
+
resultMessage = message;
|
|
92
|
+
} else if (content.text) {
|
|
93
|
+
// Text message with options
|
|
94
|
+
const message = { conversation: content.text };
|
|
95
|
+
encoded = encodeNewsletterMessage(message);
|
|
96
|
+
resultMessage = message;
|
|
97
|
+
} else if (content.image || content.video || content.audio || content.document || content.sticker) {
|
|
98
|
+
// Media message
|
|
99
|
+
const mediaMsg = await prepareWAMessageMedia(content, {
|
|
100
|
+
upload: waUploadToServer,
|
|
101
|
+
logger: config.logger,
|
|
102
|
+
mediaCache: config.mediaCache,
|
|
103
|
+
options: config.options,
|
|
104
|
+
jid
|
|
105
|
+
});
|
|
106
|
+
encoded = encodeNewsletterMessage(mediaMsg);
|
|
107
|
+
resultMessage = mediaMsg;
|
|
108
|
+
} else if (content.buttons || content.interactiveMessage) {
|
|
109
|
+
// Buttons/interactive message
|
|
110
|
+
const { proto } = await import('../../WAProto/index.js');
|
|
111
|
+
|
|
112
|
+
const interactiveMessage = proto.Message.InteractiveMessage.create({
|
|
113
|
+
body: proto.Message.InteractiveMessage.Body.create({
|
|
114
|
+
text: content.text || content.body || ''
|
|
115
|
+
}),
|
|
116
|
+
footer: content.footer
|
|
117
|
+
? proto.Message.InteractiveMessage.Footer.create({ text: content.footer })
|
|
118
|
+
: undefined,
|
|
119
|
+
nativeFlowMessage: proto.Message.InteractiveMessage.NativeFlowMessage.create({
|
|
120
|
+
buttons: (content.buttons || []).map((b) =>
|
|
121
|
+
proto.Message.InteractiveMessage.NativeFlowMessage.NativeFlowButton.create(b)
|
|
122
|
+
)
|
|
123
|
+
})
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
const message = proto.Message.create({ interactiveMessage });
|
|
127
|
+
encoded = encodeNewsletterMessage(message);
|
|
128
|
+
resultMessage = message;
|
|
129
|
+
} else {
|
|
130
|
+
// Any other message type
|
|
131
|
+
encoded = encodeNewsletterMessage(content);
|
|
132
|
+
resultMessage = content;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
await _sendNewsletterNode(jid, encoded, msgId, options.additionalAttributes || {});
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
key: { remoteJid: jid, fromMe: true, id: msgId },
|
|
139
|
+
message: resultMessage
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
// Direct send for relayMessage
|
|
144
|
+
const newsletterSendDirect = async (jid, message, options = {}) => {
|
|
145
|
+
const { encodeNewsletterMessage } = await import('../Utils/index.js');
|
|
146
|
+
const msgId = options.messageId || generateMessageTag();
|
|
147
|
+
|
|
148
|
+
const encoded = encodeNewsletterMessage(message);
|
|
149
|
+
await _sendNewsletterNode(jid, encoded, msgId, options.additionalAttributes || {});
|
|
150
|
+
|
|
151
|
+
return true;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
...sock,
|
|
156
|
+
|
|
157
|
+
// Main unified send function
|
|
158
|
+
newsletterSend,
|
|
159
|
+
newsletterSendDirect,
|
|
160
|
+
|
|
161
|
+
newsletterCreate: async (name, description) => {
|
|
162
|
+
const variables = {
|
|
163
|
+
input: { name, description: description ?? null }
|
|
164
|
+
};
|
|
165
|
+
const rawResponse = await executeWMexQuery(
|
|
166
|
+
variables,
|
|
167
|
+
QueryIds.CREATE,
|
|
168
|
+
XWAPaths.xwa2_newsletter_create
|
|
169
|
+
);
|
|
170
|
+
return parseNewsletterCreateResponse(rawResponse);
|
|
171
|
+
},
|
|
172
|
+
|
|
173
|
+
newsletterUpdate,
|
|
174
|
+
|
|
175
|
+
newsletterSubscribers: async (jid) => {
|
|
176
|
+
return executeWMexQuery(
|
|
177
|
+
{ newsletter_id: jid },
|
|
178
|
+
QueryIds.SUBSCRIBERS,
|
|
179
|
+
XWAPaths.xwa2_newsletter_subscribers
|
|
180
|
+
);
|
|
181
|
+
},
|
|
182
|
+
|
|
183
|
+
newsletterMetadata: async (type, key) => {
|
|
184
|
+
const variables = {
|
|
185
|
+
fetch_creation_time: true,
|
|
186
|
+
fetch_full_image: true,
|
|
187
|
+
fetch_viewer_metadata: true,
|
|
188
|
+
input: { key, type: type.toUpperCase() }
|
|
189
|
+
};
|
|
190
|
+
const result = await executeWMexQuery(
|
|
191
|
+
variables,
|
|
192
|
+
QueryIds.METADATA,
|
|
193
|
+
XWAPaths.xwa2_newsletter_metadata
|
|
194
|
+
);
|
|
195
|
+
return parseNewsletterMetadata(result);
|
|
196
|
+
},
|
|
197
|
+
|
|
198
|
+
newsletterFollow: (jid) => {
|
|
199
|
+
return executeWMexQuery(
|
|
200
|
+
{ newsletter_id: jid },
|
|
201
|
+
QueryIds.FOLLOW,
|
|
202
|
+
XWAPaths.xwa2_newsletter_join_v2
|
|
203
|
+
);
|
|
204
|
+
},
|
|
205
|
+
|
|
206
|
+
newsletterUnfollow: (jid) => {
|
|
207
|
+
return executeWMexQuery(
|
|
208
|
+
{ newsletter_id: jid },
|
|
209
|
+
QueryIds.UNFOLLOW,
|
|
210
|
+
XWAPaths.xwa2_newsletter_leave_v2
|
|
211
|
+
);
|
|
212
|
+
},
|
|
213
|
+
|
|
214
|
+
newsletterMute: (jid) => {
|
|
215
|
+
return executeWMexQuery(
|
|
216
|
+
{ newsletter_id: jid },
|
|
217
|
+
QueryIds.MUTE,
|
|
218
|
+
XWAPaths.xwa2_newsletter_mute_v2
|
|
219
|
+
);
|
|
220
|
+
},
|
|
221
|
+
|
|
222
|
+
newsletterUnmute: (jid) => {
|
|
223
|
+
return executeWMexQuery(
|
|
224
|
+
{ newsletter_id: jid },
|
|
225
|
+
QueryIds.UNMUTE,
|
|
226
|
+
XWAPaths.xwa2_newsletter_unmute_v2
|
|
227
|
+
);
|
|
228
|
+
},
|
|
229
|
+
|
|
230
|
+
newsletterUpdateName: async (jid, name) => {
|
|
231
|
+
return newsletterUpdate(jid, { name });
|
|
232
|
+
},
|
|
233
|
+
|
|
234
|
+
newsletterUpdateDescription: async (jid, description) => {
|
|
235
|
+
return newsletterUpdate(jid, { description });
|
|
236
|
+
},
|
|
237
|
+
|
|
238
|
+
newsletterUpdatePicture: async (jid, content) => {
|
|
239
|
+
const { img } = await generateProfilePicture(content);
|
|
240
|
+
return newsletterUpdate(jid, { picture: img.toString('base64') });
|
|
241
|
+
},
|
|
242
|
+
|
|
243
|
+
newsletterRemovePicture: async (jid) => {
|
|
244
|
+
return newsletterUpdate(jid, { picture: '' });
|
|
245
|
+
},
|
|
246
|
+
|
|
247
|
+
newsletterReactMessage: async (jid, serverId, reaction) => {
|
|
248
|
+
await query({
|
|
249
|
+
tag: 'message',
|
|
250
|
+
attrs: {
|
|
251
|
+
to: jid,
|
|
252
|
+
...(reaction ? {} : { edit: '7' }),
|
|
253
|
+
type: 'reaction',
|
|
254
|
+
server_id: serverId,
|
|
255
|
+
id: generateMessageTag()
|
|
256
|
+
},
|
|
257
|
+
content: [
|
|
258
|
+
{
|
|
259
|
+
tag: 'reaction',
|
|
260
|
+
attrs: reaction ? { code: reaction } : {}
|
|
261
|
+
}
|
|
262
|
+
]
|
|
263
|
+
});
|
|
264
|
+
},
|
|
265
|
+
|
|
266
|
+
newsletterFetchMessages: async (jid, count, since, after) => {
|
|
267
|
+
const messageUpdateAttrs = { count: count.toString() };
|
|
268
|
+
if (typeof since === 'number') messageUpdateAttrs.since = since.toString();
|
|
269
|
+
if (after) messageUpdateAttrs.after = after.toString();
|
|
270
|
+
|
|
271
|
+
return query({
|
|
272
|
+
tag: 'iq',
|
|
273
|
+
attrs: {
|
|
274
|
+
id: generateMessageTag(),
|
|
275
|
+
type: 'get',
|
|
276
|
+
xmlns: 'newsletter',
|
|
277
|
+
to: jid
|
|
278
|
+
},
|
|
279
|
+
content: [{ tag: 'message_updates', attrs: messageUpdateAttrs }]
|
|
280
|
+
});
|
|
281
|
+
},
|
|
282
|
+
|
|
283
|
+
subscribeNewsletterUpdates: async (jid) => {
|
|
284
|
+
const result = await query({
|
|
285
|
+
tag: 'iq',
|
|
286
|
+
attrs: {
|
|
287
|
+
id: generateMessageTag(),
|
|
288
|
+
type: 'set',
|
|
289
|
+
xmlns: 'newsletter',
|
|
290
|
+
to: jid
|
|
291
|
+
},
|
|
292
|
+
content: [{ tag: 'live_updates', attrs: {}, content: [] }]
|
|
293
|
+
});
|
|
294
|
+
const liveUpdatesNode = getBinaryNodeChild(result, 'live_updates');
|
|
295
|
+
const duration = liveUpdatesNode?.attrs?.duration;
|
|
296
|
+
return duration ? { duration } : null;
|
|
297
|
+
},
|
|
298
|
+
|
|
299
|
+
newsletterAdminCount: async (jid) => {
|
|
300
|
+
const response = await executeWMexQuery(
|
|
301
|
+
{ newsletter_id: jid },
|
|
302
|
+
QueryIds.ADMIN_COUNT,
|
|
303
|
+
XWAPaths.xwa2_newsletter_admin_count
|
|
304
|
+
);
|
|
305
|
+
return response.admin_count;
|
|
306
|
+
},
|
|
307
|
+
|
|
308
|
+
newsletterChangeOwner: async (jid, newOwnerJid) => {
|
|
309
|
+
await executeWMexQuery(
|
|
310
|
+
{ newsletter_id: jid, user_id: newOwnerJid },
|
|
311
|
+
QueryIds.CHANGE_OWNER,
|
|
312
|
+
XWAPaths.xwa2_newsletter_change_owner
|
|
313
|
+
);
|
|
314
|
+
},
|
|
315
|
+
|
|
316
|
+
newsletterDemote: async (jid, userJid) => {
|
|
317
|
+
await executeWMexQuery(
|
|
318
|
+
{ newsletter_id: jid, user_id: userJid },
|
|
319
|
+
QueryIds.DEMOTE,
|
|
320
|
+
XWAPaths.xwa2_newsletter_demote
|
|
321
|
+
);
|
|
322
|
+
},
|
|
323
|
+
|
|
324
|
+
newsletterDelete: async (jid) => {
|
|
325
|
+
await executeWMexQuery(
|
|
326
|
+
{ newsletter_id: jid },
|
|
327
|
+
QueryIds.DELETE,
|
|
328
|
+
XWAPaths.xwa2_newsletter_delete_v2
|
|
329
|
+
);
|
|
330
|
+
},
|
|
331
|
+
|
|
332
|
+
// Keep original for backward compatibility
|
|
333
|
+
newsletterSendMedia: async (jid, content, waUploadToServer, options = {}) => {
|
|
334
|
+
const { encodeNewsletterMessage, generateMessageIDV2, prepareWAMessageMedia } =
|
|
335
|
+
await import('../Utils/index.js');
|
|
336
|
+
|
|
337
|
+
const msgId = options.messageId || generateMessageIDV2(sock.user?.id);
|
|
338
|
+
|
|
339
|
+
const mediaMsg = await prepareWAMessageMedia(content, {
|
|
340
|
+
upload: waUploadToServer,
|
|
341
|
+
logger: config.logger,
|
|
342
|
+
mediaCache: config.mediaCache,
|
|
343
|
+
options: config.options,
|
|
344
|
+
jid
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
const encoded = encodeNewsletterMessage(mediaMsg);
|
|
348
|
+
await _sendNewsletterNode(jid, encoded, msgId, options.additionalAttributes || {});
|
|
349
|
+
|
|
350
|
+
return { key: { remoteJid: jid, fromMe: true, id: msgId }, message: mediaMsg };
|
|
351
|
+
},
|
|
352
|
+
|
|
353
|
+
newsletterSendButtons: async (jid, content, options = {}) => {
|
|
354
|
+
const { encodeNewsletterMessage, generateMessageIDV2 } =
|
|
355
|
+
await import('../Utils/index.js');
|
|
356
|
+
const { proto } = await import('../../WAProto/index.js');
|
|
357
|
+
|
|
358
|
+
const msgId = options.messageId || generateMessageIDV2(sock.user?.id);
|
|
359
|
+
|
|
360
|
+
const interactiveMessage = proto.Message.InteractiveMessage.create({
|
|
361
|
+
body: proto.Message.InteractiveMessage.Body.create({
|
|
362
|
+
text: content.body || ''
|
|
363
|
+
}),
|
|
364
|
+
footer: content.footer
|
|
365
|
+
? proto.Message.InteractiveMessage.Footer.create({ text: content.footer })
|
|
366
|
+
: undefined,
|
|
367
|
+
nativeFlowMessage: proto.Message.InteractiveMessage.NativeFlowMessage.create({
|
|
368
|
+
buttons: (content.buttons || []).map((b) =>
|
|
369
|
+
proto.Message.InteractiveMessage.NativeFlowMessage.NativeFlowButton.create(b)
|
|
370
|
+
)
|
|
371
|
+
})
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
const message = proto.Message.create({ interactiveMessage });
|
|
375
|
+
const encoded = encodeNewsletterMessage(message);
|
|
376
|
+
|
|
377
|
+
await _sendNewsletterNode(jid, encoded, msgId, options.additionalAttributes || {});
|
|
378
|
+
|
|
379
|
+
return { key: { remoteJid: jid, fromMe: true, id: msgId }, message };
|
|
380
|
+
},
|
|
381
|
+
|
|
382
|
+
// ... දැනට ඇති කේතයට පහළින් මෙය එක් කරන්න ...
|
|
383
|
+
|
|
384
|
+
newsletterVotePoll: async (jid, serverId, optionIndex) => {
|
|
385
|
+
return await query({
|
|
386
|
+
tag: 'message',
|
|
387
|
+
attrs: {
|
|
388
|
+
to: jid,
|
|
389
|
+
id: generateMessageTag(),
|
|
390
|
+
type: 'poll',
|
|
391
|
+
server_id: serverId,
|
|
392
|
+
edit: '3' // 👈 Vote එකට 'edit: 3' අවශ්යයි!
|
|
393
|
+
},
|
|
394
|
+
content: [
|
|
395
|
+
{
|
|
396
|
+
tag: 'poll_update',
|
|
397
|
+
attrs: {
|
|
398
|
+
poll_update_type: 'VOTE',
|
|
399
|
+
poll_creation_message_key: serverId
|
|
400
|
+
},
|
|
401
|
+
content: [
|
|
402
|
+
{
|
|
403
|
+
tag: 'selected_options',
|
|
404
|
+
content: [
|
|
405
|
+
{ tag: 'option', attrs: { index: optionIndex.toString() } }
|
|
406
|
+
]
|
|
407
|
+
}
|
|
408
|
+
]
|
|
409
|
+
}
|
|
410
|
+
]
|
|
411
|
+
});
|
|
412
|
+
},
|
|
413
|
+
|
|
414
|
+
// Convenience methods
|
|
415
|
+
newsletterSendText: async (jid, text, options = {}) => {
|
|
416
|
+
return newsletterSend(jid, { text }, sock.waUploadToServer, options);
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
};
|