@queenanya/baileys 9.5.2 → 9.5.3-beta.2
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/README.md +614 -0
- package/lib/Defaults/index.d.ts +5 -0
- package/lib/Defaults/index.d.ts.map +1 -1
- package/lib/Defaults/index.js +32 -3
- package/lib/Defaults/index.js.map +1 -1
- package/lib/Socket/business.d.ts +35 -2
- package/lib/Socket/business.d.ts.map +1 -1
- package/lib/Socket/chats.d.ts +3 -1
- package/lib/Socket/chats.d.ts.map +1 -1
- package/lib/Socket/chats.js +49 -4
- package/lib/Socket/chats.js.map +1 -1
- package/lib/Socket/communities.d.ts +35 -2
- package/lib/Socket/communities.d.ts.map +1 -1
- package/lib/Socket/groups.d.ts +1 -0
- package/lib/Socket/groups.d.ts.map +1 -1
- package/lib/Socket/index.d.ts +35 -2
- package/lib/Socket/index.d.ts.map +1 -1
- package/lib/Socket/messages-recv.d.ts +36 -3
- package/lib/Socket/messages-recv.d.ts.map +1 -1
- package/lib/Socket/messages-recv.js +61 -44
- package/lib/Socket/messages-recv.js.map +1 -1
- package/lib/Socket/messages-send.d.ts +11 -5
- package/lib/Socket/messages-send.d.ts.map +1 -1
- package/lib/Socket/messages-send.js +110 -78
- package/lib/Socket/messages-send.js.map +1 -1
- package/lib/Socket/newsletter.d.ts +1 -0
- package/lib/Socket/newsletter.d.ts.map +1 -1
- package/lib/Socket/newsletter.js +2 -2
- package/lib/Socket/newsletter.js.map +1 -1
- package/lib/Socket/socket.d.ts.map +1 -1
- package/lib/Socket/socket.js +77 -11
- package/lib/Socket/socket.js.map +1 -1
- package/lib/Types/Call.d.ts +8 -0
- package/lib/Types/Call.d.ts.map +1 -1
- package/lib/Types/Events.d.ts +2 -0
- package/lib/Types/Events.d.ts.map +1 -1
- package/lib/Types/Message.d.ts +161 -12
- package/lib/Types/Message.d.ts.map +1 -1
- package/lib/Types/index.d.ts +9 -0
- package/lib/Types/index.d.ts.map +1 -1
- package/lib/Types/index.js.map +1 -1
- package/lib/Utils/browser-utils.d.ts +13 -0
- package/lib/Utils/browser-utils.d.ts.map +1 -1
- package/lib/Utils/browser-utils.js +90 -10
- package/lib/Utils/browser-utils.js.map +1 -1
- package/lib/Utils/event-buffer.js +8 -1
- package/lib/Utils/event-buffer.js.map +1 -1
- package/lib/Utils/history.d.ts +2 -0
- package/lib/Utils/history.d.ts.map +1 -1
- package/lib/Utils/history.js +2 -1
- package/lib/Utils/history.js.map +1 -1
- package/lib/Utils/index.d.ts +2 -0
- package/lib/Utils/index.d.ts.map +1 -1
- package/lib/Utils/index.js +2 -0
- package/lib/Utils/index.js.map +1 -1
- package/lib/Utils/interactive-message.d.ts +201 -0
- package/lib/Utils/interactive-message.d.ts.map +1 -0
- package/lib/Utils/interactive-message.js +256 -0
- package/lib/Utils/interactive-message.js.map +1 -0
- package/lib/Utils/messages-media.d.ts +16 -2
- package/lib/Utils/messages-media.d.ts.map +1 -1
- package/lib/Utils/messages-media.js +19 -10
- package/lib/Utils/messages-media.js.map +1 -1
- package/lib/Utils/messages.d.ts.map +1 -1
- package/lib/Utils/messages.js +408 -11
- package/lib/Utils/messages.js.map +1 -1
- package/lib/Utils/offline-node-processor.d.ts +17 -0
- package/lib/Utils/offline-node-processor.d.ts.map +1 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/offline-node-processor.js.map +1 -0
- package/lib/Utils/stanza-ack.d.ts +11 -0
- package/lib/Utils/stanza-ack.d.ts.map +1 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/stanza-ack.js.map +1 -0
- package/lib/Utils/use-mongo-file-auth-state.d.ts +16 -0
- package/lib/Utils/use-mongo-file-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-mongo-file-auth-state.js +60 -0
- package/lib/Utils/use-mongo-file-auth-state.js.map +1 -0
- package/lib/Utils/validate-connection.d.ts.map +1 -1
- package/lib/Utils/validate-connection.js +15 -2
- package/lib/Utils/validate-connection.js.map +1 -1
- package/lib/WABinary/generic-utils.d.ts +9 -0
- package/lib/WABinary/generic-utils.d.ts.map +1 -1
- package/lib/WABinary/generic-utils.js +23 -0
- package/lib/WABinary/generic-utils.js.map +1 -1
- package/lib/addons/anti-delete.d.ts +72 -0
- package/lib/addons/anti-delete.d.ts.map +1 -0
- package/lib/addons/anti-delete.js +165 -0
- package/lib/addons/anti-delete.js.map +1 -0
- package/lib/addons/auto-reply.d.ts +67 -0
- package/lib/addons/auto-reply.d.ts.map +1 -0
- package/lib/addons/auto-reply.js +145 -0
- package/lib/addons/auto-reply.js.map +1 -0
- package/lib/addons/chat-control.d.ts +57 -0
- package/lib/addons/chat-control.d.ts.map +1 -0
- package/lib/addons/chat-control.js +128 -0
- package/lib/addons/chat-control.js.map +1 -0
- package/lib/addons/from-chats.d.ts +30 -0
- package/lib/addons/from-chats.d.ts.map +1 -0
- package/lib/addons/from-chats.js +38 -0
- package/lib/addons/from-chats.js.map +1 -0
- package/lib/addons/from-messages-recv.d.ts +59 -0
- package/lib/addons/from-messages-recv.d.ts.map +1 -0
- package/lib/addons/from-messages-recv.js +326 -0
- package/lib/addons/from-messages-recv.js.map +1 -0
- package/lib/addons/from-messages-send.d.ts +50 -0
- package/lib/addons/from-messages-send.d.ts.map +1 -0
- package/lib/addons/from-messages-send.js +148 -0
- package/lib/addons/from-messages-send.js.map +1 -0
- package/lib/addons/from-messages.d.ts +52 -0
- package/lib/addons/from-messages.d.ts.map +1 -0
- package/lib/addons/from-messages.js +305 -0
- package/lib/addons/from-messages.js.map +1 -0
- package/lib/addons/index.d.ts +28 -0
- package/lib/addons/index.d.ts.map +1 -0
- package/lib/addons/index.js +44 -0
- package/lib/addons/index.js.map +1 -0
- package/lib/addons/interactive-message.d.ts +201 -0
- package/lib/addons/interactive-message.d.ts.map +1 -0
- package/lib/addons/interactive-message.js +256 -0
- package/lib/addons/interactive-message.js.map +1 -0
- package/lib/addons/jid-plotting.d.ts +53 -0
- package/lib/addons/jid-plotting.d.ts.map +1 -0
- package/lib/addons/jid-plotting.js +150 -0
- package/lib/addons/jid-plotting.js.map +1 -0
- package/lib/addons/message-search.d.ts +38 -0
- package/lib/addons/message-search.d.ts.map +1 -0
- package/lib/addons/message-search.js +171 -0
- package/lib/addons/message-search.js.map +1 -0
- package/lib/addons/message-utils.d.ts +14 -0
- package/lib/addons/message-utils.d.ts.map +1 -0
- package/lib/addons/message-utils.js +174 -0
- package/lib/addons/message-utils.js.map +1 -0
- package/lib/addons/scheduling.d.ts +40 -0
- package/lib/addons/scheduling.d.ts.map +1 -0
- package/lib/addons/scheduling.js +110 -0
- package/lib/addons/scheduling.js.map +1 -0
- package/lib/addons/status-posting.d.ts +120 -0
- package/lib/addons/status-posting.d.ts.map +1 -0
- package/lib/addons/status-posting.js +94 -0
- package/lib/addons/status-posting.js.map +1 -0
- package/lib/addons/templates.d.ts +72 -0
- package/lib/addons/templates.d.ts.map +1 -0
- package/lib/addons/templates.js +145 -0
- package/lib/addons/templates.js.map +1 -0
- package/lib/addons/vcard.d.ts +57 -0
- package/lib/addons/vcard.d.ts.map +1 -0
- package/lib/addons/vcard.js +88 -0
- package/lib/addons/vcard.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { proto } from '../../WAProto/index.js';
|
|
2
|
+
import type { MediaGenerationOptions, WAMediaUpload } from '../Types/index.js';
|
|
3
|
+
export type InteractiveButton = {
|
|
4
|
+
buttonId?: string;
|
|
5
|
+
displayText: string;
|
|
6
|
+
};
|
|
7
|
+
export type InteractiveButtonMessageContent = {
|
|
8
|
+
/** Body text of the message */
|
|
9
|
+
body: string;
|
|
10
|
+
/** Footer text */
|
|
11
|
+
footer?: string;
|
|
12
|
+
/** Buttons to display */
|
|
13
|
+
buttons: InteractiveButton[];
|
|
14
|
+
/** Optional: plain text title (uses TEXT header type) */
|
|
15
|
+
title?: string;
|
|
16
|
+
/** Optional: image header */
|
|
17
|
+
headerImage?: WAMediaUpload;
|
|
18
|
+
/** Optional: video header */
|
|
19
|
+
headerVideo?: WAMediaUpload;
|
|
20
|
+
/** Optional: document header */
|
|
21
|
+
headerDocument?: WAMediaUpload & {
|
|
22
|
+
filename?: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export type ListRow = {
|
|
26
|
+
rowId: string;
|
|
27
|
+
title: string;
|
|
28
|
+
description?: string;
|
|
29
|
+
};
|
|
30
|
+
export type ListSection = {
|
|
31
|
+
title: string;
|
|
32
|
+
rows: ListRow[];
|
|
33
|
+
};
|
|
34
|
+
export type InteractiveListMessageContent = {
|
|
35
|
+
title: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
buttonText: string;
|
|
38
|
+
footer?: string;
|
|
39
|
+
sections: ListSection[];
|
|
40
|
+
};
|
|
41
|
+
export type TemplateHydratedButton = {
|
|
42
|
+
index: number;
|
|
43
|
+
quickReplyButton?: {
|
|
44
|
+
displayText: string;
|
|
45
|
+
id: string;
|
|
46
|
+
};
|
|
47
|
+
urlButton?: {
|
|
48
|
+
displayText: string;
|
|
49
|
+
url: string;
|
|
50
|
+
};
|
|
51
|
+
callButton?: {
|
|
52
|
+
displayText: string;
|
|
53
|
+
phoneNumber: string;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
export type TemplateMessageContent = {
|
|
57
|
+
body: string;
|
|
58
|
+
footer?: string;
|
|
59
|
+
title?: string;
|
|
60
|
+
buttons: TemplateHydratedButton[];
|
|
61
|
+
headerImage?: WAMediaUpload;
|
|
62
|
+
headerVideo?: WAMediaUpload;
|
|
63
|
+
headerLocation?: {
|
|
64
|
+
latitude: number;
|
|
65
|
+
longitude: number;
|
|
66
|
+
name?: string;
|
|
67
|
+
address?: string;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
export type NativeFlowButton = {
|
|
71
|
+
name: string;
|
|
72
|
+
buttonParamsJson: string;
|
|
73
|
+
};
|
|
74
|
+
export type NativeFlowOptions = {
|
|
75
|
+
footer?: string;
|
|
76
|
+
header?: {
|
|
77
|
+
title?: string;
|
|
78
|
+
subtitle?: string;
|
|
79
|
+
hasMediaAttachment?: boolean;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
export type CopyCodeButtonOptions = NativeFlowOptions & {
|
|
83
|
+
displayText?: string;
|
|
84
|
+
};
|
|
85
|
+
export type UrlButton = {
|
|
86
|
+
displayText: string;
|
|
87
|
+
url: string;
|
|
88
|
+
merchantUrl?: string;
|
|
89
|
+
};
|
|
90
|
+
export type UrlButtonOptions = {
|
|
91
|
+
footer?: string;
|
|
92
|
+
title?: string;
|
|
93
|
+
};
|
|
94
|
+
export type QuickReplyButton = {
|
|
95
|
+
displayText: string;
|
|
96
|
+
id: string;
|
|
97
|
+
};
|
|
98
|
+
export type QuickReplyOptions = {
|
|
99
|
+
footer?: string;
|
|
100
|
+
title?: string;
|
|
101
|
+
};
|
|
102
|
+
export type CombinedButton = {
|
|
103
|
+
type: 'url';
|
|
104
|
+
displayText: string;
|
|
105
|
+
url: string;
|
|
106
|
+
} | {
|
|
107
|
+
type: 'reply';
|
|
108
|
+
displayText: string;
|
|
109
|
+
id: string;
|
|
110
|
+
} | {
|
|
111
|
+
type: 'copy';
|
|
112
|
+
displayText: string;
|
|
113
|
+
copyCode: string;
|
|
114
|
+
} | {
|
|
115
|
+
type: 'call';
|
|
116
|
+
displayText: string;
|
|
117
|
+
phoneNumber: string;
|
|
118
|
+
};
|
|
119
|
+
export type CombinedButtonOptions = {
|
|
120
|
+
footer?: string;
|
|
121
|
+
title?: string;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Generate a classic WhatsApp ButtonsMessage (up to 3 buttons).
|
|
125
|
+
* Works via `sendMessage(jid, content.buttonsMessage)`.
|
|
126
|
+
*/
|
|
127
|
+
export declare const generateInteractiveButtonMessage: (content: InteractiveButtonMessageContent, options?: MediaGenerationOptions) => Promise<{
|
|
128
|
+
buttonsMessage: proto.Message.IButtonsMessage;
|
|
129
|
+
}>;
|
|
130
|
+
/**
|
|
131
|
+
* Generate a single-select list message.
|
|
132
|
+
* Works via `sendMessage(jid, content.listMessage)`.
|
|
133
|
+
*/
|
|
134
|
+
export declare const generateInteractiveListMessage: (content: InteractiveListMessageContent) => {
|
|
135
|
+
listMessage: proto.Message.IListMessage;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Generate a template message with quick-reply / URL / call buttons.
|
|
139
|
+
* Works via `sendMessage(jid, content.templateMessage)`.
|
|
140
|
+
*/
|
|
141
|
+
export declare const generateTemplateMessage: (content: TemplateMessageContent, options?: MediaGenerationOptions) => Promise<{
|
|
142
|
+
templateMessage: proto.Message.ITemplateMessage;
|
|
143
|
+
}>;
|
|
144
|
+
/**
|
|
145
|
+
* Core builder: generate a native-flow interactiveMessage with raw button definitions.
|
|
146
|
+
* All higher-level helpers (generateUrlButtonMessage, generateQuickReplyButtons, etc.) call this.
|
|
147
|
+
*/
|
|
148
|
+
export declare const generateNativeFlowMessage: (body: string, buttons: NativeFlowButton[], options?: NativeFlowOptions) => {
|
|
149
|
+
interactiveMessage: proto.Message.IInteractiveMessage;
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Button that copies a code to the clipboard when tapped.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* const msg = generateCopyCodeButton('Here is your OTP', '123456')
|
|
156
|
+
* await sock.sendMessage(jid, msg.interactiveMessage)
|
|
157
|
+
*/
|
|
158
|
+
export declare const generateCopyCodeButton: (body: string, copyCode: string, displayText?: string, options?: CopyCodeButtonOptions) => {
|
|
159
|
+
interactiveMessage: proto.Message.IInteractiveMessage;
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* One or more CTA URL buttons (opens a link in browser).
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* const msg = generateUrlButtonMessage('Visit us!', [
|
|
166
|
+
* { displayText: 'Open Website', url: 'https://example.com' }
|
|
167
|
+
* ])
|
|
168
|
+
* await sock.sendMessage(jid, msg.interactiveMessage)
|
|
169
|
+
*/
|
|
170
|
+
export declare const generateUrlButtonMessage: (body: string, buttons: UrlButton[], options?: UrlButtonOptions) => {
|
|
171
|
+
interactiveMessage: proto.Message.IInteractiveMessage;
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* One or more quick-reply buttons (sends a reply when tapped).
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* const msg = generateQuickReplyButtons('Choose an option:', [
|
|
178
|
+
* { displayText: 'Yes', id: 'yes' },
|
|
179
|
+
* { displayText: 'No', id: 'no' }
|
|
180
|
+
* ])
|
|
181
|
+
* await sock.sendMessage(jid, msg.interactiveMessage)
|
|
182
|
+
*/
|
|
183
|
+
export declare const generateQuickReplyButtons: (body: string, buttons: QuickReplyButton[], options?: QuickReplyOptions) => {
|
|
184
|
+
interactiveMessage: proto.Message.IInteractiveMessage;
|
|
185
|
+
};
|
|
186
|
+
/**
|
|
187
|
+
* Mix of url / reply / copy / call buttons in one message.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* const msg = generateCombinedButtons('What do you want?', [
|
|
191
|
+
* { type: 'url', displayText: 'Visit', url: 'https://example.com' },
|
|
192
|
+
* { type: 'reply', displayText: 'Ping', id: 'ping' },
|
|
193
|
+
* { type: 'copy', displayText: 'Copy', copyCode: 'ABC123' },
|
|
194
|
+
* { type: 'call', displayText: 'Call', phoneNumber: '+911234567890' }
|
|
195
|
+
* ])
|
|
196
|
+
* await sock.sendMessage(jid, msg.interactiveMessage)
|
|
197
|
+
*/
|
|
198
|
+
export declare const generateCombinedButtons: (body: string, buttons: CombinedButton[], options?: CombinedButtonOptions) => {
|
|
199
|
+
interactiveMessage: proto.Message.IInteractiveMessage;
|
|
200
|
+
};
|
|
201
|
+
//# sourceMappingURL=interactive-message.d.ts.map
|
|
@@ -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generators ────────────────────────────────────────────────────────────────
|
|
4
|
+
/**
|
|
5
|
+
* Generate a classic WhatsApp ButtonsMessage (up to 3 buttons).
|
|
6
|
+
* Works via `sendMessage(jid, content.buttonsMessage)`.
|
|
7
|
+
*/
|
|
8
|
+
export const generateInteractiveButtonMessage = async (content, options) => {
|
|
9
|
+
const buttons = content.buttons.map((btn, idx) => ({
|
|
10
|
+
buttonId: btn.buttonId ?? `btn-${idx}`,
|
|
11
|
+
buttonText: { displayText: btn.displayText },
|
|
12
|
+
type: proto.Message.ButtonsMessage.Button.Type.RESPONSE,
|
|
13
|
+
nativeFlowInfo: undefined
|
|
14
|
+
}));
|
|
15
|
+
const buttonsMessage = {
|
|
16
|
+
contentText: content.body,
|
|
17
|
+
footerText: content.footer,
|
|
18
|
+
buttons,
|
|
19
|
+
headerType: proto.Message.ButtonsMessage.HeaderType.EMPTY
|
|
20
|
+
};
|
|
21
|
+
if (content.headerImage && options) {
|
|
22
|
+
const media = await prepareWAMessageMedia({ image: content.headerImage }, options);
|
|
23
|
+
buttonsMessage.imageMessage = media.imageMessage;
|
|
24
|
+
buttonsMessage.headerType = proto.Message.ButtonsMessage.HeaderType.IMAGE;
|
|
25
|
+
}
|
|
26
|
+
else if (content.headerVideo && options) {
|
|
27
|
+
const media = await prepareWAMessageMedia({ video: content.headerVideo }, options);
|
|
28
|
+
buttonsMessage.videoMessage = media.videoMessage;
|
|
29
|
+
buttonsMessage.headerType = proto.Message.ButtonsMessage.HeaderType.VIDEO;
|
|
30
|
+
}
|
|
31
|
+
else if (content.headerDocument && options) {
|
|
32
|
+
const doc = content.headerDocument;
|
|
33
|
+
const media = await prepareWAMessageMedia({ document: doc, mimetype: 'application/pdf', fileName: doc.filename }, options);
|
|
34
|
+
buttonsMessage.documentMessage = media.documentMessage;
|
|
35
|
+
buttonsMessage.headerType = proto.Message.ButtonsMessage.HeaderType.DOCUMENT;
|
|
36
|
+
}
|
|
37
|
+
else if (content.title) {
|
|
38
|
+
buttonsMessage.text = content.title;
|
|
39
|
+
buttonsMessage.headerType = proto.Message.ButtonsMessage.HeaderType.TEXT;
|
|
40
|
+
}
|
|
41
|
+
return { buttonsMessage };
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Generate a single-select list message.
|
|
45
|
+
* Works via `sendMessage(jid, content.listMessage)`.
|
|
46
|
+
*/
|
|
47
|
+
export const generateInteractiveListMessage = (content) => {
|
|
48
|
+
const sections = content.sections.map(section => ({
|
|
49
|
+
title: section.title,
|
|
50
|
+
rows: section.rows.map(row => ({
|
|
51
|
+
rowId: row.rowId,
|
|
52
|
+
title: row.title,
|
|
53
|
+
description: row.description ?? ''
|
|
54
|
+
}))
|
|
55
|
+
}));
|
|
56
|
+
return {
|
|
57
|
+
listMessage: {
|
|
58
|
+
title: content.title,
|
|
59
|
+
description: content.description ?? '',
|
|
60
|
+
buttonText: content.buttonText,
|
|
61
|
+
footerText: content.footer ?? '',
|
|
62
|
+
listType: proto.Message.ListMessage.ListType.SINGLE_SELECT,
|
|
63
|
+
sections
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Generate a template message with quick-reply / URL / call buttons.
|
|
69
|
+
* Works via `sendMessage(jid, content.templateMessage)`.
|
|
70
|
+
*/
|
|
71
|
+
export const generateTemplateMessage = async (content, options) => {
|
|
72
|
+
const hydratedButtons = content.buttons.map(btn => {
|
|
73
|
+
const hydratedBtn = { index: btn.index };
|
|
74
|
+
if (btn.quickReplyButton) {
|
|
75
|
+
hydratedBtn.quickReplyButton = {
|
|
76
|
+
displayText: btn.quickReplyButton.displayText,
|
|
77
|
+
id: btn.quickReplyButton.id
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
else if (btn.urlButton) {
|
|
81
|
+
hydratedBtn.urlButton = {
|
|
82
|
+
displayText: btn.urlButton.displayText,
|
|
83
|
+
url: btn.urlButton.url
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
else if (btn.callButton) {
|
|
87
|
+
hydratedBtn.callButton = {
|
|
88
|
+
displayText: btn.callButton.displayText,
|
|
89
|
+
phoneNumber: btn.callButton.phoneNumber
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return hydratedBtn;
|
|
93
|
+
});
|
|
94
|
+
const hydratedTemplate = {
|
|
95
|
+
hydratedContentText: content.body,
|
|
96
|
+
hydratedFooterText: content.footer,
|
|
97
|
+
hydratedButtons
|
|
98
|
+
};
|
|
99
|
+
if (content.title) {
|
|
100
|
+
hydratedTemplate.hydratedTitleText = content.title;
|
|
101
|
+
}
|
|
102
|
+
if (content.headerImage && options) {
|
|
103
|
+
const media = await prepareWAMessageMedia({ image: content.headerImage }, options);
|
|
104
|
+
hydratedTemplate.imageMessage = media.imageMessage;
|
|
105
|
+
}
|
|
106
|
+
else if (content.headerVideo && options) {
|
|
107
|
+
const media = await prepareWAMessageMedia({ video: content.headerVideo }, options);
|
|
108
|
+
hydratedTemplate.videoMessage = media.videoMessage;
|
|
109
|
+
}
|
|
110
|
+
else if (content.headerLocation) {
|
|
111
|
+
hydratedTemplate.locationMessage = {
|
|
112
|
+
degreesLatitude: content.headerLocation.latitude,
|
|
113
|
+
degreesLongitude: content.headerLocation.longitude,
|
|
114
|
+
name: content.headerLocation.name,
|
|
115
|
+
address: content.headerLocation.address
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
templateMessage: {
|
|
120
|
+
hydratedTemplate
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Core builder: generate a native-flow interactiveMessage with raw button definitions.
|
|
126
|
+
* All higher-level helpers (generateUrlButtonMessage, generateQuickReplyButtons, etc.) call this.
|
|
127
|
+
*/
|
|
128
|
+
export const generateNativeFlowMessage = (body, buttons, options) => {
|
|
129
|
+
return {
|
|
130
|
+
interactiveMessage: {
|
|
131
|
+
body: { text: body },
|
|
132
|
+
footer: options?.footer ? { text: options.footer } : undefined,
|
|
133
|
+
header: options?.header
|
|
134
|
+
? {
|
|
135
|
+
title: options.header.title,
|
|
136
|
+
subtitle: options.header.subtitle,
|
|
137
|
+
hasMediaAttachment: options.header.hasMediaAttachment ?? false
|
|
138
|
+
}
|
|
139
|
+
: undefined,
|
|
140
|
+
nativeFlowMessage: {
|
|
141
|
+
buttons: buttons.map(btn => ({
|
|
142
|
+
name: btn.name,
|
|
143
|
+
buttonParamsJson: btn.buttonParamsJson
|
|
144
|
+
})),
|
|
145
|
+
messageParamsJson: ''
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* Button that copies a code to the clipboard when tapped.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* const msg = generateCopyCodeButton('Here is your OTP', '123456')
|
|
155
|
+
* await sock.sendMessage(jid, msg.interactiveMessage)
|
|
156
|
+
*/
|
|
157
|
+
export const generateCopyCodeButton = (body, copyCode, displayText = 'Copy Code', options) => {
|
|
158
|
+
return generateNativeFlowMessage(body, [
|
|
159
|
+
{
|
|
160
|
+
name: 'cta_copy',
|
|
161
|
+
buttonParamsJson: JSON.stringify({ display_text: displayText, copy_code: copyCode })
|
|
162
|
+
}
|
|
163
|
+
], options);
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* One or more CTA URL buttons (opens a link in browser).
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* const msg = generateUrlButtonMessage('Visit us!', [
|
|
170
|
+
* { displayText: 'Open Website', url: 'https://example.com' }
|
|
171
|
+
* ])
|
|
172
|
+
* await sock.sendMessage(jid, msg.interactiveMessage)
|
|
173
|
+
*/
|
|
174
|
+
export const generateUrlButtonMessage = (body, buttons, options) => {
|
|
175
|
+
const nativeButtons = buttons.map(btn => ({
|
|
176
|
+
name: 'cta_url',
|
|
177
|
+
buttonParamsJson: JSON.stringify({
|
|
178
|
+
display_text: btn.displayText,
|
|
179
|
+
url: btn.url,
|
|
180
|
+
merchant_url: btn.merchantUrl
|
|
181
|
+
})
|
|
182
|
+
}));
|
|
183
|
+
return generateNativeFlowMessage(body, nativeButtons, {
|
|
184
|
+
footer: options?.footer,
|
|
185
|
+
header: options?.title ? { title: options.title } : undefined
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* One or more quick-reply buttons (sends a reply when tapped).
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* const msg = generateQuickReplyButtons('Choose an option:', [
|
|
193
|
+
* { displayText: 'Yes', id: 'yes' },
|
|
194
|
+
* { displayText: 'No', id: 'no' }
|
|
195
|
+
* ])
|
|
196
|
+
* await sock.sendMessage(jid, msg.interactiveMessage)
|
|
197
|
+
*/
|
|
198
|
+
export const generateQuickReplyButtons = (body, buttons, options) => {
|
|
199
|
+
const nativeButtons = buttons.map(btn => ({
|
|
200
|
+
name: 'quick_reply',
|
|
201
|
+
buttonParamsJson: JSON.stringify({ display_text: btn.displayText, id: btn.id })
|
|
202
|
+
}));
|
|
203
|
+
return generateNativeFlowMessage(body, nativeButtons, {
|
|
204
|
+
footer: options?.footer,
|
|
205
|
+
header: options?.title ? { title: options.title } : undefined
|
|
206
|
+
});
|
|
207
|
+
};
|
|
208
|
+
/**
|
|
209
|
+
* Mix of url / reply / copy / call buttons in one message.
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* const msg = generateCombinedButtons('What do you want?', [
|
|
213
|
+
* { type: 'url', displayText: 'Visit', url: 'https://example.com' },
|
|
214
|
+
* { type: 'reply', displayText: 'Ping', id: 'ping' },
|
|
215
|
+
* { type: 'copy', displayText: 'Copy', copyCode: 'ABC123' },
|
|
216
|
+
* { type: 'call', displayText: 'Call', phoneNumber: '+911234567890' }
|
|
217
|
+
* ])
|
|
218
|
+
* await sock.sendMessage(jid, msg.interactiveMessage)
|
|
219
|
+
*/
|
|
220
|
+
export const generateCombinedButtons = (body, buttons, options) => {
|
|
221
|
+
const nativeButtons = buttons.map(btn => {
|
|
222
|
+
switch (btn.type) {
|
|
223
|
+
case 'url':
|
|
224
|
+
return {
|
|
225
|
+
name: 'cta_url',
|
|
226
|
+
buttonParamsJson: JSON.stringify({ display_text: btn.displayText, url: btn.url })
|
|
227
|
+
};
|
|
228
|
+
case 'reply':
|
|
229
|
+
return {
|
|
230
|
+
name: 'quick_reply',
|
|
231
|
+
buttonParamsJson: JSON.stringify({ display_text: btn.displayText, id: btn.id })
|
|
232
|
+
};
|
|
233
|
+
case 'copy':
|
|
234
|
+
return {
|
|
235
|
+
name: 'cta_copy',
|
|
236
|
+
buttonParamsJson: JSON.stringify({
|
|
237
|
+
display_text: btn.displayText,
|
|
238
|
+
copy_code: btn.copyCode
|
|
239
|
+
})
|
|
240
|
+
};
|
|
241
|
+
case 'call':
|
|
242
|
+
return {
|
|
243
|
+
name: 'cta_call',
|
|
244
|
+
buttonParamsJson: JSON.stringify({
|
|
245
|
+
display_text: btn.displayText,
|
|
246
|
+
phone_number: btn.phoneNumber
|
|
247
|
+
})
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
return generateNativeFlowMessage(body, nativeButtons, {
|
|
252
|
+
footer: options?.footer,
|
|
253
|
+
header: options?.title ? { title: options.title } : undefined
|
|
254
|
+
});
|
|
255
|
+
};
|
|
256
|
+
//# sourceMappingURL=interactive-message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interactive-message.js","sourceRoot":"","sources":["../../src/Utils/interactive-message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAE9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAqHlD,kFAAkF;AAElF;;;GAGG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,KAAK,EACpD,OAAwC,EACxC,OAAgC,EAC6B,EAAE;IAC/D,MAAM,OAAO,GAA2C,OAAO,CAAC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AAE,GAAG,CAAC,GAAG,EAAE,CAAC;iBACjF,CAAA;YACF,KAAK,OAAO;gBACX,OAAO;oBACN,IAAI,EAAE,aAAa;oBACnB,gBAAgB,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,YAAY,EAAE,GAAG,CAAC,WAAW,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC;iBAC/E,CAAA;YACF,KAAK,MAAM;gBACV,OAAO;oBACN,IAAI,EAAE,UAAU;oBAChB,gBAAgB,EAAE,IAAI,CAAC,SAAS,CAAC;wBAChC,YAAY,EAAE,GAAG,CAAC,WAAW;wBAC7B,SAAS,EAAE,GAAG,CAAC,QAAQ;qBACvB,CAAC;iBACF,CAAA;YACF,KAAK,MAAM;gBACV,OAAO;oBACN,IAAI,EAAE,UAAU;oBAChB,gBAAgB,EAAE,IAAI,CAAC,SAAS,CAAC;wBAChC,YAAY,EAAE,GAAG,CAAC,WAAW;wBAC7B,YAAY,EAAE,GAAG,CAAC,WAAW;qBAC7B,CAAC;iBACF,CAAA;QACH,CAAC;IACF,CAAC,CAAC,CAAA;IAEF,OAAO,yBAAyB,CAAC,IAAI,EAAE,aAAa,EAAE;QACrD,MAAM,EAAE,OAAO,EAAE,MAAM;QACvB,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS;KAC7D,CAAC,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -7,6 +7,13 @@ import { type MediaType } from '../Defaults/index.js';
|
|
|
7
7
|
import type { DownloadableMessage, MediaConnInfo, MediaDecryptionKeyInfo, SocketConfig, WAMediaUpload, WAMediaUploadFunction, WAMessageContent, WAMessageKey } from '../Types/index.js';
|
|
8
8
|
import { type BinaryNode } from '../WABinary/index.js';
|
|
9
9
|
import type { ILogger } from './logger.js';
|
|
10
|
+
export declare const getImageProcessingLibrary: () => Promise<{
|
|
11
|
+
sharp: any;
|
|
12
|
+
jimp?: undefined;
|
|
13
|
+
} | {
|
|
14
|
+
jimp: typeof import("jimp");
|
|
15
|
+
sharp?: undefined;
|
|
16
|
+
}>;
|
|
10
17
|
export declare const hkdfInfoKey: (type: MediaType) => string;
|
|
11
18
|
export declare const getRawMediaUploadData: (media: WAMediaUpload, mediaType: MediaType, logger?: ILogger) => Promise<{
|
|
12
19
|
filePath: string;
|
|
@@ -56,6 +63,7 @@ export declare const getStream: (item: WAMediaUpload, opts?: RequestInit & {
|
|
|
56
63
|
/** generates a thumbnail for a given media, if required */
|
|
57
64
|
export declare function generateThumbnail(file: string, mediaType: 'video' | 'image', options: {
|
|
58
65
|
logger?: ILogger;
|
|
66
|
+
hdMode?: boolean;
|
|
59
67
|
}): Promise<{
|
|
60
68
|
thumbnail: string | undefined;
|
|
61
69
|
originalImageDimensions: {
|
|
@@ -70,9 +78,11 @@ type EncryptedStreamOptions = {
|
|
|
70
78
|
saveOriginalFileIfRequired?: boolean;
|
|
71
79
|
logger?: ILogger;
|
|
72
80
|
opts?: RequestInit;
|
|
81
|
+
/** Optional mediaKey to reuse (required for sticker pack thumbnail to match ZIP encryption) */
|
|
82
|
+
mediaKey?: Buffer | Uint8Array;
|
|
73
83
|
};
|
|
74
|
-
export declare const encryptedStream: (media: WAMediaUpload, mediaType: MediaType, { logger, saveOriginalFileIfRequired, opts }?: EncryptedStreamOptions) => Promise<{
|
|
75
|
-
mediaKey:
|
|
84
|
+
export declare const encryptedStream: (media: WAMediaUpload, mediaType: MediaType, { logger, saveOriginalFileIfRequired, opts, mediaKey: providedMediaKey }?: EncryptedStreamOptions) => Promise<{
|
|
85
|
+
mediaKey: Buffer<ArrayBuffer>;
|
|
76
86
|
originalFilePath: string | undefined;
|
|
77
87
|
encFilePath: string;
|
|
78
88
|
mac: Buffer<ArrayBuffer>;
|
|
@@ -99,6 +109,10 @@ type MediaUploadResult = {
|
|
|
99
109
|
meta_hmac?: string;
|
|
100
110
|
ts?: number;
|
|
101
111
|
fbid?: number;
|
|
112
|
+
thumbnail_info?: {
|
|
113
|
+
thumbnail_sha256?: string;
|
|
114
|
+
thumbnail_direct_path?: string;
|
|
115
|
+
};
|
|
102
116
|
};
|
|
103
117
|
export type UploadParams = {
|
|
104
118
|
url: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages-media.d.ts","sourceRoot":"","sources":["../../src/Utils/messages-media.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAKjC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAIlC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAC5C,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AACzB,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAC9C,OAAO,
|
|
1
|
+
{"version":3,"file":"messages-media.d.ts","sourceRoot":"","sources":["../../src/Utils/messages-media.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAKjC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAIlC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAC5C,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AACzB,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAC9C,OAAO,EAIN,KAAK,SAAS,EAEd,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EAEX,mBAAmB,EACnB,aAAa,EACb,sBAAsB,EAEtB,YAAY,EAEZ,aAAa,EACb,qBAAqB,EACrB,gBAAgB,EAChB,YAAY,EACZ,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,KAAK,UAAU,EAAmE,MAAM,aAAa,CAAA;AAG9G,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAIvC,eAAO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EAAE,MAAM,CAAA;IAClB,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,cAAc,CAAC,EAAE;QAChB,gBAAgB,CAAC,EAAE,MAAM,CAAA;QACzB,qBAAqB,CAAC,EAAE,MAAM,CAAA;KAC9B,CAAA;CACD,CAAA;AAED,MAAM,MAAM,YAAY,GAAG;IAC1B,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,KAAK,CAAA;CACb,CAAA;AAED,eAAO,MAAM,kBAAkB,GAC9B,8CAA8C,YAAY,EAC1D,sBAAiB,KACf,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAuEvC,CAAA;AAwDD,eAAO,MAAM,mBAAmB,GAC/B,oDAAoD,YAAY,EAChE,kBAAkB,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,aAAa,CAAC,KAC1D,qBAuFF,CAAA;AAMD;;GAEG;AACH,eAAO,MAAM,wBAAwB,GAAI,KAAK,YAAY,EAAE,UAAU,MAAM,GAAG,UAAU,EAAE,MAAM,MAAM,eAwCtG,CAAA;AAED,eAAO,MAAM,oBAAoB,GAAI,MAAM,UAAU;;;;;;;CA+BpD,CAAA;AAED,eAAO,MAAM,qBAAqB,GACjC,oBAAoB;IAAE,UAAU,EAAE,UAAU,CAAC;IAAC,EAAE,EAAE,UAAU,CAAA;CAAE,EAC9D,UAAU,UAAU,EACpB,OAAO,MAAM,iCAKb,CAAA;AAED,eAAO,MAAM,0BAA0B,GAAI,MAAM,MAAM,0BACiB,CAAA"}
|
|
@@ -8,12 +8,12 @@ import { join } from 'path';
|
|
|
8
8
|
import { Readable, Transform } from 'stream';
|
|
9
9
|
import { URL } from 'url';
|
|
10
10
|
import { proto } from '../../WAProto/index.js';
|
|
11
|
-
import { DEFAULT_ORIGIN, MEDIA_HKDF_KEY_MAPPING, MEDIA_PATH_MAP } from '../Defaults/index.js';
|
|
11
|
+
import { DEFAULT_ORIGIN, MEDIA_HKDF_KEY_MAPPING, MEDIA_PATH_MAP, NEWSLETTER_MEDIA_PATH_MAP } from '../Defaults/index.js';
|
|
12
12
|
import { getBinaryNodeChild, getBinaryNodeChildBuffer, jidNormalizedUser } from '../WABinary/index.js';
|
|
13
13
|
import { aesDecryptGCM, aesEncryptGCM, hkdf } from './crypto.js';
|
|
14
14
|
import { generateMessageIDV2 } from './generics.js';
|
|
15
15
|
const getTmpFilesDirectory = () => tmpdir();
|
|
16
|
-
const getImageProcessingLibrary = async () => {
|
|
16
|
+
export const getImageProcessingLibrary = async () => {
|
|
17
17
|
//@ts-ignore
|
|
18
18
|
const [jimp, sharp] = await Promise.all([import('jimp').catch(() => { }), import('sharp').catch(() => { })]);
|
|
19
19
|
if (sharp) {
|
|
@@ -267,8 +267,9 @@ export const getStream = async (item, opts) => {
|
|
|
267
267
|
export async function generateThumbnail(file, mediaType, options) {
|
|
268
268
|
let thumbnail;
|
|
269
269
|
let originalImageDimensions;
|
|
270
|
+
const hdMode = options.hdMode === true;
|
|
270
271
|
if (mediaType === 'image') {
|
|
271
|
-
const { buffer, original } = await extractImageThumb(file);
|
|
272
|
+
const { buffer, original } = await extractImageThumb(file, hdMode ? 320 : undefined);
|
|
272
273
|
thumbnail = buffer.toString('base64');
|
|
273
274
|
if (original.width && original.height) {
|
|
274
275
|
originalImageDimensions = {
|
|
@@ -278,9 +279,10 @@ export async function generateThumbnail(file, mediaType, options) {
|
|
|
278
279
|
}
|
|
279
280
|
}
|
|
280
281
|
else if (mediaType === 'video') {
|
|
282
|
+
const thumbSize = hdMode ? { width: 320, height: 180 } : { width: 32, height: 32 };
|
|
281
283
|
const imgFilename = join(getTmpFilesDirectory(), generateMessageIDV2() + '.jpg');
|
|
282
284
|
try {
|
|
283
|
-
await extractVideoThumb(file, imgFilename, '00:00:00',
|
|
285
|
+
await extractVideoThumb(file, imgFilename, '00:00:00', thumbSize);
|
|
284
286
|
const buff = await fs.readFile(imgFilename);
|
|
285
287
|
thumbnail = buff.toString('base64');
|
|
286
288
|
await fs.unlink(imgFilename);
|
|
@@ -306,10 +308,10 @@ export const getHttpStream = async (url, options = {}) => {
|
|
|
306
308
|
// @ts-ignore Node18+ Readable.fromWeb exists
|
|
307
309
|
return response.body instanceof Readable ? response.body : Readable.fromWeb(response.body);
|
|
308
310
|
};
|
|
309
|
-
export const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfRequired, opts } = {}) => {
|
|
311
|
+
export const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfRequired, opts, mediaKey: providedMediaKey } = {}) => {
|
|
310
312
|
const { stream, type } = await getStream(media, opts);
|
|
311
313
|
logger?.debug('fetched media stream');
|
|
312
|
-
const mediaKey = Crypto.randomBytes(32);
|
|
314
|
+
const mediaKey = providedMediaKey ? Buffer.from(providedMediaKey) : Crypto.randomBytes(32);
|
|
313
315
|
const { cipherKey, iv, macKey } = await getMediaKeys(mediaKey, mediaType);
|
|
314
316
|
const encFilePath = join(getTmpFilesDirectory(), mediaType + generateMessageIDV2() + '-enc');
|
|
315
317
|
const encFileWriteStream = createWriteStream(encFilePath);
|
|
@@ -627,7 +629,7 @@ const uploadMedia = async (params, logger) => {
|
|
|
627
629
|
}
|
|
628
630
|
};
|
|
629
631
|
export const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options }, refreshMediaConn) => {
|
|
630
|
-
return async (filePath, { mediaType, fileEncSha256B64, timeoutMs }) => {
|
|
632
|
+
return async (filePath, { mediaType, fileEncSha256B64, timeoutMs, newsletter }) => {
|
|
631
633
|
// send a query JSON to obtain the url & auth token to upload our media
|
|
632
634
|
let uploadInfo = await refreshMediaConn(false);
|
|
633
635
|
let urls;
|
|
@@ -648,7 +650,12 @@ export const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, opt
|
|
|
648
650
|
for (const { hostname } of hosts) {
|
|
649
651
|
logger.debug(`uploading to "${hostname}"`);
|
|
650
652
|
const auth = encodeURIComponent(uploadInfo.auth);
|
|
651
|
-
|
|
653
|
+
// Use newsletter-specific path when uploading for a newsletter/channel
|
|
654
|
+
const mediaPath = (newsletter ? NEWSLETTER_MEDIA_PATH_MAP[mediaType] : undefined) || MEDIA_PATH_MAP[mediaType];
|
|
655
|
+
let url = `https://${hostname}${mediaPath}/${fileEncSha256B64}?auth=${auth}&token=${fileEncSha256B64}`;
|
|
656
|
+
if (newsletter) {
|
|
657
|
+
url += '&server_thumb_gen=1';
|
|
658
|
+
}
|
|
652
659
|
let result;
|
|
653
660
|
try {
|
|
654
661
|
result = await uploadMedia({
|
|
@@ -660,11 +667,13 @@ export const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, opt
|
|
|
660
667
|
}, logger);
|
|
661
668
|
if (result?.url || result?.direct_path) {
|
|
662
669
|
urls = {
|
|
663
|
-
mediaUrl: result.url,
|
|
670
|
+
mediaUrl: result.url || result.direct_path,
|
|
664
671
|
directPath: result.direct_path,
|
|
665
672
|
meta_hmac: result.meta_hmac,
|
|
666
673
|
fbid: result.fbid,
|
|
667
|
-
ts: result.ts
|
|
674
|
+
ts: result.ts,
|
|
675
|
+
thumbnailDirectPath: result.thumbnail_info?.thumbnail_direct_path,
|
|
676
|
+
thumbnailSha256: result.thumbnail_info?.thumbnail_sha256
|
|
668
677
|
};
|
|
669
678
|
break;
|
|
670
679
|
}
|