@kyyinfinite/baileys 1.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +582 -1340
- 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/KyyMessage.js +46 -0
- package/lib/Kyyinfinite/Simple/MediaBuilder.js +41 -0
- package/lib/Kyyinfinite/Simple/MessageBuilder.js +55 -0
- package/lib/Kyyinfinite/Simple/MessageTypesBuilder.js +3 -0
- package/lib/Kyyinfinite/Simple/SimpleBuilder.js +28 -0
- package/lib/Kyyinfinite/Simple/SimpleClient.js +120 -0
- package/lib/Kyyinfinite/Simple/TextBuilder.js +28 -0
- package/lib/Kyyinfinite/Simple/UniversalMediaBuilder.js +21 -0
- package/lib/Kyyinfinite/Simple/index.d.ts +232 -0
- package/lib/Kyyinfinite/Simple/index.js +38 -0
- package/lib/Kyyinfinite/Simple/jid.js +55 -0
- package/lib/Kyyinfinite/Simple/messageUtils.js +49 -0
- package/lib/Kyyinfinite/Simple/parseMessage.js +55 -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 +104 -23
- package/test/core.test.js +38 -0
- package/test/simple-api.test.js +183 -0
- 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,466 @@
|
|
|
1
|
+
import crypto from 'crypto';
|
|
2
|
+
import { generateWAMessageFromContent } from '../Utils/messages.js';
|
|
3
|
+
import { generateMessageIDV2 } from '../Utils/generics.js';
|
|
4
|
+
import { BaseBuilder } from './BaseBuilder.js';
|
|
5
|
+
import { Toolkit } from './Toolkit.js';
|
|
6
|
+
import { AIRich } from './AIRich.js';
|
|
7
|
+
|
|
8
|
+
class Foad2 extends BaseBuilder {
|
|
9
|
+
#client;
|
|
10
|
+
|
|
11
|
+
constructor(client, { dynamic = true } = {}) {
|
|
12
|
+
super();
|
|
13
|
+
|
|
14
|
+
if (!client) {
|
|
15
|
+
throw new Error('Socket is required');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
this.#client = client;
|
|
19
|
+
this._dynamic = !!dynamic;
|
|
20
|
+
|
|
21
|
+
this._messageText = '';
|
|
22
|
+
this._previewTitle = 'Preview';
|
|
23
|
+
this._tabs = [];
|
|
24
|
+
|
|
25
|
+
this._responseId = crypto.randomUUID();
|
|
26
|
+
this._botResponseId = crypto.randomUUID();
|
|
27
|
+
|
|
28
|
+
this._lastMessageKey = null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
setResponseId(id) {
|
|
32
|
+
if (!id || typeof id !== 'string') {
|
|
33
|
+
throw new TypeError('Response ID must be a non-empty string');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
this._responseId = id;
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
refreshResponseId() {
|
|
41
|
+
this._responseId = crypto.randomUUID();
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
setBotResponseId(id) {
|
|
46
|
+
if (!id || typeof id !== 'string') {
|
|
47
|
+
throw new TypeError('Bot response ID must be a non-empty string');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
this._botResponseId = id;
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
refreshBotResponseId() {
|
|
55
|
+
this._botResponseId = crypto.randomUUID();
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
addTitle(text) {
|
|
60
|
+
if (typeof text !== 'string') {
|
|
61
|
+
throw new TypeError('Title must be a string');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
this._messageText = text;
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
setPreviewTitle(title) {
|
|
69
|
+
if (typeof title !== 'string') {
|
|
70
|
+
throw new TypeError('Preview title must be a string');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
this._previewTitle = title;
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
addHtml(
|
|
78
|
+
html,
|
|
79
|
+
{
|
|
80
|
+
title = 'Widget',
|
|
81
|
+
id,
|
|
82
|
+
url = 'https://example.com',
|
|
83
|
+
trustedSources = ['example.com'],
|
|
84
|
+
stepEntries = []
|
|
85
|
+
} = {}
|
|
86
|
+
) {
|
|
87
|
+
if (typeof html !== 'string') {
|
|
88
|
+
throw new TypeError('HTML payload must be a string');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (!html.trim()) {
|
|
92
|
+
throw new Error('HTML payload cannot be empty');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const tabId = id ?? `tab_${this._tabs.length}`;
|
|
96
|
+
|
|
97
|
+
if (this._tabs.some(tab => tab.id === tabId)) {
|
|
98
|
+
throw new Error(`Duplicate tab id: ${tabId}`);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
this._tabs.push({
|
|
102
|
+
id: tabId,
|
|
103
|
+
tab_header: title,
|
|
104
|
+
|
|
105
|
+
sections: [
|
|
106
|
+
{
|
|
107
|
+
__typename: 'GenAIUnifiedResponseSection',
|
|
108
|
+
|
|
109
|
+
view_model: {
|
|
110
|
+
__typename: 'GenAISingleLayoutViewModel',
|
|
111
|
+
|
|
112
|
+
primitive: {
|
|
113
|
+
__typename: 'GenAIaeacdsnwHtmlPrimitive',
|
|
114
|
+
|
|
115
|
+
payload: html,
|
|
116
|
+
|
|
117
|
+
url,
|
|
118
|
+
|
|
119
|
+
trusted_sources: trustedSources
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
],
|
|
124
|
+
|
|
125
|
+
step_entries: stepEntries
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
return this;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
addTab(tab = {}) {
|
|
132
|
+
const {
|
|
133
|
+
id,
|
|
134
|
+
tab_header = 'Widget',
|
|
135
|
+
sections = [],
|
|
136
|
+
step_entries = []
|
|
137
|
+
} = tab;
|
|
138
|
+
|
|
139
|
+
if (!id || typeof id !== 'string') {
|
|
140
|
+
throw new TypeError('Tab id is required');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (this._tabs.some(tab => tab.id === id)) {
|
|
144
|
+
throw new Error(`Duplicate tab id: ${id}`);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (!Array.isArray(sections)) {
|
|
148
|
+
throw new TypeError('Tab sections must be an array');
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (!Array.isArray(step_entries)) {
|
|
152
|
+
throw new TypeError('Tab step_entries must be an array');
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
this._tabs.push({
|
|
156
|
+
id,
|
|
157
|
+
tab_header,
|
|
158
|
+
sections: structuredClone(sections),
|
|
159
|
+
step_entries: structuredClone(step_entries)
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
return this;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
clearTabs() {
|
|
166
|
+
this._tabs = [];
|
|
167
|
+
return this;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
get tabs() {
|
|
171
|
+
return structuredClone(this._tabs);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
buildResponse() {
|
|
175
|
+
if (!this._tabs.length) {
|
|
176
|
+
throw new Error(
|
|
177
|
+
'Foad2 requires at least one HTML tab'
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (this._dynamic) {
|
|
182
|
+
this.refreshResponseId();
|
|
183
|
+
this.refreshBotResponseId();
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/*
|
|
187
|
+
* FOAD2 / FULLSCREEN
|
|
188
|
+
*
|
|
189
|
+
* Perbedaan utama dengan Foad:
|
|
190
|
+
*
|
|
191
|
+
* Foad:
|
|
192
|
+
* normal embedded widget
|
|
193
|
+
*
|
|
194
|
+
* Foad2:
|
|
195
|
+
* fullscreen HTML surface
|
|
196
|
+
*
|
|
197
|
+
* Struktur embedded_screens tetap dipertahankan
|
|
198
|
+
* agar kompatibel dengan richResponseMessage.
|
|
199
|
+
*/
|
|
200
|
+
|
|
201
|
+
return {
|
|
202
|
+
response_id: this._responseId,
|
|
203
|
+
|
|
204
|
+
sections: [
|
|
205
|
+
{
|
|
206
|
+
__typename:
|
|
207
|
+
'GenAIUnifiedResponseSection',
|
|
208
|
+
|
|
209
|
+
view_model: {
|
|
210
|
+
__typename:
|
|
211
|
+
'GenAISingleLayoutViewModel',
|
|
212
|
+
|
|
213
|
+
primitive: {
|
|
214
|
+
__typename:
|
|
215
|
+
'GenAIBotProgressStatusPrimitive',
|
|
216
|
+
|
|
217
|
+
title:
|
|
218
|
+
this._messageText ||
|
|
219
|
+
'Popioo:*Click Me*',
|
|
220
|
+
|
|
221
|
+
is_in_progress: true
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
],
|
|
226
|
+
|
|
227
|
+
embedded_screens: [
|
|
228
|
+
{
|
|
229
|
+
title: this._previewTitle,
|
|
230
|
+
|
|
231
|
+
content: [
|
|
232
|
+
{
|
|
233
|
+
__typename:
|
|
234
|
+
'FOAIDNixelButtonSheets',
|
|
235
|
+
|
|
236
|
+
/*
|
|
237
|
+
* FULLSCREEN MODE
|
|
238
|
+
*
|
|
239
|
+
* Flag tambahan untuk wrapper.
|
|
240
|
+
*
|
|
241
|
+
* Jika client/server mengabaikan field ini,
|
|
242
|
+
* struktur HTML tetap valid.
|
|
243
|
+
*/
|
|
244
|
+
|
|
245
|
+
display_mode: 'fullscreen',
|
|
246
|
+
|
|
247
|
+
fullscreen: true,
|
|
248
|
+
|
|
249
|
+
tabs: structuredClone(
|
|
250
|
+
this._tabs
|
|
251
|
+
)
|
|
252
|
+
}
|
|
253
|
+
]
|
|
254
|
+
}
|
|
255
|
+
]
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
async build(
|
|
260
|
+
jid,
|
|
261
|
+
{
|
|
262
|
+
messageId,
|
|
263
|
+
...options
|
|
264
|
+
} = {}
|
|
265
|
+
) {
|
|
266
|
+
const responseData =
|
|
267
|
+
this.buildResponse();
|
|
268
|
+
|
|
269
|
+
const dataBase64 =
|
|
270
|
+
Buffer
|
|
271
|
+
.from(
|
|
272
|
+
JSON.stringify(responseData)
|
|
273
|
+
)
|
|
274
|
+
.toString('base64');
|
|
275
|
+
|
|
276
|
+
return generateWAMessageFromContent(
|
|
277
|
+
jid,
|
|
278
|
+
|
|
279
|
+
{
|
|
280
|
+
messageContextInfo: {
|
|
281
|
+
deviceListMetadata: {},
|
|
282
|
+
|
|
283
|
+
deviceListMetadataVersion: 2,
|
|
284
|
+
|
|
285
|
+
botMetadata: {
|
|
286
|
+
messageDisclaimerText:
|
|
287
|
+
this._title || '',
|
|
288
|
+
|
|
289
|
+
botResponseId:
|
|
290
|
+
this._botResponseId,
|
|
291
|
+
|
|
292
|
+
verificationMetadata:
|
|
293
|
+
AIRich.generateVerificationMetadata()
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
|
|
297
|
+
...this._extraPayload,
|
|
298
|
+
|
|
299
|
+
botForwardedMessage: {
|
|
300
|
+
message: {
|
|
301
|
+
richResponseMessage: {
|
|
302
|
+
messageType: 1,
|
|
303
|
+
|
|
304
|
+
submessages:
|
|
305
|
+
this._messageText
|
|
306
|
+
? [
|
|
307
|
+
{
|
|
308
|
+
messageType: 2,
|
|
309
|
+
|
|
310
|
+
messageText:
|
|
311
|
+
this._messageText
|
|
312
|
+
}
|
|
313
|
+
]
|
|
314
|
+
: [],
|
|
315
|
+
|
|
316
|
+
unifiedResponse: {
|
|
317
|
+
data: dataBase64
|
|
318
|
+
},
|
|
319
|
+
|
|
320
|
+
contextInfo: {
|
|
321
|
+
forwardingScore: 1,
|
|
322
|
+
|
|
323
|
+
isForwarded: true,
|
|
324
|
+
|
|
325
|
+
forwardedAiBotMessageInfo: {
|
|
326
|
+
botJid:
|
|
327
|
+
'867051314767696@bot'
|
|
328
|
+
},
|
|
329
|
+
|
|
330
|
+
forwardOrigin: 4
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
},
|
|
336
|
+
|
|
337
|
+
{
|
|
338
|
+
messageId:
|
|
339
|
+
messageId ||
|
|
340
|
+
generateMessageIDV2(),
|
|
341
|
+
|
|
342
|
+
...options
|
|
343
|
+
}
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
async send(
|
|
348
|
+
jid,
|
|
349
|
+
{
|
|
350
|
+
messageId,
|
|
351
|
+
...options
|
|
352
|
+
} = {}
|
|
353
|
+
) {
|
|
354
|
+
const msg =
|
|
355
|
+
await this.build(
|
|
356
|
+
jid,
|
|
357
|
+
{
|
|
358
|
+
messageId,
|
|
359
|
+
...options
|
|
360
|
+
}
|
|
361
|
+
);
|
|
362
|
+
|
|
363
|
+
await this.#client.relayMessage(
|
|
364
|
+
msg.key.remoteJid,
|
|
365
|
+
|
|
366
|
+
msg.message,
|
|
367
|
+
|
|
368
|
+
{
|
|
369
|
+
messageId: msg.key.id,
|
|
370
|
+
...options
|
|
371
|
+
}
|
|
372
|
+
);
|
|
373
|
+
|
|
374
|
+
this._lastMessageKey =
|
|
375
|
+
msg.key;
|
|
376
|
+
|
|
377
|
+
return msg;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
async sendEdit(
|
|
381
|
+
jid,
|
|
382
|
+
id,
|
|
383
|
+
{
|
|
384
|
+
msg,
|
|
385
|
+
messageId,
|
|
386
|
+
...options
|
|
387
|
+
} = {}
|
|
388
|
+
) {
|
|
389
|
+
jid =
|
|
390
|
+
jid ??
|
|
391
|
+
this._lastMessageKey?.remoteJid;
|
|
392
|
+
|
|
393
|
+
id =
|
|
394
|
+
id ??
|
|
395
|
+
this._lastMessageKey?.id;
|
|
396
|
+
|
|
397
|
+
if (!jid) {
|
|
398
|
+
throw new Error(
|
|
399
|
+
'JID is required'
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
if (!id) {
|
|
404
|
+
throw new Error(
|
|
405
|
+
'Message id is required'
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
const source =
|
|
410
|
+
msg ??
|
|
411
|
+
(
|
|
412
|
+
await this.build(
|
|
413
|
+
jid,
|
|
414
|
+
options
|
|
415
|
+
)
|
|
416
|
+
).message;
|
|
417
|
+
|
|
418
|
+
const editedMessage =
|
|
419
|
+
await generateWAMessageFromContent(
|
|
420
|
+
jid,
|
|
421
|
+
|
|
422
|
+
{
|
|
423
|
+
botForwardedMessage: {
|
|
424
|
+
message: {
|
|
425
|
+
protocolMessage: {
|
|
426
|
+
key: {
|
|
427
|
+
remoteJid: jid,
|
|
428
|
+
fromMe: true,
|
|
429
|
+
id
|
|
430
|
+
},
|
|
431
|
+
|
|
432
|
+
type: 14,
|
|
433
|
+
|
|
434
|
+
editedMessage:
|
|
435
|
+
source
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
},
|
|
440
|
+
|
|
441
|
+
{
|
|
442
|
+
messageId:
|
|
443
|
+
messageId ||
|
|
444
|
+
generateMessageIDV2(),
|
|
445
|
+
|
|
446
|
+
...options
|
|
447
|
+
}
|
|
448
|
+
);
|
|
449
|
+
|
|
450
|
+
await this.#client.relayMessage(
|
|
451
|
+
jid,
|
|
452
|
+
|
|
453
|
+
editedMessage.message,
|
|
454
|
+
|
|
455
|
+
{
|
|
456
|
+
messageId:
|
|
457
|
+
editedMessage.key.id
|
|
458
|
+
}
|
|
459
|
+
);
|
|
460
|
+
|
|
461
|
+
return editedMessage;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
export { Foad2 };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AIRich } from '../AIRich.js'
|
|
2
|
+
import { proxyBuilder } from './SimpleBuilder.js'
|
|
3
|
+
|
|
4
|
+
const aliases = {
|
|
5
|
+
title: 'setTitle',
|
|
6
|
+
subtitle: 'setSubtitle',
|
|
7
|
+
body: 'setBody',
|
|
8
|
+
footer: 'setFooter',
|
|
9
|
+
context: 'setContextInfo',
|
|
10
|
+
payload: 'addPayload',
|
|
11
|
+
text: 'addText'
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function createAIBuilder(sock, ...args) {
|
|
15
|
+
return proxyBuilder({ sock, raw: new AIRich(sock, ...args) }, aliases)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { AIRich }
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Button } from '../Button.js'
|
|
2
|
+
import { ButtonV2 } from '../ButtonV2.js'
|
|
3
|
+
import { Carousel } from '../Carousel.js'
|
|
4
|
+
import { AIRich } from '../AIRich.js'
|
|
5
|
+
import { Foad } from '../Foad.js'
|
|
6
|
+
import { Foad2 } from '../Foad2.js'
|
|
7
|
+
import { proxyBuilder } from './SimpleBuilder.js'
|
|
8
|
+
|
|
9
|
+
const wrap = (sock, raw, aliases = {}) => proxyBuilder({ sock, raw }, aliases)
|
|
10
|
+
const common = { title: 'setTitle', subtitle: 'setSubtitle', body: 'setBody', text: 'setBody', footer: 'setFooter', context: 'setContextInfo', payload: 'addPayload' }
|
|
11
|
+
|
|
12
|
+
export const createButtonBuilder = (sock, ...args) => wrap(sock, new Button(sock, ...args), common)
|
|
13
|
+
export const createButtonV2Builder = (sock, ...args) => wrap(sock, new ButtonV2(sock, ...args), common)
|
|
14
|
+
export const createCarouselBuilder = (sock, ...args) => wrap(sock, new Carousel(sock, ...args), common)
|
|
15
|
+
export const createAIBuilder = (sock, ...args) => wrap(sock, new AIRich(sock, ...args), { ...common, text: 'addText' })
|
|
16
|
+
export const createFoadBuilder = (sock, ...args) => wrap(sock, new Foad(sock, ...args), { ...common, title: 'addTitle', text: 'addText' })
|
|
17
|
+
export const createFoad2Builder = (sock, ...args) => wrap(sock, new Foad2(sock, ...args), { ...common, title: 'addTitle', text: 'addText' })
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { Button } from '../Button.js'
|
|
2
|
+
import { ButtonV2 } from '../ButtonV2.js'
|
|
3
|
+
import { proxyBuilder } from './SimpleBuilder.js'
|
|
4
|
+
|
|
5
|
+
const aliases = {
|
|
6
|
+
// BaseBuilder
|
|
7
|
+
title: 'setTitle',
|
|
8
|
+
subtitle: 'setSubtitle',
|
|
9
|
+
body: 'setBody',
|
|
10
|
+
text: 'setBody',
|
|
11
|
+
footer: 'setFooter',
|
|
12
|
+
context: 'setContextInfo',
|
|
13
|
+
payload: 'addPayload',
|
|
14
|
+
|
|
15
|
+
// Media
|
|
16
|
+
image: 'setImage',
|
|
17
|
+
document: 'setDocument',
|
|
18
|
+
media: 'setMedia',
|
|
19
|
+
|
|
20
|
+
// Button collection
|
|
21
|
+
clear: 'clearButtons',
|
|
22
|
+
params: 'setParams',
|
|
23
|
+
|
|
24
|
+
// Quick reply
|
|
25
|
+
reply: 'addReply',
|
|
26
|
+
quickReply: 'addReply',
|
|
27
|
+
|
|
28
|
+
// CTA
|
|
29
|
+
call: 'addCall',
|
|
30
|
+
url: 'addUrl',
|
|
31
|
+
copy: 'addCopy',
|
|
32
|
+
ctaCopy: 'addCopy',
|
|
33
|
+
ctaUrl: 'addUrl',
|
|
34
|
+
ctaCall: 'addCall',
|
|
35
|
+
// Backwards-friendly alias for the spelling requested in early examples.
|
|
36
|
+
coppy: 'addCopy',
|
|
37
|
+
reminder: 'addReminder',
|
|
38
|
+
cancelReminder: 'addCancelReminder',
|
|
39
|
+
address: 'addAddress',
|
|
40
|
+
location: 'addLocation',
|
|
41
|
+
|
|
42
|
+
// List / selection
|
|
43
|
+
select: 'addSelection',
|
|
44
|
+
section: 'makeSection',
|
|
45
|
+
row: 'makeRow'
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function createButtonBuilder(sock, ...args) {
|
|
49
|
+
const builder = proxyBuilder({
|
|
50
|
+
sock,
|
|
51
|
+
raw: new Button(sock, ...args)
|
|
52
|
+
}, aliases)
|
|
53
|
+
|
|
54
|
+
// Friendly Simple API:
|
|
55
|
+
// .addButton(label, id) => quick reply
|
|
56
|
+
// The original Button.addButton(name, params) remains untouched and is
|
|
57
|
+
// still available through builder.raw / api.raw.Button.
|
|
58
|
+
return new Proxy(builder, {
|
|
59
|
+
get(target, prop, receiver) {
|
|
60
|
+
if (prop === 'addButton') {
|
|
61
|
+
return (displayText = '', id = '', options = {}) => {
|
|
62
|
+
const value = target.raw.addReply(
|
|
63
|
+
displayText,
|
|
64
|
+
id,
|
|
65
|
+
options
|
|
66
|
+
)
|
|
67
|
+
return value === target.raw ? receiver : value
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Explicit CTA aliases make the public API self-documenting:
|
|
72
|
+
// .copy(), .url(), .call()
|
|
73
|
+
// They are resolved here so they always return the facade for chaining.
|
|
74
|
+
if (prop === 'copy' || prop === 'coppy' || prop === 'ctaCopy') {
|
|
75
|
+
return (...args) => {
|
|
76
|
+
const value = target.raw.addCopy(...args)
|
|
77
|
+
return value === target.raw ? receiver : value
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (prop === 'url' || prop === 'ctaUrl') {
|
|
82
|
+
return (...args) => {
|
|
83
|
+
const value = target.raw.addUrl(...args)
|
|
84
|
+
return value === target.raw ? receiver : value
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (prop === 'call' || prop === 'ctaCall') {
|
|
89
|
+
return (...args) => {
|
|
90
|
+
const value = target.raw.addCall(...args)
|
|
91
|
+
return value === target.raw ? receiver : value
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return Reflect.get(target, prop, receiver)
|
|
96
|
+
}
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function createButtonV2Builder(sock, ...args) {
|
|
101
|
+
return proxyBuilder({
|
|
102
|
+
sock,
|
|
103
|
+
raw: new ButtonV2(sock, ...args)
|
|
104
|
+
}, aliases)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export { Button, ButtonV2 }
|