@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.
Files changed (242) hide show
  1. package/README.md +408 -64
  2. package/WAProto/WAProto.proto +360 -916
  3. package/WAProto/fix-imports.js +22 -18
  4. package/WAProto/index.d.ts +14015 -0
  5. package/WAProto/index.js +47122 -81757
  6. package/engine-requirements.js +10 -0
  7. package/lib/Defaults/index.d.ts +15 -14
  8. package/lib/Defaults/index.d.ts.map +1 -1
  9. package/lib/Defaults/index.js +99 -107
  10. package/lib/Defaults/index.js.map +1 -1
  11. package/lib/Kyyinfinite/AIRich.js +2041 -0
  12. package/lib/Kyyinfinite/BaseBuilder.js +64 -0
  13. package/lib/Kyyinfinite/Button.js +341 -0
  14. package/lib/Kyyinfinite/ButtonV2.js +175 -0
  15. package/lib/Kyyinfinite/Carousel.js +125 -0
  16. package/lib/Kyyinfinite/Foad.js +542 -0
  17. package/lib/Kyyinfinite/Foad2.js +466 -0
  18. package/lib/Kyyinfinite/Simple/AIBuilder.js +18 -0
  19. package/lib/Kyyinfinite/Simple/BuilderFactories.js +17 -0
  20. package/lib/Kyyinfinite/Simple/ButtonBuilder.js +107 -0
  21. package/lib/Kyyinfinite/Simple/CardBuilder.js +179 -0
  22. package/lib/Kyyinfinite/Simple/CarouselBuilder.js +97 -0
  23. package/lib/Kyyinfinite/Simple/FoadBuilder.js +18 -0
  24. package/lib/Kyyinfinite/Simple/MediaBuilder.js +35 -0
  25. package/lib/Kyyinfinite/Simple/MessageBuilder.js +41 -0
  26. package/lib/Kyyinfinite/Simple/MessageTypesBuilder.js +3 -0
  27. package/lib/Kyyinfinite/Simple/SimpleBuilder.js +28 -0
  28. package/lib/Kyyinfinite/Simple/SimpleClient.js +83 -0
  29. package/lib/Kyyinfinite/Simple/TextBuilder.js +22 -0
  30. package/lib/Kyyinfinite/Simple/index.d.ts +141 -0
  31. package/lib/Kyyinfinite/Simple/index.js +31 -0
  32. package/lib/Kyyinfinite/Toolkit.js +453 -0
  33. package/lib/Kyyinfinite/constants.js +1 -0
  34. package/lib/Kyyinfinite/errors.js +39 -0
  35. package/lib/Kyyinfinite/index.d.ts +2 -0
  36. package/lib/Kyyinfinite/index.js +2 -0
  37. package/lib/Kyyinfinite/wrapper.d.ts +2 -0
  38. package/lib/Kyyinfinite/wrapper.js +10 -0
  39. package/lib/Signal/Group/group_cipher.js.map +1 -1
  40. package/lib/Signal/Group/keyhelper.d.ts.map +1 -1
  41. package/lib/Signal/Group/keyhelper.js.map +1 -1
  42. package/lib/Signal/Group/sender-chain-key.js.map +1 -1
  43. package/lib/Signal/Group/sender-key-message.js.map +1 -1
  44. package/lib/Signal/Group/sender-message-key.js.map +1 -1
  45. package/lib/Signal/libsignal.d.ts.map +1 -1
  46. package/lib/Signal/libsignal.js +45 -17
  47. package/lib/Signal/libsignal.js.map +1 -1
  48. package/lib/Signal/lid-mapping.d.ts +4 -0
  49. package/lib/Signal/lid-mapping.d.ts.map +1 -1
  50. package/lib/Signal/lid-mapping.js +6 -0
  51. package/lib/Signal/lid-mapping.js.map +1 -1
  52. package/lib/Socket/business.d.ts +213 -532
  53. package/lib/Socket/business.d.ts.map +1 -1
  54. package/lib/Socket/business.js +358 -401
  55. package/lib/Socket/chats.d.ts +16 -2
  56. package/lib/Socket/chats.d.ts.map +1 -1
  57. package/lib/Socket/chats.js +247 -40
  58. package/lib/Socket/chats.js.map +1 -1
  59. package/lib/Socket/communities.d.ts +269 -641
  60. package/lib/Socket/communities.d.ts.map +1 -1
  61. package/lib/Socket/groups.d.ts +13 -2
  62. package/lib/Socket/groups.d.ts.map +1 -1
  63. package/lib/Socket/groups.js +21 -1
  64. package/lib/Socket/groups.js.map +1 -1
  65. package/lib/Socket/index.d.ts +255 -631
  66. package/lib/Socket/index.d.ts.map +1 -1
  67. package/lib/Socket/index.js +9 -10
  68. package/lib/Socket/index.js.map +1 -1
  69. package/lib/Socket/messages-recv.d.ts +23 -58
  70. package/lib/Socket/messages-recv.d.ts.map +1 -1
  71. package/lib/Socket/messages-recv.js +645 -181
  72. package/lib/Socket/messages-recv.js.map +1 -1
  73. package/lib/Socket/messages-send.d.ts +195 -575
  74. package/lib/Socket/messages-send.d.ts.map +1 -1
  75. package/lib/Socket/messages-send.js +1099 -1549
  76. package/lib/Socket/messages-send.js.map +1 -1
  77. package/lib/Socket/mex.d.ts.map +1 -1
  78. package/lib/Socket/mex.js +2 -8
  79. package/lib/Socket/mex.js.map +1 -1
  80. package/lib/Socket/newsletter.d.ts +11 -18
  81. package/lib/Socket/newsletter.d.ts.map +1 -1
  82. package/lib/Socket/newsletter.js +167 -302
  83. package/lib/Socket/newsletter.js.map +1 -1
  84. package/lib/Socket/socket.d.ts +6 -2
  85. package/lib/Socket/socket.d.ts.map +1 -1
  86. package/lib/Socket/socket.js +59 -25
  87. package/lib/Socket/socket.js.map +1 -1
  88. package/lib/Types/Auth.d.ts +1 -0
  89. package/lib/Types/Auth.d.ts.map +1 -1
  90. package/lib/Types/Bussines.d.ts +22 -34
  91. package/lib/Types/Call.d.ts +1 -1
  92. package/lib/Types/Call.d.ts.map +1 -1
  93. package/lib/Types/Chat.d.ts +1 -0
  94. package/lib/Types/Chat.d.ts.map +1 -1
  95. package/lib/Types/Contact.d.ts +2 -0
  96. package/lib/Types/Contact.d.ts.map +1 -1
  97. package/lib/Types/Events.d.ts +20 -1
  98. package/lib/Types/Events.d.ts.map +1 -1
  99. package/lib/Types/GroupMetadata.d.ts +4 -1
  100. package/lib/Types/GroupMetadata.d.ts.map +1 -1
  101. package/lib/Types/Message.d.ts +239 -341
  102. package/lib/Types/Message.d.ts.map +1 -1
  103. package/lib/Types/Message.js.map +1 -1
  104. package/lib/Types/{Newsletter.d.ts → Mex.d.ts} +11 -5
  105. package/lib/Types/Mex.d.ts.map +1 -0
  106. package/lib/Types/{Newsletter.js → Mex.js} +9 -3
  107. package/lib/Types/Mex.js.map +1 -0
  108. package/lib/Types/Signal.d.ts +12 -1
  109. package/lib/Types/Signal.d.ts.map +1 -1
  110. package/lib/Types/Socket.d.ts +126 -148
  111. package/lib/Types/Socket.d.ts.map +1 -1
  112. package/lib/Types/State.d.ts +58 -0
  113. package/lib/Types/State.d.ts.map +1 -1
  114. package/lib/Types/State.js +43 -0
  115. package/lib/Types/State.js.map +1 -1
  116. package/lib/Types/index.d.ts +52 -52
  117. package/lib/Types/index.d.ts.map +1 -1
  118. package/lib/Types/index.js +23 -30
  119. package/lib/Types/index.js.map +1 -1
  120. package/lib/Utils/auth-utils.d.ts +5 -0
  121. package/lib/Utils/auth-utils.d.ts.map +1 -1
  122. package/lib/Utils/auth-utils.js +12 -0
  123. package/lib/Utils/auth-utils.js.map +1 -1
  124. package/lib/Utils/browser-utils.d.ts.map +1 -1
  125. package/lib/Utils/browser-utils.js +1 -0
  126. package/lib/Utils/browser-utils.js.map +1 -1
  127. package/lib/Utils/chat-utils.d.ts +34 -4
  128. package/lib/Utils/chat-utils.d.ts.map +1 -1
  129. package/lib/Utils/chat-utils.js +80 -20
  130. package/lib/Utils/chat-utils.js.map +1 -1
  131. package/lib/Utils/companion-reg-client-utils.d.ts +17 -0
  132. package/lib/Utils/companion-reg-client-utils.d.ts.map +1 -0
  133. package/lib/Utils/companion-reg-client-utils.js +35 -0
  134. package/lib/Utils/companion-reg-client-utils.js.map +1 -0
  135. package/lib/Utils/crypto.d.ts +12 -12
  136. package/lib/Utils/crypto.d.ts.map +1 -1
  137. package/lib/Utils/crypto.js.map +1 -1
  138. package/lib/Utils/decode-wa-message.d.ts +18 -0
  139. package/lib/Utils/decode-wa-message.d.ts.map +1 -1
  140. package/lib/Utils/decode-wa-message.js +34 -0
  141. package/lib/Utils/decode-wa-message.js.map +1 -1
  142. package/lib/Utils/event-buffer.d.ts +2 -0
  143. package/lib/Utils/event-buffer.d.ts.map +1 -1
  144. package/lib/Utils/event-buffer.js +49 -1
  145. package/lib/Utils/event-buffer.js.map +1 -1
  146. package/lib/Utils/generics.d.ts +3 -2
  147. package/lib/Utils/generics.d.ts.map +1 -1
  148. package/lib/Utils/generics.js +10 -1
  149. package/lib/Utils/generics.js.map +1 -1
  150. package/lib/Utils/history.d.ts +2 -0
  151. package/lib/Utils/history.d.ts.map +1 -1
  152. package/lib/Utils/history.js +12 -9
  153. package/lib/Utils/history.js.map +1 -1
  154. package/lib/Utils/identity-change-handler.d.ts +7 -0
  155. package/lib/Utils/identity-change-handler.d.ts.map +1 -1
  156. package/lib/Utils/identity-change-handler.js +1 -0
  157. package/lib/Utils/identity-change-handler.js.map +1 -1
  158. package/lib/Utils/index.d.ts +22 -25
  159. package/lib/Utils/index.d.ts.map +1 -1
  160. package/lib/Utils/index.js +2 -4
  161. package/lib/Utils/index.js.map +1 -1
  162. package/lib/Utils/link-preview.js +2 -2
  163. package/lib/Utils/link-preview.js.map +1 -1
  164. package/lib/Utils/logger.d.ts +1 -2
  165. package/lib/Utils/logger.d.ts.map +1 -1
  166. package/lib/Utils/message-retry-manager.d.ts +5 -0
  167. package/lib/Utils/message-retry-manager.d.ts.map +1 -1
  168. package/lib/Utils/message-retry-manager.js +40 -0
  169. package/lib/Utils/message-retry-manager.js.map +1 -1
  170. package/lib/Utils/messages-media.d.ts +16 -13
  171. package/lib/Utils/messages-media.d.ts.map +1 -1
  172. package/lib/Utils/messages-media.js +85 -79
  173. package/lib/Utils/messages-media.js.map +1 -1
  174. package/lib/Utils/messages.d.ts +1 -1
  175. package/lib/Utils/messages.d.ts.map +1 -1
  176. package/lib/Utils/messages.js +751 -1096
  177. package/lib/Utils/messages.js.map +1 -1
  178. package/lib/Utils/noise-handler.d.ts +1 -1
  179. package/lib/Utils/process-message.d.ts.map +1 -1
  180. package/lib/Utils/process-message.js +103 -1
  181. package/lib/Utils/process-message.js.map +1 -1
  182. package/lib/Utils/signal.d.ts +13 -0
  183. package/lib/Utils/signal.d.ts.map +1 -1
  184. package/lib/Utils/signal.js +42 -0
  185. package/lib/Utils/signal.js.map +1 -1
  186. package/lib/Utils/sync-action-utils.d.ts.map +1 -1
  187. package/lib/Utils/sync-action-utils.js +1 -0
  188. package/lib/Utils/sync-action-utils.js.map +1 -1
  189. package/lib/Utils/tc-token-utils.d.ts +26 -1
  190. package/lib/Utils/tc-token-utils.d.ts.map +1 -1
  191. package/lib/Utils/tc-token-utils.js +151 -5
  192. package/lib/Utils/tc-token-utils.js.map +1 -1
  193. package/lib/Utils/validate-connection.d.ts.map +1 -1
  194. package/lib/Utils/validate-connection.js +12 -2
  195. package/lib/Utils/validate-connection.js.map +1 -1
  196. package/lib/WABinary/decode.d.ts +1 -1
  197. package/lib/WABinary/decode.d.ts.map +1 -1
  198. package/lib/WABinary/generic-utils.d.ts +1 -3
  199. package/lib/WABinary/generic-utils.d.ts.map +1 -1
  200. package/lib/WABinary/generic-utils.js +0 -78
  201. package/lib/WABinary/generic-utils.js.map +1 -1
  202. package/lib/WAM/encode.d.ts +1 -1
  203. package/lib/WAM/encode.d.ts.map +1 -1
  204. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -1
  205. package/lib/WAUSync/Protocols/USyncContactProtocol.js +26 -3
  206. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -1
  207. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
  208. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +1 -0
  209. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
  210. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +1 -0
  211. package/lib/WAUSync/Protocols/index.d.ts +1 -0
  212. package/lib/WAUSync/Protocols/index.d.ts.map +1 -1
  213. package/lib/WAUSync/Protocols/index.js +1 -0
  214. package/lib/WAUSync/Protocols/index.js.map +1 -1
  215. package/lib/WAUSync/USyncQuery.d.ts +1 -0
  216. package/lib/WAUSync/USyncQuery.d.ts.map +1 -1
  217. package/lib/WAUSync/USyncQuery.js +6 -2
  218. package/lib/WAUSync/USyncQuery.js.map +1 -1
  219. package/lib/WAUSync/USyncUser.d.ts +4 -0
  220. package/lib/WAUSync/USyncUser.d.ts.map +1 -1
  221. package/lib/WAUSync/USyncUser.js +8 -0
  222. package/lib/WAUSync/USyncUser.js.map +1 -1
  223. package/lib/index.d.ts +3 -2
  224. package/lib/index.d.ts.map +1 -1
  225. package/lib/index.js +13 -12
  226. package/lib/index.js.map +1 -1
  227. package/package.json +93 -23
  228. package/LICENSE +0 -21
  229. package/lib/Socket/dugong.d.ts +0 -130
  230. package/lib/Socket/dugong.d.ts.map +0 -1
  231. package/lib/Socket/dugong.js +0 -768
  232. package/lib/Socket/dugong.js.map +0 -1
  233. package/lib/Types/Newsletter.d.ts.map +0 -1
  234. package/lib/Types/Newsletter.js.map +0 -1
  235. package/lib/Utils/kyy-features.d.ts +0 -158
  236. package/lib/Utils/kyy-features.js +0 -365
  237. package/lib/Utils/rich-messages.d.ts +0 -277
  238. package/lib/Utils/rich-messages.d.ts.map +0 -1
  239. package/lib/Utils/rich-messages.js +0 -1144
  240. package/lib/Utils/rich-messages.js.map +0 -1
  241. package/lib/Utils/sticker-pack.d.ts +0 -10
  242. package/lib/Utils/sticker-pack.js +0 -111
@@ -0,0 +1,179 @@
1
+ import { prepareWAMessageMedia } from '../../Utils/messages.js'
2
+
3
+ export class CardBuilder {
4
+ constructor(parent, options = {}) {
5
+ this.parent = parent
6
+ this.card = {
7
+ header: {
8
+ hasMediaAttachment: false
9
+ },
10
+ body: { text: '' },
11
+ footer: { text: '' },
12
+ nativeFlowMessage: { buttons: [] }
13
+ }
14
+
15
+ if (options && typeof options === 'object') {
16
+ if (options.image !== undefined) this.image(options.image, options.imageOptions || {})
17
+ if (options.video !== undefined) this.video(options.video, options.videoOptions || {})
18
+ this.payload(options)
19
+ }
20
+ }
21
+
22
+ title(value) {
23
+ this.card.header.title = String(value ?? '')
24
+ return this
25
+ }
26
+
27
+ body(value) {
28
+ this.card.body.text = String(value ?? '')
29
+ return this
30
+ }
31
+
32
+ text(value) {
33
+ return this.body(value)
34
+ }
35
+
36
+ footer(value) {
37
+ this.card.footer.text = String(value ?? '')
38
+ return this
39
+ }
40
+
41
+ image(media, options = {}) {
42
+ this.card._media = { type: 'image', media, options }
43
+ return this
44
+ }
45
+
46
+ video(media, options = {}) {
47
+ this.card._media = { type: 'video', media, options }
48
+ return this
49
+ }
50
+
51
+ media(type, media, options = {}) {
52
+ if (type !== 'image' && type !== 'video') {
53
+ throw new TypeError('Carousel card media must be image or video')
54
+ }
55
+ return this[type](media, options)
56
+ }
57
+
58
+ button(displayText, id, options = {}) {
59
+ return this._button('quick_reply', {
60
+ display_text: displayText,
61
+ id,
62
+ ...options
63
+ })
64
+ }
65
+
66
+ reply(displayText, id, options = {}) {
67
+ return this.button(displayText, id, options)
68
+ }
69
+
70
+ quickReply(displayText, id, options = {}) {
71
+ return this.button(displayText, id, options)
72
+ }
73
+
74
+ url(displayText, url, options = {}) {
75
+ return this._button('cta_url', {
76
+ display_text: displayText,
77
+ url,
78
+ ...options
79
+ })
80
+ }
81
+
82
+ copy(displayText, copyCode, options = {}) {
83
+ return this._button('cta_copy', {
84
+ display_text: displayText,
85
+ copy_code: copyCode,
86
+ ...options
87
+ })
88
+ }
89
+
90
+ coppy(displayText, copyCode, options = {}) {
91
+ return this.copy(displayText, copyCode, options)
92
+ }
93
+
94
+ call(displayText, phone, options = {}) {
95
+ return this._button('cta_call', {
96
+ display_text: displayText,
97
+ id: phone,
98
+ ...options
99
+ })
100
+ }
101
+
102
+ buttons(buttons = []) {
103
+ if (!Array.isArray(buttons)) {
104
+ throw new TypeError('Buttons must be an array')
105
+ }
106
+
107
+ this.card.nativeFlowMessage.buttons.push(...buttons)
108
+ return this
109
+ }
110
+
111
+ rawButton(button) {
112
+ if (!button || typeof button !== 'object' || Array.isArray(button)) {
113
+ throw new TypeError('Button must be a plain object')
114
+ }
115
+
116
+ this.card.nativeFlowMessage.buttons.push(button)
117
+ return this
118
+ }
119
+
120
+ context(value) {
121
+ this.card.contextInfo = value || {}
122
+ return this
123
+ }
124
+
125
+ payload(value) {
126
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
127
+ return this
128
+ }
129
+
130
+ const { header, body, footer, nativeFlowMessage, image, video, imageOptions, videoOptions, ...extra } = value
131
+
132
+ Object.assign(this.card, extra)
133
+ if (header) Object.assign(this.card.header, header)
134
+ if (body) Object.assign(this.card.body, body)
135
+ if (footer) Object.assign(this.card.footer, footer)
136
+ if (nativeFlowMessage) Object.assign(this.card.nativeFlowMessage, nativeFlowMessage)
137
+
138
+ return this
139
+ }
140
+
141
+ _button(name, params) {
142
+ this.card.nativeFlowMessage.buttons.push({
143
+ name,
144
+ buttonParamsJson: JSON.stringify(params)
145
+ })
146
+ return this
147
+ }
148
+
149
+ async build() {
150
+ const { _media, ...card } = this.card
151
+
152
+ if (!_media) {
153
+ throw new Error('Carousel card requires image() or video()')
154
+ }
155
+
156
+ const media = {
157
+ [_media.type]: _media.media,
158
+ ..._media.options
159
+ }
160
+
161
+ const prepared = await prepareWAMessageMedia(media, {
162
+ upload: this.parent.sock.waUploadToServer
163
+ })
164
+
165
+ card.header.hasMediaAttachment = true
166
+ card.header[`${_media.type}Message`] = prepared[`${_media.type}Message`]
167
+
168
+ return card
169
+ }
170
+
171
+ add() {
172
+ this.parent._cards.push(this)
173
+ return this.parent
174
+ }
175
+
176
+ end() {
177
+ return this.add()
178
+ }
179
+ }
@@ -0,0 +1,97 @@
1
+ import { Carousel } from '../Carousel.js'
2
+ import { CardBuilder } from './CardBuilder.js'
3
+
4
+ const aliases = {
5
+ title: 'setTitle',
6
+ subtitle: 'setSubtitle',
7
+ body: 'setBody',
8
+ text: 'setBody',
9
+ footer: 'setFooter',
10
+ context: 'setContextInfo',
11
+ payload: 'addPayload'
12
+ }
13
+
14
+ export class CarouselBuilder {
15
+ constructor(sock, ...args) {
16
+ if (!sock) throw new Error('Socket is required')
17
+
18
+ this.sock = sock
19
+ this.raw = new Carousel(sock, ...args)
20
+ this._cards = []
21
+ this._rawCards = []
22
+ }
23
+
24
+ card(options = {}) {
25
+ return new CardBuilder(this, options)
26
+ }
27
+
28
+ addCard(card) {
29
+ if (card instanceof CardBuilder) {
30
+ if (!this._cards.includes(card)) this._cards.push(card)
31
+ return this
32
+ }
33
+
34
+ this._rawCards.push(card)
35
+ return this
36
+ }
37
+
38
+ cards(cards = []) {
39
+ if (!Array.isArray(cards)) {
40
+ throw new TypeError('Cards must be an array')
41
+ }
42
+
43
+ for (const card of cards) this.addCard(card)
44
+ return this
45
+ }
46
+
47
+ clear() {
48
+ this._cards = []
49
+ this._rawCards = []
50
+ this.raw._cards = []
51
+ return this
52
+ }
53
+
54
+ async _prepareCards() {
55
+ this.raw._cards = []
56
+
57
+ for (const card of this._rawCards) {
58
+ this.raw.addCard(card)
59
+ }
60
+
61
+ for (const card of this._cards) {
62
+ this.raw.addCard(await card.build())
63
+ }
64
+
65
+ return this.raw
66
+ }
67
+
68
+ async build(jid, options = {}) {
69
+ await this._prepareCards()
70
+ return this.raw.build(jid, options)
71
+ }
72
+
73
+ async send(jid, options = {}) {
74
+ await this._prepareCards()
75
+ return this.raw.send(jid, options)
76
+ }
77
+
78
+ loadFrom(message) {
79
+ this.raw.loadFrom(message)
80
+ this._cards = []
81
+ this._rawCards = [...this.raw._cards]
82
+ return this
83
+ }
84
+ }
85
+
86
+ for (const [name, method] of Object.entries(aliases)) {
87
+ CarouselBuilder.prototype[name] = function (...args) {
88
+ const value = this.raw[method](...args)
89
+ return value === this.raw ? this : value
90
+ }
91
+ }
92
+
93
+ export { Carousel, CardBuilder }
94
+
95
+ export function createCarouselBuilder(sock, ...args) {
96
+ return new CarouselBuilder(sock, ...args)
97
+ }
@@ -0,0 +1,18 @@
1
+ import { Foad } from '../Foad.js'
2
+ import { Foad2 } from '../Foad2.js'
3
+ import { proxyBuilder } from './SimpleBuilder.js'
4
+
5
+ const foadAliases = {
6
+ title: 'addTitle',
7
+ html: 'addHtml'
8
+ }
9
+
10
+ export function createFoadBuilder(sock, ...args) {
11
+ return proxyBuilder({ sock, raw: new Foad(sock, ...args) }, foadAliases)
12
+ }
13
+
14
+ export function createFoad2Builder(sock, ...args) {
15
+ return proxyBuilder({ sock, raw: new Foad2(sock, ...args) }, foadAliases)
16
+ }
17
+
18
+ export { Foad, Foad2 }
@@ -0,0 +1,35 @@
1
+ export class MediaBuilder {
2
+ constructor(sock, type, media) {
3
+ this.sock = sock
4
+ this.type = type
5
+ this.content = { [type]: media }
6
+ }
7
+
8
+ caption(value) { this.content.caption = String(value ?? ''); return this }
9
+ fileName(value) { this.content.fileName = String(value ?? ''); return this }
10
+ mimetype(value) { this.content.mimetype = value; return this }
11
+ context(value) { this.content.contextInfo = value || {}; return this }
12
+ mentions(value) { this.content.mentions = Array.isArray(value) ? [...value] : []; return this }
13
+ payload(value) { Object.assign(this.content, value || {}); return this }
14
+ viewOnce(value = true) { this.content.viewOnce = Boolean(value); return this }
15
+ ptt(value = true) { this.content.ptt = Boolean(value); return this }
16
+ voice(value = true) { return this.ptt(value) }
17
+ ptv(value = true) { this.content.ptv = Boolean(value); return this }
18
+ videoNote(value = true) { return this.ptv(value) }
19
+ gif(value = true) { this.content.gifPlayback = Boolean(value); return this }
20
+ animated(value = true) { this.content.isAnimated = Boolean(value); return this }
21
+ dimensions(width, height) {
22
+ if (width != null) this.content.width = Number(width)
23
+ if (height != null) this.content.height = Number(height)
24
+ return this
25
+ }
26
+ thumbnail(value) { this.content.jpegThumbnail = value; return this }
27
+
28
+ build() {
29
+ return { ...this.content }
30
+ }
31
+
32
+ send(jid, options = {}) {
33
+ return this.sock.sendMessage(jid, this.build(), options)
34
+ }
35
+ }
@@ -0,0 +1,41 @@
1
+ export class MessageBuilder {
2
+ constructor(sock, content = {}) {
3
+ if (!sock) throw new Error('Socket is required')
4
+ this.sock = sock
5
+ this.content = { ...content }
6
+ }
7
+
8
+ payload(value) {
9
+ if (!value || typeof value !== 'object') return this
10
+ Object.assign(this.content, value)
11
+ return this
12
+ }
13
+
14
+ context(value) {
15
+ this.content.contextInfo = value || {}
16
+ return this
17
+ }
18
+
19
+ mentions(value) {
20
+ this.content.mentions = Array.isArray(value) ? [...value] : []
21
+ return this
22
+ }
23
+
24
+ viewOnce(value = true) {
25
+ this.content.viewOnce = Boolean(value)
26
+ return this
27
+ }
28
+
29
+ edit(key) {
30
+ this.content.edit = key
31
+ return this
32
+ }
33
+
34
+ build() {
35
+ return { ...this.content }
36
+ }
37
+
38
+ send(jid, options = {}) {
39
+ return this.sock.sendMessage(jid, this.build(), options)
40
+ }
41
+ }
@@ -0,0 +1,3 @@
1
+ import { MessageBuilder } from './MessageBuilder.js'
2
+
3
+ export class MessageTypesBuilder extends MessageBuilder {}
@@ -0,0 +1,28 @@
1
+ export class SimpleBuilder {
2
+ constructor(client, factory) {
3
+ if (!client) throw new Error('Socket is required')
4
+ this.sock = client
5
+ this._factory = factory
6
+ this.raw = factory()
7
+ }
8
+
9
+ build(...args) { return this.raw.build(...args) }
10
+ send(...args) { return this.raw.send(...args) }
11
+ }
12
+
13
+ export function proxyBuilder(builder, aliases = {}) {
14
+ return new Proxy(builder, {
15
+ get(target, prop, receiver) {
16
+ if (prop in target) return Reflect.get(target, prop, receiver)
17
+ const mapped = aliases[prop] || prop
18
+ const raw = target.raw
19
+ if (raw && typeof raw[mapped] === 'function') {
20
+ return (...args) => {
21
+ const value = raw[mapped](...args)
22
+ return value === raw ? receiver : value
23
+ }
24
+ }
25
+ return undefined
26
+ }
27
+ })
28
+ }
@@ -0,0 +1,83 @@
1
+ import { TextBuilder } from './TextBuilder.js'
2
+ import { MediaBuilder } from './MediaBuilder.js'
3
+ import { MessageBuilder } from './MessageBuilder.js'
4
+ import { createButtonBuilder, createButtonV2Builder } from './ButtonBuilder.js'
5
+ import { createCarouselBuilder } from './CarouselBuilder.js'
6
+ import { createAIBuilder } from './AIBuilder.js'
7
+ import { createFoadBuilder, createFoad2Builder } from './FoadBuilder.js'
8
+ import { Toolkit, Button, ButtonV2, Carousel, AIRich, Foad, Foad2 } from '../wrapper.js'
9
+
10
+ export class SimpleClient {
11
+ constructor(sock) {
12
+ if (!sock || (typeof sock !== 'object' && typeof sock !== 'function')) {
13
+ throw new TypeError('A Baileys socket is required')
14
+ }
15
+ this.sock = sock
16
+ this.raw = Object.freeze({ Toolkit, Button, ButtonV2, Carousel, AIRich, Foad, Foad2 })
17
+ this.wrapper = this.raw
18
+ }
19
+
20
+ text(text = '') { return new TextBuilder(this.sock, text) }
21
+ image(media) { return new MediaBuilder(this.sock, 'image', media) }
22
+ video(media) { return new MediaBuilder(this.sock, 'video', media) }
23
+ audio(media) { return new MediaBuilder(this.sock, 'audio', media) }
24
+ voice(media) { return new MediaBuilder(this.sock, 'audio', media).ptt(true) }
25
+ document(media) { return new MediaBuilder(this.sock, 'document', media) }
26
+ sticker(media) { return new MediaBuilder(this.sock, 'sticker', media) }
27
+ ptv(media) { return new MediaBuilder(this.sock, 'video', media).ptv(true) }
28
+ gif(media) { return new MediaBuilder(this.sock, 'video', media).gif(true) }
29
+
30
+ message(content = {}) { return new MessageBuilder(this.sock, content) }
31
+ poll(name, values = [], selectableCount = 1) {
32
+ return new MessageBuilder(this.sock, {
33
+ poll: { name, values, selectableCount }
34
+ })
35
+ }
36
+ event(options = {}) { return new MessageBuilder(this.sock, { event: options }) }
37
+ album(options = {}) { return new MessageBuilder(this.sock, { album: options }) }
38
+ contacts(displayName, contacts = []) {
39
+ return new MessageBuilder(this.sock, {
40
+ contacts: { displayName, contacts }
41
+ })
42
+ }
43
+ location(location = {}) { return new MessageBuilder(this.sock, { location }) }
44
+ buttonReply(displayText, id, index = 0) {
45
+ return new MessageBuilder(this.sock, {
46
+ buttonReply: { displayText, id, index },
47
+ type: 'plain'
48
+ })
49
+ }
50
+ listReply(reply = {}) { return new MessageBuilder(this.sock, { listReply: reply }) }
51
+ react(messageKey, text = '') {
52
+ return new MessageBuilder(this.sock, {
53
+ react: { key: messageKey, text }
54
+ })
55
+ }
56
+ groupInvite(info = {}) { return new MessageBuilder(this.sock, { groupInvite: info }) }
57
+ product(product, options = {}) {
58
+ return new MessageBuilder(this.sock, { product, ...options })
59
+ }
60
+ requestPhoneNumber(value = true) {
61
+ return new MessageBuilder(this.sock, { requestPhoneNumber: Boolean(value) })
62
+ }
63
+ sharePhoneNumber(value = true) {
64
+ return new MessageBuilder(this.sock, { sharePhoneNumber: Boolean(value) })
65
+ }
66
+ pin(messageKey, type, time) {
67
+ const payload = { pin: messageKey, type }
68
+ if (time != null) payload.time = time
69
+ return new MessageBuilder(this.sock, payload)
70
+ }
71
+ forward(message, force = false) {
72
+ return new MessageBuilder(this.sock, { forward: message, force })
73
+ }
74
+ delete(messageKey) { return new MessageBuilder(this.sock, { delete: messageKey }) }
75
+ disappearing(value) { return new MessageBuilder(this.sock, { disappearingMessagesInChat: value }) }
76
+ limitSharing(value = true) { return new MessageBuilder(this.sock, { limitSharing: Boolean(value) }) }
77
+ button(...args) { return createButtonBuilder(this.sock, ...args) }
78
+ buttonV2(...args) { return createButtonV2Builder(this.sock, ...args) }
79
+ carousel(...args) { return createCarouselBuilder(this.sock, ...args) }
80
+ ai(...args) { return createAIBuilder(this.sock, ...args) }
81
+ foad(...args) { return createFoadBuilder(this.sock, ...args) }
82
+ foad2(...args) { return createFoad2Builder(this.sock, ...args) }
83
+ }
@@ -0,0 +1,22 @@
1
+ export class TextBuilder {
2
+ constructor(sock, text = '') {
3
+ this.sock = sock
4
+ this.content = { text: String(text ?? '') }
5
+ }
6
+
7
+ text(value) { this.content.text = String(value ?? ''); return this }
8
+ footer(value) { this.content.footer = String(value ?? ''); return this }
9
+ context(value) { this.content.contextInfo = value || {}; return this }
10
+ mentions(value) { this.content.mentions = Array.isArray(value) ? [...value] : []; return this }
11
+ viewOnce(value = true) { this.content.viewOnce = Boolean(value); return this }
12
+ edit(key) { this.content.edit = key; return this }
13
+ payload(value) { Object.assign(this.content, value || {}); return this }
14
+
15
+ build() {
16
+ return { ...this.content }
17
+ }
18
+
19
+ send(jid, options = {}) {
20
+ return this.sock.sendMessage(jid, { ...this.content }, options)
21
+ }
22
+ }
@@ -0,0 +1,141 @@
1
+ export declare class SimpleClient {
2
+ readonly sock: any
3
+ readonly raw: Record<string, any>
4
+ readonly wrapper: Record<string, any>
5
+ constructor(sock: any)
6
+ text(text?: string): TextBuilder
7
+ image(media: any): MediaBuilder
8
+ video(media: any): MediaBuilder
9
+ audio(media: any): MediaBuilder
10
+ voice(media: any): MediaBuilder
11
+ document(media: any): MediaBuilder
12
+ sticker(media: any): MediaBuilder
13
+ ptv(media: any): MediaBuilder
14
+ gif(media: any): MediaBuilder
15
+ message(content?: Record<string, any>): MessageBuilder
16
+ poll(name: string, values?: string[], selectableCount?: number): MessageBuilder
17
+ event(options?: Record<string, any>): MessageBuilder
18
+ album(options?: Record<string, any>): MessageBuilder
19
+ contacts(displayName: string, contacts?: any[]): MessageBuilder
20
+ location(location?: Record<string, any>): MessageBuilder
21
+ buttonReply(displayText: string, id: string, index?: number): MessageBuilder
22
+ listReply(reply?: Record<string, any>): MessageBuilder
23
+ react(messageKey: any, text?: string): MessageBuilder
24
+ groupInvite(info?: Record<string, any>): MessageBuilder
25
+ product(product: any, options?: Record<string, any>): MessageBuilder
26
+ requestPhoneNumber(value?: boolean): MessageBuilder
27
+ sharePhoneNumber(value?: boolean): MessageBuilder
28
+ pin(messageKey: any, type?: any, time?: 86400 | 604800 | 2592000): MessageBuilder
29
+ forward(message: any, force?: boolean): MessageBuilder
30
+ delete(messageKey: any): MessageBuilder
31
+ disappearing(value: boolean | number): MessageBuilder
32
+ limitSharing(value?: boolean): MessageBuilder
33
+ button(...args: any[]): any
34
+ buttonV2(...args: any[]): any
35
+ carousel(...args: any[]): any
36
+ ai(...args: any[]): any
37
+ foad(...args: any[]): any
38
+ foad2(...args: any[]): any
39
+ }
40
+
41
+ export declare class TextBuilder {
42
+ constructor(sock: any, text?: string)
43
+ text(value: string): this
44
+ footer(value: string): this
45
+ context(value: Record<string, any>): this
46
+ mentions(value: string[]): this
47
+ viewOnce(value?: boolean): this
48
+ edit(key: any): this
49
+ payload(value: Record<string, any>): this
50
+ mentions(value: string[]): this
51
+ viewOnce(value?: boolean): this
52
+ edit(key: any): this
53
+ build(): Record<string, any>
54
+ send(jid: string, options?: Record<string, any>): Promise<any>
55
+ }
56
+
57
+ export declare class MediaBuilder {
58
+ constructor(sock: any, type: string, media: any)
59
+ caption(value: string): this
60
+ fileName(value: string): this
61
+ mimetype(value: string): this
62
+ context(value: Record<string, any>): this
63
+ payload(value: Record<string, any>): this
64
+ mentions(value: string[]): this
65
+ viewOnce(value?: boolean): this
66
+ ptt(value?: boolean): this
67
+ voice(value?: boolean): this
68
+ ptv(value?: boolean): this
69
+ videoNote(value?: boolean): this
70
+ gif(value?: boolean): this
71
+ animated(value?: boolean): this
72
+ dimensions(width?: number, height?: number): this
73
+ thumbnail(value: any): this
74
+ build(): Record<string, any>
75
+ send(jid: string, options?: Record<string, any>): Promise<any>
76
+ }
77
+
78
+ export declare class CardBuilder {
79
+ constructor(parent: any, options?: Record<string, any>)
80
+ title(value: string): this
81
+ body(value: string): this
82
+ text(value: string): this
83
+ footer(value: string): this
84
+ image(media: any, options?: Record<string, any>): this
85
+ video(media: any, options?: Record<string, any>): this
86
+ media(type: 'image' | 'video', media: any, options?: Record<string, any>): this
87
+ button(displayText: string, id: string, options?: Record<string, any>): this
88
+ reply(displayText: string, id: string, options?: Record<string, any>): this
89
+ quickReply(displayText: string, id: string, options?: Record<string, any>): this
90
+ url(displayText: string, url: string, options?: Record<string, any>): this
91
+ copy(displayText: string, copyCode: string, options?: Record<string, any>): this
92
+ coppy(displayText: string, copyCode: string, options?: Record<string, any>): this
93
+ call(displayText: string, phone: string, options?: Record<string, any>): this
94
+ buttons(buttons?: any[]): this
95
+ rawButton(button: Record<string, any>): this
96
+ context(value: Record<string, any>): this
97
+ payload(value: Record<string, any>): this
98
+ build(): Promise<Record<string, any>>
99
+ add(): CarouselBuilder
100
+ end(): CarouselBuilder
101
+ }
102
+
103
+ export declare class CarouselBuilder {
104
+ readonly sock: any
105
+ readonly raw: any
106
+ constructor(sock: any, ...args: any[])
107
+ card(options?: Record<string, any>): CardBuilder
108
+ cards(cards?: any[]): this
109
+ addCard(card: any): this
110
+ clear(): this
111
+ title(value: string): this
112
+ subtitle(value: string): this
113
+ body(value: string): this
114
+ text(value: string): this
115
+ footer(value: string): this
116
+ context(value: Record<string, any>): this
117
+ payload(value: Record<string, any>): this
118
+ loadFrom(message: any): this
119
+ build(jid: string, options?: Record<string, any>): Promise<any>
120
+ send(jid: string, options?: Record<string, any>): Promise<any>
121
+ }
122
+
123
+ export declare class MessageBuilder {
124
+ constructor(sock: any, content?: Record<string, any>)
125
+ payload(value: Record<string, any>): this
126
+ context(value: Record<string, any>): this
127
+ mentions(value: string[]): this
128
+ viewOnce(value?: boolean): this
129
+ edit(key: any): this
130
+ build(): Record<string, any>
131
+ send(jid: string, options?: Record<string, any>): Promise<any>
132
+ }
133
+
134
+ export declare function createKyyinfinite(sock: any): SimpleClient
135
+ export declare function attachKyyinfinite(sock: any): any
136
+ export declare function createAIBuilder(sock: any, ...args: any[]): any
137
+ export declare function createButtonBuilder(sock: any, ...args: any[]): any
138
+ export declare function createButtonV2Builder(sock: any, ...args: any[]): any
139
+ export declare function createCarouselBuilder(sock: any, ...args: any[]): CarouselBuilder
140
+ export declare function createFoadBuilder(sock: any, ...args: any[]): any
141
+ export declare function createFoad2Builder(sock: any, ...args: any[]): any
@@ -0,0 +1,31 @@
1
+ import { SimpleClient } from './SimpleClient.js'
2
+
3
+ export { SimpleClient }
4
+ export { TextBuilder } from './TextBuilder.js'
5
+ export { MediaBuilder } from './MediaBuilder.js'
6
+ export { MessageBuilder } from './MessageBuilder.js'
7
+ export { createAIBuilder, AIRich } from './AIBuilder.js'
8
+ export { createButtonBuilder, createButtonV2Builder, Button, ButtonV2 } from './ButtonBuilder.js'
9
+ export { createCarouselBuilder, CarouselBuilder, CardBuilder, Carousel } from './CarouselBuilder.js'
10
+ export { createFoadBuilder, createFoad2Builder, Foad, Foad2 } from './FoadBuilder.js'
11
+
12
+ export function createKyyinfinite(sock) {
13
+ return new SimpleClient(sock)
14
+ }
15
+
16
+ export function attachKyyinfinite(sock) {
17
+ const api = new SimpleClient(sock)
18
+ const names = ['text', 'image', 'video', 'audio', 'voice', 'document', 'sticker', 'ptv', 'gif', 'message', 'poll', 'event', 'album', 'contacts', 'location', 'react', 'groupInvite', 'product', 'requestPhoneNumber', 'sharePhoneNumber', 'pin', 'forward', 'delete', 'disappearing', 'limitSharing', 'button', 'buttonV2', 'carousel', 'ai', 'foad', 'foad2']
19
+
20
+ for (const name of names) {
21
+ if (name in sock) continue
22
+ Object.defineProperty(sock, name, {
23
+ configurable: true,
24
+ enumerable: false,
25
+ writable: false,
26
+ value: (...args) => api[name](...args)
27
+ })
28
+ }
29
+
30
+ return sock
31
+ }