@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.
Files changed (248) hide show
  1. package/README.md +582 -1340
  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/KyyMessage.js +46 -0
  25. package/lib/Kyyinfinite/Simple/MediaBuilder.js +41 -0
  26. package/lib/Kyyinfinite/Simple/MessageBuilder.js +55 -0
  27. package/lib/Kyyinfinite/Simple/MessageTypesBuilder.js +3 -0
  28. package/lib/Kyyinfinite/Simple/SimpleBuilder.js +28 -0
  29. package/lib/Kyyinfinite/Simple/SimpleClient.js +120 -0
  30. package/lib/Kyyinfinite/Simple/TextBuilder.js +28 -0
  31. package/lib/Kyyinfinite/Simple/UniversalMediaBuilder.js +21 -0
  32. package/lib/Kyyinfinite/Simple/index.d.ts +232 -0
  33. package/lib/Kyyinfinite/Simple/index.js +38 -0
  34. package/lib/Kyyinfinite/Simple/jid.js +55 -0
  35. package/lib/Kyyinfinite/Simple/messageUtils.js +49 -0
  36. package/lib/Kyyinfinite/Simple/parseMessage.js +55 -0
  37. package/lib/Kyyinfinite/Toolkit.js +453 -0
  38. package/lib/Kyyinfinite/constants.js +1 -0
  39. package/lib/Kyyinfinite/errors.js +39 -0
  40. package/lib/Kyyinfinite/index.d.ts +2 -0
  41. package/lib/Kyyinfinite/index.js +2 -0
  42. package/lib/Kyyinfinite/wrapper.d.ts +2 -0
  43. package/lib/Kyyinfinite/wrapper.js +10 -0
  44. package/lib/Signal/Group/group_cipher.js.map +1 -1
  45. package/lib/Signal/Group/keyhelper.d.ts.map +1 -1
  46. package/lib/Signal/Group/keyhelper.js.map +1 -1
  47. package/lib/Signal/Group/sender-chain-key.js.map +1 -1
  48. package/lib/Signal/Group/sender-key-message.js.map +1 -1
  49. package/lib/Signal/Group/sender-message-key.js.map +1 -1
  50. package/lib/Signal/libsignal.d.ts.map +1 -1
  51. package/lib/Signal/libsignal.js +45 -17
  52. package/lib/Signal/libsignal.js.map +1 -1
  53. package/lib/Signal/lid-mapping.d.ts +4 -0
  54. package/lib/Signal/lid-mapping.d.ts.map +1 -1
  55. package/lib/Signal/lid-mapping.js +6 -0
  56. package/lib/Signal/lid-mapping.js.map +1 -1
  57. package/lib/Socket/business.d.ts +213 -532
  58. package/lib/Socket/business.d.ts.map +1 -1
  59. package/lib/Socket/business.js +358 -401
  60. package/lib/Socket/chats.d.ts +16 -2
  61. package/lib/Socket/chats.d.ts.map +1 -1
  62. package/lib/Socket/chats.js +247 -40
  63. package/lib/Socket/chats.js.map +1 -1
  64. package/lib/Socket/communities.d.ts +269 -641
  65. package/lib/Socket/communities.d.ts.map +1 -1
  66. package/lib/Socket/groups.d.ts +13 -2
  67. package/lib/Socket/groups.d.ts.map +1 -1
  68. package/lib/Socket/groups.js +21 -1
  69. package/lib/Socket/groups.js.map +1 -1
  70. package/lib/Socket/index.d.ts +255 -631
  71. package/lib/Socket/index.d.ts.map +1 -1
  72. package/lib/Socket/index.js +9 -10
  73. package/lib/Socket/index.js.map +1 -1
  74. package/lib/Socket/messages-recv.d.ts +23 -58
  75. package/lib/Socket/messages-recv.d.ts.map +1 -1
  76. package/lib/Socket/messages-recv.js +645 -181
  77. package/lib/Socket/messages-recv.js.map +1 -1
  78. package/lib/Socket/messages-send.d.ts +195 -575
  79. package/lib/Socket/messages-send.d.ts.map +1 -1
  80. package/lib/Socket/messages-send.js +1099 -1549
  81. package/lib/Socket/messages-send.js.map +1 -1
  82. package/lib/Socket/mex.d.ts.map +1 -1
  83. package/lib/Socket/mex.js +2 -8
  84. package/lib/Socket/mex.js.map +1 -1
  85. package/lib/Socket/newsletter.d.ts +11 -18
  86. package/lib/Socket/newsletter.d.ts.map +1 -1
  87. package/lib/Socket/newsletter.js +167 -302
  88. package/lib/Socket/newsletter.js.map +1 -1
  89. package/lib/Socket/socket.d.ts +6 -2
  90. package/lib/Socket/socket.d.ts.map +1 -1
  91. package/lib/Socket/socket.js +59 -25
  92. package/lib/Socket/socket.js.map +1 -1
  93. package/lib/Types/Auth.d.ts +1 -0
  94. package/lib/Types/Auth.d.ts.map +1 -1
  95. package/lib/Types/Bussines.d.ts +22 -34
  96. package/lib/Types/Call.d.ts +1 -1
  97. package/lib/Types/Call.d.ts.map +1 -1
  98. package/lib/Types/Chat.d.ts +1 -0
  99. package/lib/Types/Chat.d.ts.map +1 -1
  100. package/lib/Types/Contact.d.ts +2 -0
  101. package/lib/Types/Contact.d.ts.map +1 -1
  102. package/lib/Types/Events.d.ts +20 -1
  103. package/lib/Types/Events.d.ts.map +1 -1
  104. package/lib/Types/GroupMetadata.d.ts +4 -1
  105. package/lib/Types/GroupMetadata.d.ts.map +1 -1
  106. package/lib/Types/Message.d.ts +239 -341
  107. package/lib/Types/Message.d.ts.map +1 -1
  108. package/lib/Types/Message.js.map +1 -1
  109. package/lib/Types/{Newsletter.d.ts → Mex.d.ts} +11 -5
  110. package/lib/Types/Mex.d.ts.map +1 -0
  111. package/lib/Types/{Newsletter.js → Mex.js} +9 -3
  112. package/lib/Types/Mex.js.map +1 -0
  113. package/lib/Types/Signal.d.ts +12 -1
  114. package/lib/Types/Signal.d.ts.map +1 -1
  115. package/lib/Types/Socket.d.ts +126 -148
  116. package/lib/Types/Socket.d.ts.map +1 -1
  117. package/lib/Types/State.d.ts +58 -0
  118. package/lib/Types/State.d.ts.map +1 -1
  119. package/lib/Types/State.js +43 -0
  120. package/lib/Types/State.js.map +1 -1
  121. package/lib/Types/index.d.ts +52 -52
  122. package/lib/Types/index.d.ts.map +1 -1
  123. package/lib/Types/index.js +23 -30
  124. package/lib/Types/index.js.map +1 -1
  125. package/lib/Utils/auth-utils.d.ts +5 -0
  126. package/lib/Utils/auth-utils.d.ts.map +1 -1
  127. package/lib/Utils/auth-utils.js +12 -0
  128. package/lib/Utils/auth-utils.js.map +1 -1
  129. package/lib/Utils/browser-utils.d.ts.map +1 -1
  130. package/lib/Utils/browser-utils.js +1 -0
  131. package/lib/Utils/browser-utils.js.map +1 -1
  132. package/lib/Utils/chat-utils.d.ts +34 -4
  133. package/lib/Utils/chat-utils.d.ts.map +1 -1
  134. package/lib/Utils/chat-utils.js +80 -20
  135. package/lib/Utils/chat-utils.js.map +1 -1
  136. package/lib/Utils/companion-reg-client-utils.d.ts +17 -0
  137. package/lib/Utils/companion-reg-client-utils.d.ts.map +1 -0
  138. package/lib/Utils/companion-reg-client-utils.js +35 -0
  139. package/lib/Utils/companion-reg-client-utils.js.map +1 -0
  140. package/lib/Utils/crypto.d.ts +12 -12
  141. package/lib/Utils/crypto.d.ts.map +1 -1
  142. package/lib/Utils/crypto.js.map +1 -1
  143. package/lib/Utils/decode-wa-message.d.ts +18 -0
  144. package/lib/Utils/decode-wa-message.d.ts.map +1 -1
  145. package/lib/Utils/decode-wa-message.js +34 -0
  146. package/lib/Utils/decode-wa-message.js.map +1 -1
  147. package/lib/Utils/event-buffer.d.ts +2 -0
  148. package/lib/Utils/event-buffer.d.ts.map +1 -1
  149. package/lib/Utils/event-buffer.js +49 -1
  150. package/lib/Utils/event-buffer.js.map +1 -1
  151. package/lib/Utils/generics.d.ts +3 -2
  152. package/lib/Utils/generics.d.ts.map +1 -1
  153. package/lib/Utils/generics.js +10 -1
  154. package/lib/Utils/generics.js.map +1 -1
  155. package/lib/Utils/history.d.ts +2 -0
  156. package/lib/Utils/history.d.ts.map +1 -1
  157. package/lib/Utils/history.js +12 -9
  158. package/lib/Utils/history.js.map +1 -1
  159. package/lib/Utils/identity-change-handler.d.ts +7 -0
  160. package/lib/Utils/identity-change-handler.d.ts.map +1 -1
  161. package/lib/Utils/identity-change-handler.js +1 -0
  162. package/lib/Utils/identity-change-handler.js.map +1 -1
  163. package/lib/Utils/index.d.ts +22 -25
  164. package/lib/Utils/index.d.ts.map +1 -1
  165. package/lib/Utils/index.js +2 -4
  166. package/lib/Utils/index.js.map +1 -1
  167. package/lib/Utils/link-preview.js +2 -2
  168. package/lib/Utils/link-preview.js.map +1 -1
  169. package/lib/Utils/logger.d.ts +1 -2
  170. package/lib/Utils/logger.d.ts.map +1 -1
  171. package/lib/Utils/message-retry-manager.d.ts +5 -0
  172. package/lib/Utils/message-retry-manager.d.ts.map +1 -1
  173. package/lib/Utils/message-retry-manager.js +40 -0
  174. package/lib/Utils/message-retry-manager.js.map +1 -1
  175. package/lib/Utils/messages-media.d.ts +16 -13
  176. package/lib/Utils/messages-media.d.ts.map +1 -1
  177. package/lib/Utils/messages-media.js +85 -79
  178. package/lib/Utils/messages-media.js.map +1 -1
  179. package/lib/Utils/messages.d.ts +1 -1
  180. package/lib/Utils/messages.d.ts.map +1 -1
  181. package/lib/Utils/messages.js +751 -1096
  182. package/lib/Utils/messages.js.map +1 -1
  183. package/lib/Utils/noise-handler.d.ts +1 -1
  184. package/lib/Utils/process-message.d.ts.map +1 -1
  185. package/lib/Utils/process-message.js +103 -1
  186. package/lib/Utils/process-message.js.map +1 -1
  187. package/lib/Utils/signal.d.ts +13 -0
  188. package/lib/Utils/signal.d.ts.map +1 -1
  189. package/lib/Utils/signal.js +42 -0
  190. package/lib/Utils/signal.js.map +1 -1
  191. package/lib/Utils/sync-action-utils.d.ts.map +1 -1
  192. package/lib/Utils/sync-action-utils.js +1 -0
  193. package/lib/Utils/sync-action-utils.js.map +1 -1
  194. package/lib/Utils/tc-token-utils.d.ts +26 -1
  195. package/lib/Utils/tc-token-utils.d.ts.map +1 -1
  196. package/lib/Utils/tc-token-utils.js +151 -5
  197. package/lib/Utils/tc-token-utils.js.map +1 -1
  198. package/lib/Utils/validate-connection.d.ts.map +1 -1
  199. package/lib/Utils/validate-connection.js +12 -2
  200. package/lib/Utils/validate-connection.js.map +1 -1
  201. package/lib/WABinary/decode.d.ts +1 -1
  202. package/lib/WABinary/decode.d.ts.map +1 -1
  203. package/lib/WABinary/generic-utils.d.ts +1 -3
  204. package/lib/WABinary/generic-utils.d.ts.map +1 -1
  205. package/lib/WABinary/generic-utils.js +0 -78
  206. package/lib/WABinary/generic-utils.js.map +1 -1
  207. package/lib/WAM/encode.d.ts +1 -1
  208. package/lib/WAM/encode.d.ts.map +1 -1
  209. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -1
  210. package/lib/WAUSync/Protocols/USyncContactProtocol.js +26 -3
  211. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -1
  212. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
  213. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +1 -0
  214. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
  215. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +1 -0
  216. package/lib/WAUSync/Protocols/index.d.ts +1 -0
  217. package/lib/WAUSync/Protocols/index.d.ts.map +1 -1
  218. package/lib/WAUSync/Protocols/index.js +1 -0
  219. package/lib/WAUSync/Protocols/index.js.map +1 -1
  220. package/lib/WAUSync/USyncQuery.d.ts +1 -0
  221. package/lib/WAUSync/USyncQuery.d.ts.map +1 -1
  222. package/lib/WAUSync/USyncQuery.js +6 -2
  223. package/lib/WAUSync/USyncQuery.js.map +1 -1
  224. package/lib/WAUSync/USyncUser.d.ts +4 -0
  225. package/lib/WAUSync/USyncUser.d.ts.map +1 -1
  226. package/lib/WAUSync/USyncUser.js +8 -0
  227. package/lib/WAUSync/USyncUser.js.map +1 -1
  228. package/lib/index.d.ts +3 -2
  229. package/lib/index.d.ts.map +1 -1
  230. package/lib/index.js +13 -12
  231. package/lib/index.js.map +1 -1
  232. package/package.json +104 -23
  233. package/test/core.test.js +38 -0
  234. package/test/simple-api.test.js +183 -0
  235. package/lib/Socket/dugong.d.ts +0 -130
  236. package/lib/Socket/dugong.d.ts.map +0 -1
  237. package/lib/Socket/dugong.js +0 -768
  238. package/lib/Socket/dugong.js.map +0 -1
  239. package/lib/Types/Newsletter.d.ts.map +0 -1
  240. package/lib/Types/Newsletter.js.map +0 -1
  241. package/lib/Utils/kyy-features.d.ts +0 -158
  242. package/lib/Utils/kyy-features.js +0 -365
  243. package/lib/Utils/rich-messages.d.ts +0 -277
  244. package/lib/Utils/rich-messages.d.ts.map +0 -1
  245. package/lib/Utils/rich-messages.js +0 -1144
  246. package/lib/Utils/rich-messages.js.map +0 -1
  247. package/lib/Utils/sticker-pack.d.ts +0 -10
  248. 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,46 @@
1
+ import { downloadMediaMessage } from '../../Utils/messages.js'
2
+
3
+ export class KyyMessage {
4
+ constructor(sock, message) {
5
+ if (!sock) throw new Error('Socket is required')
6
+ if (!message) throw new TypeError('A WhatsApp message is required')
7
+ this.sock = sock
8
+ this.message = message
9
+ this.key = message.key || message
10
+ }
11
+
12
+ get id() { return this.key?.id }
13
+ get jid() { return this.key?.remoteJid }
14
+ get sender() { return this.key?.participant || this.key?.remoteJid }
15
+ get fromMe() { return Boolean(this.key?.fromMe) }
16
+
17
+ reply(content, options = {}) {
18
+ const message = typeof content === 'string' ? { text: content } : { ...(content || {}) }
19
+ const sendOptions = { ...(options || {}), quoted: this.message }
20
+ return this.sock.sendMessage(this.jid, message, sendOptions)
21
+ }
22
+
23
+ react(text = '') {
24
+ return this.sock.sendMessage(this.jid, { react: { text: String(text), key: this.key } })
25
+ }
26
+
27
+ edit(content, options = {}) {
28
+ const message = typeof content === 'string' ? { text: content } : { ...(content || {}) }
29
+ message.edit = this.key
30
+ return this.sock.sendMessage(this.jid, message, options)
31
+ }
32
+
33
+ delete() {
34
+ return this.sock.sendMessage(this.jid, { delete: this.key })
35
+ }
36
+
37
+ forward(jid = this.jid, force = false) {
38
+ return this.sock.sendMessage(jid, { forward: this.message, force })
39
+ }
40
+
41
+ download(type = 'buffer', options = {}, ctx) {
42
+ return downloadMediaMessage(this.message, type, options, ctx)
43
+ }
44
+
45
+ raw() { return this.message }
46
+ }
@@ -0,0 +1,41 @@
1
+ import { applyAutoMentions, resolveMedia } from './messageUtils.js'
2
+
3
+ export class MediaBuilder {
4
+ constructor(sock, type, media) {
5
+ this.sock = sock
6
+ this.type = type
7
+ this.content = { [type]: resolveMedia(media) }
8
+ this._autoMentions = true
9
+ this._sendOptions = {}
10
+ }
11
+
12
+ caption(value) { this.content.caption = String(value ?? ''); return this }
13
+ fileName(value) { this.content.fileName = String(value ?? ''); return this }
14
+ mimetype(value) { this.content.mimetype = value; return this }
15
+ context(value) { this.content.contextInfo = value || {}; return this }
16
+ mentions(value) { this.content.mentions = Array.isArray(value) ? [...value] : []; return this }
17
+ autoMentions(value = true) { this._autoMentions = Boolean(value); return this }
18
+ quoted(message) { this._sendOptions.quoted = message; return this }
19
+ payload(value) { Object.assign(this.content, value || {}); return this }
20
+ viewOnce(value = true) { this.content.viewOnce = Boolean(value); return this }
21
+ ptt(value = true) { this.content.ptt = Boolean(value); return this }
22
+ voice(value = true) { return this.ptt(value) }
23
+ ptv(value = true) { this.content.ptv = Boolean(value); return this }
24
+ videoNote(value = true) { return this.ptv(value) }
25
+ gif(value = true) { this.content.gifPlayback = Boolean(value); return this }
26
+ animated(value = true) { this.content.isAnimated = Boolean(value); return this }
27
+ dimensions(width, height) {
28
+ if (width != null) this.content.width = Number(width)
29
+ if (height != null) this.content.height = Number(height)
30
+ return this
31
+ }
32
+ thumbnail(value) { this.content.jpegThumbnail = value; return this }
33
+
34
+ build() {
35
+ return applyAutoMentions({ ...this.content }, this._autoMentions)
36
+ }
37
+
38
+ send(jid, options = {}) {
39
+ return this.sock.sendMessage(jid, this.build(), { ...this._sendOptions, ...(options || {}) })
40
+ }
41
+ }
@@ -0,0 +1,55 @@
1
+ import { applyAutoMentions, resolveMediaContent } from './messageUtils.js'
2
+
3
+ export class MessageBuilder {
4
+ constructor(sock, content = {}) {
5
+ if (!sock) throw new Error('Socket is required')
6
+ this.sock = sock
7
+ this.content = { ...content }
8
+ this._autoMentions = true
9
+ this._sendOptions = {}
10
+ }
11
+
12
+ payload(value) {
13
+ if (!value || typeof value !== 'object') return this
14
+ Object.assign(this.content, value)
15
+ return this
16
+ }
17
+
18
+ context(value) {
19
+ this.content.contextInfo = value || {}
20
+ return this
21
+ }
22
+
23
+ mentions(value) {
24
+ this.content.mentions = Array.isArray(value) ? [...value] : []
25
+ return this
26
+ }
27
+
28
+ autoMentions(value = true) {
29
+ this._autoMentions = Boolean(value)
30
+ return this
31
+ }
32
+
33
+ quoted(message) {
34
+ this._sendOptions.quoted = message
35
+ return this
36
+ }
37
+
38
+ viewOnce(value = true) {
39
+ this.content.viewOnce = Boolean(value)
40
+ return this
41
+ }
42
+
43
+ edit(key) {
44
+ this.content.edit = key
45
+ return this
46
+ }
47
+
48
+ build() {
49
+ return applyAutoMentions(resolveMediaContent({ ...this.content }), this._autoMentions)
50
+ }
51
+
52
+ send(jid, options = {}) {
53
+ return this.sock.sendMessage(jid, this.build(), { ...this._sendOptions, ...(options || {}) })
54
+ }
55
+ }
@@ -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,120 @@
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
+ import { KyyMessage } from './KyyMessage.js'
10
+ import { UniversalMediaBuilder } from './UniversalMediaBuilder.js'
11
+ import { parseMessage } from './parseMessage.js'
12
+ import { applyAutoMentions, extractMentions, resolveMedia, resolveMediaContent, quotedOptions } from './messageUtils.js'
13
+ import { parseJid, normalizeJid, jidUser, jidServer, jidDevice, isGroupJid, isPrivateJid, isBroadcastJid, isStatusJid, isNewsletterJid, isLidJid, makeJid } from './jid.js'
14
+
15
+ export class SimpleClient {
16
+ constructor(sock) {
17
+ if (!sock || (typeof sock !== 'object' && typeof sock !== 'function')) {
18
+ throw new TypeError('A Baileys socket is required')
19
+ }
20
+ this.sock = sock
21
+ this.raw = Object.freeze({ Toolkit, Button, ButtonV2, Carousel, AIRich, Foad, Foad2 })
22
+ this.wrapper = this.raw
23
+ }
24
+
25
+ text(text = '') { return new TextBuilder(this.sock, text) }
26
+ media(media) { return new UniversalMediaBuilder(this.sock, media) }
27
+ wrapMessage(message) { return new KyyMessage(this.sock, message) }
28
+ parseMessage(message, options = {}) { return parseMessage(message, options) }
29
+ send(jid, content, options = {}) {
30
+ const { autoMentions = true, ...sendOptions } = options || {}
31
+ const message = typeof content === 'string' ? { text: content } : resolveMediaContent({ ...(content || {}) })
32
+ return this.sock.sendMessage(jid, applyAutoMentions(message, autoMentions !== false), sendOptions)
33
+ }
34
+ quoted(message, content, options = {}) {
35
+ return this.send(this.wrapMessage(message).jid, content, quotedOptions(message, options))
36
+ }
37
+ mentions(text) { return extractMentions(text) }
38
+ resolveMedia(media) { return resolveMedia(media) }
39
+ resolveMediaContent(content) { return resolveMediaContent(content) }
40
+ jid(value) { return normalizeJid(value) }
41
+ parseJid(value) { return parseJid(value) }
42
+ jidUser(value) { return jidUser(value) }
43
+ jidServer(value) { return jidServer(value) }
44
+ jidDevice(value) { return jidDevice(value) }
45
+ isGroup(value) { return isGroupJid(value) }
46
+ isPrivate(value) { return isPrivateJid(value) }
47
+ isBroadcast(value) { return isBroadcastJid(value) }
48
+ isStatus(value) { return isStatusJid(value) }
49
+ isNewsletter(value) { return isNewsletterJid(value) }
50
+ isLid(value) { return isLidJid(value) }
51
+ makeJid(user, server = 's.whatsapp.net', device = null) { return makeJid(user, server, device) }
52
+ reply(message, content, options = {}) { return this.wrapMessage(message).reply(content, options) }
53
+ reactTo(message, text = '') { return this.wrapMessage(message).react(text) }
54
+ editMessage(message, content, options = {}) { return this.wrapMessage(message).edit(content, options) }
55
+ deleteMessage(message) { return this.wrapMessage(message).delete() }
56
+ forwardMessage(message, jid, force = false) { return this.wrapMessage(message).forward(jid, force) }
57
+ downloadMessage(message, type = 'buffer', options = {}, ctx) { return this.wrapMessage(message).download(type, options, ctx) }
58
+ image(media) { return new MediaBuilder(this.sock, 'image', media) }
59
+ video(media) { return new MediaBuilder(this.sock, 'video', media) }
60
+ audio(media) { return new MediaBuilder(this.sock, 'audio', media) }
61
+ voice(media) { return new MediaBuilder(this.sock, 'audio', media).ptt(true) }
62
+ document(media) { return new MediaBuilder(this.sock, 'document', media) }
63
+ sticker(media) { return new MediaBuilder(this.sock, 'sticker', media) }
64
+ ptv(media) { return new MediaBuilder(this.sock, 'video', media).ptv(true) }
65
+ gif(media) { return new MediaBuilder(this.sock, 'video', media).gif(true) }
66
+
67
+ message(content = {}) { return new MessageBuilder(this.sock, content) }
68
+ poll(name, values = [], selectableCount = 1) {
69
+ return new MessageBuilder(this.sock, {
70
+ poll: { name, values, selectableCount }
71
+ })
72
+ }
73
+ event(options = {}) { return new MessageBuilder(this.sock, { event: options }) }
74
+ album(options = {}) { return new MessageBuilder(this.sock, { album: options }) }
75
+ contacts(displayName, contacts = []) {
76
+ return new MessageBuilder(this.sock, {
77
+ contacts: { displayName, contacts }
78
+ })
79
+ }
80
+ location(location = {}) { return new MessageBuilder(this.sock, { location }) }
81
+ buttonReply(displayText, id, index = 0) {
82
+ return new MessageBuilder(this.sock, {
83
+ buttonReply: { displayText, id, index },
84
+ type: 'plain'
85
+ })
86
+ }
87
+ listReply(reply = {}) { return new MessageBuilder(this.sock, { listReply: reply }) }
88
+ react(messageKey, text = '') {
89
+ return new MessageBuilder(this.sock, {
90
+ react: { key: messageKey, text }
91
+ })
92
+ }
93
+ groupInvite(info = {}) { return new MessageBuilder(this.sock, { groupInvite: info }) }
94
+ product(product, options = {}) {
95
+ return new MessageBuilder(this.sock, { product, ...options })
96
+ }
97
+ requestPhoneNumber(value = true) {
98
+ return new MessageBuilder(this.sock, { requestPhoneNumber: Boolean(value) })
99
+ }
100
+ sharePhoneNumber(value = true) {
101
+ return new MessageBuilder(this.sock, { sharePhoneNumber: Boolean(value) })
102
+ }
103
+ pin(messageKey, type, time) {
104
+ const payload = { pin: messageKey, type }
105
+ if (time != null) payload.time = time
106
+ return new MessageBuilder(this.sock, payload)
107
+ }
108
+ forward(message, force = false) {
109
+ return new MessageBuilder(this.sock, { forward: message, force })
110
+ }
111
+ delete(messageKey) { return new MessageBuilder(this.sock, { delete: messageKey }) }
112
+ disappearing(value) { return new MessageBuilder(this.sock, { disappearingMessagesInChat: value }) }
113
+ limitSharing(value = true) { return new MessageBuilder(this.sock, { limitSharing: Boolean(value) }) }
114
+ button(...args) { return createButtonBuilder(this.sock, ...args) }
115
+ buttonV2(...args) { return createButtonV2Builder(this.sock, ...args) }
116
+ carousel(...args) { return createCarouselBuilder(this.sock, ...args) }
117
+ ai(...args) { return createAIBuilder(this.sock, ...args) }
118
+ foad(...args) { return createFoadBuilder(this.sock, ...args) }
119
+ foad2(...args) { return createFoad2Builder(this.sock, ...args) }
120
+ }
@@ -0,0 +1,28 @@
1
+ import { applyAutoMentions } from './messageUtils.js'
2
+
3
+ export class TextBuilder {
4
+ constructor(sock, text = '') {
5
+ this.sock = sock
6
+ this.content = { text: String(text ?? '') }
7
+ this._autoMentions = true
8
+ this._sendOptions = {}
9
+ }
10
+
11
+ text(value) { this.content.text = String(value ?? ''); return this }
12
+ footer(value) { this.content.footer = String(value ?? ''); return this }
13
+ context(value) { this.content.contextInfo = value || {}; return this }
14
+ mentions(value) { this.content.mentions = Array.isArray(value) ? [...value] : []; return this }
15
+ autoMentions(value = true) { this._autoMentions = Boolean(value); return this }
16
+ quoted(message) { this._sendOptions.quoted = message; return this }
17
+ viewOnce(value = true) { this.content.viewOnce = Boolean(value); return this }
18
+ edit(key) { this.content.edit = key; return this }
19
+ payload(value) { Object.assign(this.content, value || {}); return this }
20
+
21
+ build() {
22
+ return applyAutoMentions({ ...this.content }, this._autoMentions)
23
+ }
24
+
25
+ send(jid, options = {}) {
26
+ return this.sock.sendMessage(jid, this.build(), { ...this._sendOptions, ...(options || {}) })
27
+ }
28
+ }
@@ -0,0 +1,21 @@
1
+ import { MediaBuilder } from './MediaBuilder.js'
2
+
3
+ export class UniversalMediaBuilder extends MediaBuilder {
4
+ constructor(sock, media) {
5
+ super(sock, 'image', media)
6
+ }
7
+
8
+ _setType(type) {
9
+ const current = this.content[this.type]
10
+ delete this.content[this.type]
11
+ this.type = type
12
+ this.content[type] = current
13
+ return this
14
+ }
15
+
16
+ asImage() { return this._setType('image') }
17
+ asVideo() { return this._setType('video') }
18
+ asAudio() { return this._setType('audio') }
19
+ asDocument() { return this._setType('document') }
20
+ asSticker() { return this._setType('sticker') }
21
+ }