@kyyinfinite/baileys 1.0.0 → 2.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/README.md +408 -64
- package/WAProto/WAProto.proto +360 -916
- package/WAProto/fix-imports.js +22 -18
- package/WAProto/index.d.ts +14015 -0
- package/WAProto/index.js +47122 -81757
- package/engine-requirements.js +10 -0
- package/lib/Defaults/index.d.ts +15 -14
- package/lib/Defaults/index.d.ts.map +1 -1
- package/lib/Defaults/index.js +99 -107
- package/lib/Defaults/index.js.map +1 -1
- package/lib/Kyyinfinite/AIRich.js +2041 -0
- package/lib/Kyyinfinite/BaseBuilder.js +64 -0
- package/lib/Kyyinfinite/Button.js +341 -0
- package/lib/Kyyinfinite/ButtonV2.js +175 -0
- package/lib/Kyyinfinite/Carousel.js +125 -0
- package/lib/Kyyinfinite/Foad.js +542 -0
- package/lib/Kyyinfinite/Foad2.js +466 -0
- package/lib/Kyyinfinite/Simple/AIBuilder.js +18 -0
- package/lib/Kyyinfinite/Simple/BuilderFactories.js +17 -0
- package/lib/Kyyinfinite/Simple/ButtonBuilder.js +107 -0
- package/lib/Kyyinfinite/Simple/CardBuilder.js +179 -0
- package/lib/Kyyinfinite/Simple/CarouselBuilder.js +97 -0
- package/lib/Kyyinfinite/Simple/FoadBuilder.js +18 -0
- package/lib/Kyyinfinite/Simple/MediaBuilder.js +35 -0
- package/lib/Kyyinfinite/Simple/MessageBuilder.js +41 -0
- package/lib/Kyyinfinite/Simple/MessageTypesBuilder.js +3 -0
- package/lib/Kyyinfinite/Simple/SimpleBuilder.js +28 -0
- package/lib/Kyyinfinite/Simple/SimpleClient.js +83 -0
- package/lib/Kyyinfinite/Simple/TextBuilder.js +22 -0
- package/lib/Kyyinfinite/Simple/index.d.ts +141 -0
- package/lib/Kyyinfinite/Simple/index.js +31 -0
- package/lib/Kyyinfinite/Toolkit.js +453 -0
- package/lib/Kyyinfinite/constants.js +1 -0
- package/lib/Kyyinfinite/errors.js +39 -0
- package/lib/Kyyinfinite/index.d.ts +2 -0
- package/lib/Kyyinfinite/index.js +2 -0
- package/lib/Kyyinfinite/wrapper.d.ts +2 -0
- package/lib/Kyyinfinite/wrapper.js +10 -0
- package/lib/Signal/Group/group_cipher.js.map +1 -1
- package/lib/Signal/Group/keyhelper.d.ts.map +1 -1
- package/lib/Signal/Group/keyhelper.js.map +1 -1
- package/lib/Signal/Group/sender-chain-key.js.map +1 -1
- package/lib/Signal/Group/sender-key-message.js.map +1 -1
- package/lib/Signal/Group/sender-message-key.js.map +1 -1
- package/lib/Signal/libsignal.d.ts.map +1 -1
- package/lib/Signal/libsignal.js +45 -17
- package/lib/Signal/libsignal.js.map +1 -1
- package/lib/Signal/lid-mapping.d.ts +4 -0
- package/lib/Signal/lid-mapping.d.ts.map +1 -1
- package/lib/Signal/lid-mapping.js +6 -0
- package/lib/Signal/lid-mapping.js.map +1 -1
- package/lib/Socket/business.d.ts +213 -532
- package/lib/Socket/business.d.ts.map +1 -1
- package/lib/Socket/business.js +358 -401
- package/lib/Socket/chats.d.ts +16 -2
- package/lib/Socket/chats.d.ts.map +1 -1
- package/lib/Socket/chats.js +247 -40
- package/lib/Socket/chats.js.map +1 -1
- package/lib/Socket/communities.d.ts +269 -641
- package/lib/Socket/communities.d.ts.map +1 -1
- package/lib/Socket/groups.d.ts +13 -2
- package/lib/Socket/groups.d.ts.map +1 -1
- package/lib/Socket/groups.js +21 -1
- package/lib/Socket/groups.js.map +1 -1
- package/lib/Socket/index.d.ts +255 -631
- package/lib/Socket/index.d.ts.map +1 -1
- package/lib/Socket/index.js +9 -10
- package/lib/Socket/index.js.map +1 -1
- package/lib/Socket/messages-recv.d.ts +23 -58
- package/lib/Socket/messages-recv.d.ts.map +1 -1
- package/lib/Socket/messages-recv.js +645 -181
- package/lib/Socket/messages-recv.js.map +1 -1
- package/lib/Socket/messages-send.d.ts +195 -575
- package/lib/Socket/messages-send.d.ts.map +1 -1
- package/lib/Socket/messages-send.js +1099 -1549
- package/lib/Socket/messages-send.js.map +1 -1
- package/lib/Socket/mex.d.ts.map +1 -1
- package/lib/Socket/mex.js +2 -8
- package/lib/Socket/mex.js.map +1 -1
- package/lib/Socket/newsletter.d.ts +11 -18
- package/lib/Socket/newsletter.d.ts.map +1 -1
- package/lib/Socket/newsletter.js +167 -302
- package/lib/Socket/newsletter.js.map +1 -1
- package/lib/Socket/socket.d.ts +6 -2
- package/lib/Socket/socket.d.ts.map +1 -1
- package/lib/Socket/socket.js +59 -25
- package/lib/Socket/socket.js.map +1 -1
- package/lib/Types/Auth.d.ts +1 -0
- package/lib/Types/Auth.d.ts.map +1 -1
- package/lib/Types/Bussines.d.ts +22 -34
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Call.d.ts.map +1 -1
- package/lib/Types/Chat.d.ts +1 -0
- package/lib/Types/Chat.d.ts.map +1 -1
- package/lib/Types/Contact.d.ts +2 -0
- package/lib/Types/Contact.d.ts.map +1 -1
- package/lib/Types/Events.d.ts +20 -1
- package/lib/Types/Events.d.ts.map +1 -1
- package/lib/Types/GroupMetadata.d.ts +4 -1
- package/lib/Types/GroupMetadata.d.ts.map +1 -1
- package/lib/Types/Message.d.ts +239 -341
- package/lib/Types/Message.d.ts.map +1 -1
- package/lib/Types/Message.js.map +1 -1
- package/lib/Types/{Newsletter.d.ts → Mex.d.ts} +11 -5
- package/lib/Types/Mex.d.ts.map +1 -0
- package/lib/Types/{Newsletter.js → Mex.js} +9 -3
- package/lib/Types/Mex.js.map +1 -0
- package/lib/Types/Signal.d.ts +12 -1
- package/lib/Types/Signal.d.ts.map +1 -1
- package/lib/Types/Socket.d.ts +126 -148
- package/lib/Types/Socket.d.ts.map +1 -1
- package/lib/Types/State.d.ts +58 -0
- package/lib/Types/State.d.ts.map +1 -1
- package/lib/Types/State.js +43 -0
- package/lib/Types/State.js.map +1 -1
- package/lib/Types/index.d.ts +52 -52
- package/lib/Types/index.d.ts.map +1 -1
- package/lib/Types/index.js +23 -30
- package/lib/Types/index.js.map +1 -1
- package/lib/Utils/auth-utils.d.ts +5 -0
- package/lib/Utils/auth-utils.d.ts.map +1 -1
- package/lib/Utils/auth-utils.js +12 -0
- package/lib/Utils/auth-utils.js.map +1 -1
- package/lib/Utils/browser-utils.d.ts.map +1 -1
- package/lib/Utils/browser-utils.js +1 -0
- package/lib/Utils/browser-utils.js.map +1 -1
- package/lib/Utils/chat-utils.d.ts +34 -4
- package/lib/Utils/chat-utils.d.ts.map +1 -1
- package/lib/Utils/chat-utils.js +80 -20
- package/lib/Utils/chat-utils.js.map +1 -1
- package/lib/Utils/companion-reg-client-utils.d.ts +17 -0
- package/lib/Utils/companion-reg-client-utils.d.ts.map +1 -0
- package/lib/Utils/companion-reg-client-utils.js +35 -0
- package/lib/Utils/companion-reg-client-utils.js.map +1 -0
- package/lib/Utils/crypto.d.ts +12 -12
- package/lib/Utils/crypto.d.ts.map +1 -1
- package/lib/Utils/crypto.js.map +1 -1
- package/lib/Utils/decode-wa-message.d.ts +18 -0
- package/lib/Utils/decode-wa-message.d.ts.map +1 -1
- package/lib/Utils/decode-wa-message.js +34 -0
- package/lib/Utils/decode-wa-message.js.map +1 -1
- package/lib/Utils/event-buffer.d.ts +2 -0
- package/lib/Utils/event-buffer.d.ts.map +1 -1
- package/lib/Utils/event-buffer.js +49 -1
- package/lib/Utils/event-buffer.js.map +1 -1
- package/lib/Utils/generics.d.ts +3 -2
- package/lib/Utils/generics.d.ts.map +1 -1
- package/lib/Utils/generics.js +10 -1
- package/lib/Utils/generics.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 +12 -9
- package/lib/Utils/history.js.map +1 -1
- package/lib/Utils/identity-change-handler.d.ts +7 -0
- package/lib/Utils/identity-change-handler.d.ts.map +1 -1
- package/lib/Utils/identity-change-handler.js +1 -0
- package/lib/Utils/identity-change-handler.js.map +1 -1
- package/lib/Utils/index.d.ts +22 -25
- package/lib/Utils/index.d.ts.map +1 -1
- package/lib/Utils/index.js +2 -4
- package/lib/Utils/index.js.map +1 -1
- package/lib/Utils/link-preview.js +2 -2
- package/lib/Utils/link-preview.js.map +1 -1
- package/lib/Utils/logger.d.ts +1 -2
- package/lib/Utils/logger.d.ts.map +1 -1
- package/lib/Utils/message-retry-manager.d.ts +5 -0
- package/lib/Utils/message-retry-manager.d.ts.map +1 -1
- package/lib/Utils/message-retry-manager.js +40 -0
- package/lib/Utils/message-retry-manager.js.map +1 -1
- package/lib/Utils/messages-media.d.ts +16 -13
- package/lib/Utils/messages-media.d.ts.map +1 -1
- package/lib/Utils/messages-media.js +85 -79
- package/lib/Utils/messages-media.js.map +1 -1
- package/lib/Utils/messages.d.ts +1 -1
- package/lib/Utils/messages.d.ts.map +1 -1
- package/lib/Utils/messages.js +751 -1096
- package/lib/Utils/messages.js.map +1 -1
- package/lib/Utils/noise-handler.d.ts +1 -1
- package/lib/Utils/process-message.d.ts.map +1 -1
- package/lib/Utils/process-message.js +103 -1
- package/lib/Utils/process-message.js.map +1 -1
- package/lib/Utils/signal.d.ts +13 -0
- package/lib/Utils/signal.d.ts.map +1 -1
- package/lib/Utils/signal.js +42 -0
- package/lib/Utils/signal.js.map +1 -1
- package/lib/Utils/sync-action-utils.d.ts.map +1 -1
- package/lib/Utils/sync-action-utils.js +1 -0
- package/lib/Utils/sync-action-utils.js.map +1 -1
- package/lib/Utils/tc-token-utils.d.ts +26 -1
- package/lib/Utils/tc-token-utils.d.ts.map +1 -1
- package/lib/Utils/tc-token-utils.js +151 -5
- package/lib/Utils/tc-token-utils.js.map +1 -1
- package/lib/Utils/validate-connection.d.ts.map +1 -1
- package/lib/Utils/validate-connection.js +12 -2
- package/lib/Utils/validate-connection.js.map +1 -1
- package/lib/WABinary/decode.d.ts +1 -1
- package/lib/WABinary/decode.d.ts.map +1 -1
- package/lib/WABinary/generic-utils.d.ts +1 -3
- package/lib/WABinary/generic-utils.d.ts.map +1 -1
- package/lib/WABinary/generic-utils.js +0 -78
- package/lib/WABinary/generic-utils.js.map +1 -1
- package/lib/WAM/encode.d.ts +1 -1
- package/lib/WAM/encode.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +26 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -1
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/index.d.ts +1 -0
- package/lib/WAUSync/Protocols/index.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/index.js +1 -0
- package/lib/WAUSync/Protocols/index.js.map +1 -1
- package/lib/WAUSync/USyncQuery.d.ts +1 -0
- package/lib/WAUSync/USyncQuery.d.ts.map +1 -1
- package/lib/WAUSync/USyncQuery.js +6 -2
- package/lib/WAUSync/USyncQuery.js.map +1 -1
- package/lib/WAUSync/USyncUser.d.ts +4 -0
- package/lib/WAUSync/USyncUser.d.ts.map +1 -1
- package/lib/WAUSync/USyncUser.js +8 -0
- package/lib/WAUSync/USyncUser.js.map +1 -1
- package/lib/index.d.ts +3 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +13 -12
- package/lib/index.js.map +1 -1
- package/package.json +93 -23
- package/LICENSE +0 -21
- package/lib/Socket/dugong.d.ts +0 -130
- package/lib/Socket/dugong.d.ts.map +0 -1
- package/lib/Socket/dugong.js +0 -768
- package/lib/Socket/dugong.js.map +0 -1
- package/lib/Types/Newsletter.d.ts.map +0 -1
- package/lib/Types/Newsletter.js.map +0 -1
- package/lib/Utils/kyy-features.d.ts +0 -158
- package/lib/Utils/kyy-features.js +0 -365
- package/lib/Utils/rich-messages.d.ts +0 -277
- package/lib/Utils/rich-messages.d.ts.map +0 -1
- package/lib/Utils/rich-messages.js +0 -1144
- package/lib/Utils/rich-messages.js.map +0 -1
- package/lib/Utils/sticker-pack.d.ts +0 -10
- package/lib/Utils/sticker-pack.js +0 -111
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
class BaseBuilder {
|
|
2
|
+
constructor() {
|
|
3
|
+
this._title = '';
|
|
4
|
+
this._subtitle = '';
|
|
5
|
+
this._body = '';
|
|
6
|
+
this._footer = '';
|
|
7
|
+
this._contextInfo = {};
|
|
8
|
+
this._extraPayload = {};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
setTitle(title) {
|
|
12
|
+
if (typeof title !== 'string') {
|
|
13
|
+
throw new TypeError('Title must be a string');
|
|
14
|
+
}
|
|
15
|
+
this._title = title;
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
setSubtitle(subtitle) {
|
|
20
|
+
if (typeof subtitle !== 'string') {
|
|
21
|
+
throw new TypeError('Subtitle must be a string');
|
|
22
|
+
}
|
|
23
|
+
this._subtitle = subtitle;
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
setBody(body) {
|
|
28
|
+
if (typeof body !== 'string') {
|
|
29
|
+
throw new TypeError('Body must be a string');
|
|
30
|
+
}
|
|
31
|
+
this._body = body;
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
setFooter(footer) {
|
|
36
|
+
if (typeof footer !== 'string') {
|
|
37
|
+
throw new TypeError('Footer must be a string');
|
|
38
|
+
}
|
|
39
|
+
this._footer = footer;
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
setContextInfo(obj) {
|
|
44
|
+
if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {
|
|
45
|
+
throw new TypeError('ContextInfo must be a plain object');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
this._contextInfo = obj;
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
addPayload(obj) {
|
|
53
|
+
if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {
|
|
54
|
+
throw new TypeError('Payload must be a plain object');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
Object.assign(this._extraPayload, obj);
|
|
58
|
+
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
export { BaseBuilder };
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import { generateWAMessageFromContent, prepareWAMessageMedia } from '../Utils/messages.js';
|
|
2
|
+
import { generateMessageIDV2 } from '../Utils/generics.js';
|
|
3
|
+
import { BaseBuilder } from './BaseBuilder.js';
|
|
4
|
+
import { Toolkit } from './Toolkit.js';
|
|
5
|
+
|
|
6
|
+
class Button extends BaseBuilder {
|
|
7
|
+
#client;
|
|
8
|
+
|
|
9
|
+
constructor(client) {
|
|
10
|
+
super();
|
|
11
|
+
if (!client) {
|
|
12
|
+
throw new Error('Socket is required');
|
|
13
|
+
}
|
|
14
|
+
this.#client = client;
|
|
15
|
+
|
|
16
|
+
this._buttons = [];
|
|
17
|
+
this._data;
|
|
18
|
+
this._currentSelectionIndex = -1;
|
|
19
|
+
this._currentSectionIndex = -1;
|
|
20
|
+
this._params = {};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
loadFrom(msg) {
|
|
24
|
+
if (!msg) throw new Error('interactiveMessage needed');
|
|
25
|
+
if (!msg.interactiveMessage) throw new Error('interactiveMessage not found');
|
|
26
|
+
|
|
27
|
+
const { interactiveMessage, ...extraPayload } = msg;
|
|
28
|
+
const iM = interactiveMessage;
|
|
29
|
+
const header = iM.header || {};
|
|
30
|
+
const nativeFlow = iM.nativeFlowMessage || {};
|
|
31
|
+
|
|
32
|
+
this._title = header.title || '';
|
|
33
|
+
this._subtitle = header.subtitle || '';
|
|
34
|
+
this._body = iM.body?.text || '';
|
|
35
|
+
this._footer = iM.footer?.text || '';
|
|
36
|
+
this._contextInfo = iM.contextInfo || {};
|
|
37
|
+
this._extraPayload = extraPayload;
|
|
38
|
+
|
|
39
|
+
this._buttons = Array.isArray(nativeFlow.buttons)
|
|
40
|
+
? nativeFlow.buttons.map((button) => ({
|
|
41
|
+
...button,
|
|
42
|
+
buttonParamsJson: typeof button.buttonParamsJson === 'string' ? button.buttonParamsJson : JSON.stringify(button.buttonParamsJson || {}),
|
|
43
|
+
}))
|
|
44
|
+
: [];
|
|
45
|
+
|
|
46
|
+
this._data = header.imageMessage
|
|
47
|
+
? { imageMessage: header.imageMessage }
|
|
48
|
+
: header.videoMessage
|
|
49
|
+
? { videoMessage: header.videoMessage }
|
|
50
|
+
: header.documentMessage
|
|
51
|
+
? { documentMessage: header.documentMessage }
|
|
52
|
+
: header.productMessage
|
|
53
|
+
? { productMessage: header.productMessage }
|
|
54
|
+
: undefined;
|
|
55
|
+
|
|
56
|
+
this._params = {};
|
|
57
|
+
|
|
58
|
+
if (typeof nativeFlow.messageParamsJson === 'string') {
|
|
59
|
+
try {
|
|
60
|
+
this._params = JSON.parse(nativeFlow.messageParamsJson || '{}');
|
|
61
|
+
} catch {
|
|
62
|
+
this._params = {};
|
|
63
|
+
}
|
|
64
|
+
} else if (nativeFlow.messageParamsJson && typeof nativeFlow.messageParamsJson === 'object') {
|
|
65
|
+
this._params = { ...nativeFlow.messageParamsJson };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
this._currentSelectionIndex = this._buttons.findLastIndex((button) => button.name === 'single_select');
|
|
69
|
+
|
|
70
|
+
this._currentSectionIndex = -1;
|
|
71
|
+
|
|
72
|
+
if (this._currentSelectionIndex !== -1) {
|
|
73
|
+
try {
|
|
74
|
+
const button = this._buttons[this._currentSelectionIndex];
|
|
75
|
+
const params = JSON.parse(button.buttonParamsJson || '{}');
|
|
76
|
+
|
|
77
|
+
if (Array.isArray(params.sections) && params.sections.length) {
|
|
78
|
+
this._currentSectionIndex = params.sections.length - 1;
|
|
79
|
+
}
|
|
80
|
+
} catch {
|
|
81
|
+
this._currentSelectionIndex = -1;
|
|
82
|
+
this._currentSectionIndex = -1;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
setImage(path, options = {}) {
|
|
90
|
+
if (!path) throw new Error('Url or buffer needed');
|
|
91
|
+
Buffer.isBuffer(path) ? (this._data = { image: path, ...options }) : (this._data = { image: { url: path }, ...options });
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
setDocument(path, options = {}) {
|
|
96
|
+
if (!path) throw new Error('Url or buffer needed');
|
|
97
|
+
Buffer.isBuffer(path) ? (this._data = { document: path, ...options }) : (this._data = { document: { url: path }, ...options });
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
setMedia(obj) {
|
|
102
|
+
if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {
|
|
103
|
+
throw new TypeError('Media must be a plain object');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
this._data = obj;
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
clearButtons() {
|
|
111
|
+
this._buttons = [];
|
|
112
|
+
return this;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
setParams(obj) {
|
|
116
|
+
this._params = obj;
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
addButton(name, params) {
|
|
121
|
+
this._buttons.push({
|
|
122
|
+
name,
|
|
123
|
+
buttonParamsJson: typeof params === 'string' ? params : JSON.stringify(params),
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
return this;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
makeRow(header = '', title = '', description = '', id = '') {
|
|
130
|
+
if (this._currentSelectionIndex === -1 || this._currentSectionIndex === -1) {
|
|
131
|
+
throw new Error('You need to create a selection and a section first');
|
|
132
|
+
}
|
|
133
|
+
const buttonParams = JSON.parse(this._buttons[this._currentSelectionIndex].buttonParamsJson);
|
|
134
|
+
buttonParams.sections[this._currentSectionIndex].rows.push({ header, title, description, id });
|
|
135
|
+
this._buttons[this._currentSelectionIndex].buttonParamsJson = JSON.stringify(buttonParams);
|
|
136
|
+
return this;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
makeSection(title = '', highlight_label = '') {
|
|
140
|
+
if (this._currentSelectionIndex === -1) {
|
|
141
|
+
throw new Error('You need to create a selection first');
|
|
142
|
+
}
|
|
143
|
+
const buttonParams = JSON.parse(this._buttons[this._currentSelectionIndex].buttonParamsJson);
|
|
144
|
+
buttonParams.sections.push({ title, highlight_label, rows: [] });
|
|
145
|
+
this._currentSectionIndex = buttonParams.sections.length - 1;
|
|
146
|
+
this._buttons[this._currentSelectionIndex].buttonParamsJson = JSON.stringify(buttonParams);
|
|
147
|
+
return this;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
addSelection(title, options = {}) {
|
|
151
|
+
this._buttons.push({ name: 'single_select', buttonParamsJson: JSON.stringify({ title, sections: [], ...options }) });
|
|
152
|
+
this._currentSelectionIndex = this._buttons.length - 1;
|
|
153
|
+
this._currentSectionIndex = -1;
|
|
154
|
+
return this;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
addReply(display_text = '', id = '', options = {}) {
|
|
158
|
+
this._buttons.push({
|
|
159
|
+
name: 'quick_reply',
|
|
160
|
+
buttonParamsJson: JSON.stringify({
|
|
161
|
+
display_text,
|
|
162
|
+
id,
|
|
163
|
+
...options,
|
|
164
|
+
}),
|
|
165
|
+
});
|
|
166
|
+
return this;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
addCall(display_text = '', id = '', options = {}) {
|
|
170
|
+
this._buttons.push({
|
|
171
|
+
name: 'cta_call',
|
|
172
|
+
buttonParamsJson: JSON.stringify({
|
|
173
|
+
display_text,
|
|
174
|
+
id,
|
|
175
|
+
...options,
|
|
176
|
+
}),
|
|
177
|
+
});
|
|
178
|
+
return this;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
addReminder(display_text = '', id = '', options = {}) {
|
|
182
|
+
this._buttons.push({
|
|
183
|
+
name: 'cta_reminder',
|
|
184
|
+
buttonParamsJson: JSON.stringify({
|
|
185
|
+
display_text,
|
|
186
|
+
id,
|
|
187
|
+
...options,
|
|
188
|
+
}),
|
|
189
|
+
});
|
|
190
|
+
return this;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
addCancelReminder(display_text = '', id = '', options = {}) {
|
|
194
|
+
this._buttons.push({
|
|
195
|
+
name: 'cta_cancel_reminder',
|
|
196
|
+
buttonParamsJson: JSON.stringify({
|
|
197
|
+
display_text,
|
|
198
|
+
id,
|
|
199
|
+
...options,
|
|
200
|
+
}),
|
|
201
|
+
});
|
|
202
|
+
return this;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
addAddress(display_text = '', id = '', options = {}) {
|
|
206
|
+
this._buttons.push({
|
|
207
|
+
name: 'address_message',
|
|
208
|
+
buttonParamsJson: JSON.stringify({
|
|
209
|
+
display_text,
|
|
210
|
+
id,
|
|
211
|
+
...options,
|
|
212
|
+
}),
|
|
213
|
+
});
|
|
214
|
+
return this;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
addLocation(options = {}) {
|
|
218
|
+
this._buttons.push({
|
|
219
|
+
name: 'send_location',
|
|
220
|
+
buttonParamsJson: JSON.stringify(options),
|
|
221
|
+
});
|
|
222
|
+
return this;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
addUrl(display_text = '', url = '', webview_interaction = false, options = {}) {
|
|
226
|
+
this._buttons.push({
|
|
227
|
+
...options,
|
|
228
|
+
name: 'cta_url',
|
|
229
|
+
buttonParamsJson: JSON.stringify({
|
|
230
|
+
display_text,
|
|
231
|
+
url,
|
|
232
|
+
webview_interaction,
|
|
233
|
+
...options,
|
|
234
|
+
}),
|
|
235
|
+
});
|
|
236
|
+
return this;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
addCopy(display_text = '', copy_code = '', options = {}) {
|
|
240
|
+
this._buttons.push({
|
|
241
|
+
name: 'cta_copy',
|
|
242
|
+
buttonParamsJson: JSON.stringify({
|
|
243
|
+
display_text,
|
|
244
|
+
copy_code,
|
|
245
|
+
...options,
|
|
246
|
+
}),
|
|
247
|
+
});
|
|
248
|
+
return this;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
static paramsList = {
|
|
252
|
+
limited_time_offer: {
|
|
253
|
+
text: 'string',
|
|
254
|
+
url: 'string',
|
|
255
|
+
copy_code: 'string',
|
|
256
|
+
expiration_time: 'number',
|
|
257
|
+
},
|
|
258
|
+
bottom_sheet: {
|
|
259
|
+
in_thread_buttons_limit: 'number',
|
|
260
|
+
divider_indices: ['number'],
|
|
261
|
+
list_title: 'string',
|
|
262
|
+
button_title: 'string',
|
|
263
|
+
},
|
|
264
|
+
tap_target_configuration: {
|
|
265
|
+
title: 'string',
|
|
266
|
+
description: 'string',
|
|
267
|
+
canonical_url: 'string',
|
|
268
|
+
domain: 'string',
|
|
269
|
+
buttonIndex: 'number',
|
|
270
|
+
},
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
async toCard() {
|
|
274
|
+
return {
|
|
275
|
+
body: {
|
|
276
|
+
text: this._body,
|
|
277
|
+
},
|
|
278
|
+
footer: {
|
|
279
|
+
text: this._footer,
|
|
280
|
+
},
|
|
281
|
+
header: {
|
|
282
|
+
title: this._title,
|
|
283
|
+
subtitle: this._subtitle,
|
|
284
|
+
hasMediaAttachment: !!this._data,
|
|
285
|
+
...(this._data
|
|
286
|
+
? await prepareWAMessageMedia(this._data, { upload: this.#client.waUploadToServer }).catch((e) => {
|
|
287
|
+
if (String(e).includes('Invalid media type')) return this._data;
|
|
288
|
+
throw e;
|
|
289
|
+
})
|
|
290
|
+
: {}),
|
|
291
|
+
},
|
|
292
|
+
nativeFlowMessage: {
|
|
293
|
+
messageParamsJson: JSON.stringify(this._params),
|
|
294
|
+
buttons: this._buttons,
|
|
295
|
+
},
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
async build(jid, { messageId, ...options } = {}) {
|
|
300
|
+
const message = await this.toCard();
|
|
301
|
+
|
|
302
|
+
return generateWAMessageFromContent(
|
|
303
|
+
jid,
|
|
304
|
+
{
|
|
305
|
+
...this._extraPayload,
|
|
306
|
+
interactiveMessage: {
|
|
307
|
+
...message,
|
|
308
|
+
contextInfo: this._contextInfo,
|
|
309
|
+
},
|
|
310
|
+
},
|
|
311
|
+
{ messageId: messageId || generateMessageIDV2(), ...options }
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
async send(jid, { messageId, additionalNodes = [], ...options } = {}) {
|
|
316
|
+
const msg = await this.build(jid, { messageId, ...options });
|
|
317
|
+
|
|
318
|
+
await this.#client.relayMessage(msg.key.remoteJid, msg.message, {
|
|
319
|
+
messageId: msg.key.id,
|
|
320
|
+
additionalNodes: [
|
|
321
|
+
{
|
|
322
|
+
tag: 'biz',
|
|
323
|
+
attrs: {},
|
|
324
|
+
content: [
|
|
325
|
+
{
|
|
326
|
+
tag: 'interactive',
|
|
327
|
+
attrs: { type: 'native_flow', v: '1' },
|
|
328
|
+
content: [{ tag: 'native_flow', attrs: { v: '9', name: 'mixed' } }],
|
|
329
|
+
},
|
|
330
|
+
],
|
|
331
|
+
},
|
|
332
|
+
...additionalNodes,
|
|
333
|
+
],
|
|
334
|
+
...options,
|
|
335
|
+
});
|
|
336
|
+
return msg;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
export { Button };
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { generateWAMessageFromContent, prepareWAMessageMedia } from '../Utils/messages.js';
|
|
2
|
+
import { generateMessageIDV2 } from '../Utils/generics.js';
|
|
3
|
+
import { BaseBuilder } from './BaseBuilder.js';
|
|
4
|
+
import { Toolkit } from './Toolkit.js';
|
|
5
|
+
|
|
6
|
+
class ButtonV2 extends BaseBuilder {
|
|
7
|
+
#client;
|
|
8
|
+
|
|
9
|
+
constructor(client) {
|
|
10
|
+
super();
|
|
11
|
+
if (!client) {
|
|
12
|
+
throw new Error('Socket is required');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
this.#client = client;
|
|
16
|
+
this._image;
|
|
17
|
+
this._data;
|
|
18
|
+
this._buttons = [];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
loadFrom(msg) {
|
|
22
|
+
if (!msg) throw new Error('buttonsMessage needed');
|
|
23
|
+
if (!msg.buttonsMessage) throw new Error('buttonsMessage not found');
|
|
24
|
+
|
|
25
|
+
const { buttonsMessage, ...extraPayload } = msg;
|
|
26
|
+
const bM = buttonsMessage;
|
|
27
|
+
const location = bM.locationMessage || {};
|
|
28
|
+
|
|
29
|
+
this._title = location.name || '';
|
|
30
|
+
this._subtitle = location.address || '';
|
|
31
|
+
this._body = bM.contentText || '';
|
|
32
|
+
this._footer = bM.footerText || '';
|
|
33
|
+
this._contextInfo = bM.contextInfo || {};
|
|
34
|
+
this._extraPayload = extraPayload;
|
|
35
|
+
|
|
36
|
+
this._buttons = Array.isArray(bM.buttons)
|
|
37
|
+
? bM.buttons.map((button) => ({
|
|
38
|
+
...button,
|
|
39
|
+
...(button.nativeFlowInfo
|
|
40
|
+
? {
|
|
41
|
+
nativeFlowInfo: {
|
|
42
|
+
...button.nativeFlowInfo,
|
|
43
|
+
paramsJson: typeof button.nativeFlowInfo.paramsJson === 'string' ? button.nativeFlowInfo.paramsJson : JSON.stringify(button.nativeFlowInfo.paramsJson || {}),
|
|
44
|
+
},
|
|
45
|
+
}
|
|
46
|
+
: {}),
|
|
47
|
+
}))
|
|
48
|
+
: [];
|
|
49
|
+
|
|
50
|
+
this._image = location.jpegThumbnail || undefined;
|
|
51
|
+
|
|
52
|
+
if (!this._image && bM.locationMessage) {
|
|
53
|
+
this._image = undefined;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!bM.locationMessage && bM.headerType === 6) {
|
|
57
|
+
this._image = undefined;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
this._data = Object.keys(bM).reduce((data, key) => {
|
|
61
|
+
if (!['contentText', 'footerText', 'contextInfo', 'buttons', 'headerType', 'locationMessage', 'viewOnce'].includes(key)) {
|
|
62
|
+
data[key] = bM[key];
|
|
63
|
+
}
|
|
64
|
+
return data;
|
|
65
|
+
}, {});
|
|
66
|
+
|
|
67
|
+
if (!Object.keys(this._data).length) {
|
|
68
|
+
this._data = undefined;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
addButton(displayText = '', buttonId = crypto.randomUUID()) {
|
|
75
|
+
this._buttons.push({
|
|
76
|
+
buttonId,
|
|
77
|
+
buttonText: { displayText },
|
|
78
|
+
type: 1,
|
|
79
|
+
});
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
addRawButton(obj) {
|
|
84
|
+
if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {
|
|
85
|
+
throw new TypeError('Buttons must be a plain object');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
this._buttons.push(obj);
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
setRawThumbnail(thumbnail) {
|
|
93
|
+
if (!thumbnail) throw new Error('Thumbnail needed');
|
|
94
|
+
this._image = { base64: thumbnail, is_raw: true };
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
setThumbnail(path) {
|
|
99
|
+
if (!path) throw new Error('Url or buffer needed');
|
|
100
|
+
this._image = path;
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
setMedia(obj) {
|
|
105
|
+
if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {
|
|
106
|
+
throw new TypeError('Media must be a plain object');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
this._data = obj;
|
|
110
|
+
return this;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async build(jid, { messageId, ...options } = {}) {
|
|
114
|
+
const _thumbnail = this._image?.is_raw
|
|
115
|
+
? this._image.base64
|
|
116
|
+
: this._image
|
|
117
|
+
? await Toolkit.resize(Buffer.isBuffer(this._image) ? this._image : await Toolkit.fetchBuffer(this._image, {}, { silent: true }), 300, 300)
|
|
118
|
+
: null;
|
|
119
|
+
const msg = generateWAMessageFromContent(
|
|
120
|
+
jid,
|
|
121
|
+
{
|
|
122
|
+
...this._extraPayload,
|
|
123
|
+
buttonsMessage: {
|
|
124
|
+
contentText: this._body,
|
|
125
|
+
footerText: this._footer,
|
|
126
|
+
...(this._data
|
|
127
|
+
? this._data
|
|
128
|
+
: {
|
|
129
|
+
headerType: 6,
|
|
130
|
+
locationMessage: {
|
|
131
|
+
degreesLatitude: 0,
|
|
132
|
+
degreesLongitude: 0,
|
|
133
|
+
name: this._title,
|
|
134
|
+
address: this._subtitle,
|
|
135
|
+
jpegThumbnail: _thumbnail,
|
|
136
|
+
},
|
|
137
|
+
}),
|
|
138
|
+
viewOnce: true,
|
|
139
|
+
contextInfo: this._contextInfo,
|
|
140
|
+
buttons: [...this._buttons],
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
{ messageId: messageId || generateMessageIDV2(), ...options }
|
|
144
|
+
);
|
|
145
|
+
return msg;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async send(jid, { messageId, additionalNodes = [], ...options } = {}) {
|
|
149
|
+
if (this._buttons.length < 1) throw new Error('ButtonV2 requires at least one button');
|
|
150
|
+
const msg = await this.build(jid, { messageId, ...options });
|
|
151
|
+
|
|
152
|
+
await this.#client.relayMessage(msg.key.remoteJid, msg.message, {
|
|
153
|
+
messageId: msg.key.id,
|
|
154
|
+
additionalNodes: [
|
|
155
|
+
{
|
|
156
|
+
tag: 'biz',
|
|
157
|
+
attrs: {},
|
|
158
|
+
content: [
|
|
159
|
+
{
|
|
160
|
+
tag: 'interactive',
|
|
161
|
+
attrs: { type: 'native_flow', v: '1' },
|
|
162
|
+
content: [{ tag: 'native_flow', attrs: { v: '9', name: 'mixed' } }],
|
|
163
|
+
},
|
|
164
|
+
],
|
|
165
|
+
},
|
|
166
|
+
...additionalNodes,
|
|
167
|
+
],
|
|
168
|
+
...options,
|
|
169
|
+
});
|
|
170
|
+
return msg;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
export { ButtonV2 };
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { generateWAMessageFromContent } from '../Utils/messages.js';
|
|
2
|
+
import { generateMessageIDV2 } from '../Utils/generics.js';
|
|
3
|
+
import { BaseBuilder } from './BaseBuilder.js';
|
|
4
|
+
import { Toolkit } from './Toolkit.js';
|
|
5
|
+
|
|
6
|
+
class Carousel extends BaseBuilder {
|
|
7
|
+
#client;
|
|
8
|
+
|
|
9
|
+
constructor(client) {
|
|
10
|
+
super();
|
|
11
|
+
if (!client) {
|
|
12
|
+
throw new Error('Socket is required');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
this.#client = client;
|
|
16
|
+
this._cards = [];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
loadFrom(msg) {
|
|
20
|
+
if (!msg) throw new Error('interactiveMessage needed');
|
|
21
|
+
if (!msg.interactiveMessage) throw new Error('interactiveMessage not found');
|
|
22
|
+
|
|
23
|
+
const { interactiveMessage, ...extraPayload } = msg;
|
|
24
|
+
const iM = interactiveMessage;
|
|
25
|
+
const carousel = iM.carouselMessage || {};
|
|
26
|
+
|
|
27
|
+
this._body = iM.body?.text || '';
|
|
28
|
+
this._footer = iM.footer?.text || '';
|
|
29
|
+
this._contextInfo = iM.contextInfo || {};
|
|
30
|
+
this._extraPayload = extraPayload;
|
|
31
|
+
|
|
32
|
+
this._cards = Array.isArray(carousel.cards)
|
|
33
|
+
? carousel.cards.map((card) => ({
|
|
34
|
+
...card,
|
|
35
|
+
header: {
|
|
36
|
+
...(card.header || {}),
|
|
37
|
+
hasMediaAttachment: !!card.header?.hasMediaAttachment,
|
|
38
|
+
...(card.header?.imageMessage ? { imageMessage: card.header.imageMessage } : {}),
|
|
39
|
+
...(card.header?.videoMessage ? { videoMessage: card.header.videoMessage } : {}),
|
|
40
|
+
},
|
|
41
|
+
body: {
|
|
42
|
+
text: card.body?.text || '',
|
|
43
|
+
},
|
|
44
|
+
footer: {
|
|
45
|
+
text: card.footer?.text || '',
|
|
46
|
+
},
|
|
47
|
+
nativeFlowMessage: {
|
|
48
|
+
...(card.nativeFlowMessage || {}),
|
|
49
|
+
buttons: Array.isArray(card.nativeFlowMessage?.buttons)
|
|
50
|
+
? card.nativeFlowMessage.buttons.map((button) => ({
|
|
51
|
+
...button,
|
|
52
|
+
buttonParamsJson: typeof button.buttonParamsJson === 'string' ? button.buttonParamsJson : JSON.stringify(button.buttonParamsJson || {}),
|
|
53
|
+
}))
|
|
54
|
+
: [],
|
|
55
|
+
messageParamsJson:
|
|
56
|
+
typeof card.nativeFlowMessage?.messageParamsJson === 'string' ? card.nativeFlowMessage.messageParamsJson : JSON.stringify(card.nativeFlowMessage?.messageParamsJson || {}),
|
|
57
|
+
},
|
|
58
|
+
}))
|
|
59
|
+
: [];
|
|
60
|
+
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
addCard(card) {
|
|
65
|
+
const cards = Array.isArray(card) ? card : [card];
|
|
66
|
+
const baseIndex = this._cards.length;
|
|
67
|
+
|
|
68
|
+
for (const [index, c] of cards.entries()) {
|
|
69
|
+
if (!c?.header?.hasMediaAttachment) {
|
|
70
|
+
throw new Error(`Card [${baseIndex + index}] must include an image or video in header`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
this._cards.push(...cards);
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
build(jid, { messageId, ...options } = {}) {
|
|
79
|
+
return generateWAMessageFromContent(
|
|
80
|
+
jid,
|
|
81
|
+
{
|
|
82
|
+
...this._extraPayload,
|
|
83
|
+
interactiveMessage: {
|
|
84
|
+
header: {
|
|
85
|
+
hasMediaAttachment: false,
|
|
86
|
+
},
|
|
87
|
+
body: { text: this._body },
|
|
88
|
+
footer: { text: this._footer },
|
|
89
|
+
contextInfo: this._contextInfo,
|
|
90
|
+
carouselMessage: {
|
|
91
|
+
cards: this._cards,
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
{ messageId: messageId || generateMessageIDV2(), ...options }
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async send(jid, { messageId, additionalNodes = [], ...options } = {}) {
|
|
100
|
+
const msg = this.build(jid, { messageId, ...options });
|
|
101
|
+
|
|
102
|
+
await this.#client.relayMessage(msg.key.remoteJid, msg.message, {
|
|
103
|
+
messageId: msg.key.id,
|
|
104
|
+
additionalNodes: [
|
|
105
|
+
{
|
|
106
|
+
tag: 'biz',
|
|
107
|
+
attrs: {},
|
|
108
|
+
content: [
|
|
109
|
+
{
|
|
110
|
+
tag: 'interactive',
|
|
111
|
+
attrs: { type: 'native_flow', v: '1' },
|
|
112
|
+
content: [{ tag: 'native_flow', attrs: { v: '9', name: 'mixed' } }],
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
},
|
|
116
|
+
...additionalNodes,
|
|
117
|
+
],
|
|
118
|
+
...options,
|
|
119
|
+
});
|
|
120
|
+
return msg;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
export { Carousel };
|