@merajah/baileys 1.0.9 → 4.2.1

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 (204) hide show
  1. package/lib/cache.js +1 -0
  2. package/lib/converter.js +1 -0
  3. package/lib/extra.js +1 -0
  4. package/lib/index.js +32 -22
  5. package/lib/serialize.js +1 -0
  6. package/lib/wrapper.js +1 -0
  7. package/package.json +21 -108
  8. package/readme.md +64 -42
  9. package/WAProto/index.js +0 -169661
  10. package/lib/Defaults/baileys-version.json +0 -3
  11. package/lib/Defaults/index.d.ts +0 -53
  12. package/lib/Defaults/index.js +0 -147
  13. package/lib/Defaults/phonenumber-mcc.json +0 -223
  14. package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
  15. package/lib/Signal/Group/ciphertext-message.js +0 -15
  16. package/lib/Signal/Group/group-session-builder.d.ts +0 -14
  17. package/lib/Signal/Group/group-session-builder.js +0 -64
  18. package/lib/Signal/Group/group_cipher.d.ts +0 -17
  19. package/lib/Signal/Group/group_cipher.js +0 -96
  20. package/lib/Signal/Group/index.d.ts +0 -11
  21. package/lib/Signal/Group/index.js +0 -57
  22. package/lib/Signal/Group/keyhelper.d.ts +0 -10
  23. package/lib/Signal/Group/keyhelper.js +0 -55
  24. package/lib/Signal/Group/queue-job.d.ts +0 -1
  25. package/lib/Signal/Group/queue-job.js +0 -57
  26. package/lib/Signal/Group/sender-chain-key.d.ts +0 -13
  27. package/lib/Signal/Group/sender-chain-key.js +0 -34
  28. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -16
  29. package/lib/Signal/Group/sender-key-distribution-message.js +0 -66
  30. package/lib/Signal/Group/sender-key-message.d.ts +0 -18
  31. package/lib/Signal/Group/sender-key-message.js +0 -69
  32. package/lib/Signal/Group/sender-key-name.d.ts +0 -17
  33. package/lib/Signal/Group/sender-key-name.js +0 -51
  34. package/lib/Signal/Group/sender-key-record.d.ts +0 -30
  35. package/lib/Signal/Group/sender-key-record.js +0 -53
  36. package/lib/Signal/Group/sender-key-state.d.ts +0 -38
  37. package/lib/Signal/Group/sender-key-state.js +0 -99
  38. package/lib/Signal/Group/sender-message-key.d.ts +0 -11
  39. package/lib/Signal/Group/sender-message-key.js +0 -29
  40. package/lib/Signal/libsignal.d.ts +0 -3
  41. package/lib/Signal/libsignal.js +0 -174
  42. package/lib/Socket/Client/abstract-socket-client.d.ts +0 -17
  43. package/lib/Socket/Client/abstract-socket-client.js +0 -13
  44. package/lib/Socket/Client/index.d.ts +0 -3
  45. package/lib/Socket/Client/index.js +0 -19
  46. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
  47. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  48. package/lib/Socket/Client/web-socket-client.d.ts +0 -12
  49. package/lib/Socket/Client/web-socket-client.js +0 -62
  50. package/lib/Socket/business.d.ts +0 -171
  51. package/lib/Socket/business.js +0 -260
  52. package/lib/Socket/chats.d.ts +0 -267
  53. package/lib/Socket/chats.js +0 -970
  54. package/lib/Socket/groups.d.ts +0 -115
  55. package/lib/Socket/groups.js +0 -317
  56. package/lib/Socket/index.d.ts +0 -173
  57. package/lib/Socket/index.js +0 -11
  58. package/lib/Socket/manager.d.ts +0 -253
  59. package/lib/Socket/manager.js +0 -480
  60. package/lib/Socket/messages-recv.d.ts +0 -161
  61. package/lib/Socket/messages-recv.js +0 -1110
  62. package/lib/Socket/messages-send.d.ts +0 -149
  63. package/lib/Socket/messages-send.js +0 -909
  64. package/lib/Socket/newsletter.js +0 -357
  65. package/lib/Socket/registration.d.ts +0 -267
  66. package/lib/Socket/registration.js +0 -166
  67. package/lib/Socket/socket.d.ts +0 -43
  68. package/lib/Socket/socket.js +0 -680
  69. package/lib/Socket/usync.d.ts +0 -36
  70. package/lib/Socket/usync.js +0 -70
  71. package/lib/Store/index.d.ts +0 -3
  72. package/lib/Store/index.js +0 -10
  73. package/lib/Store/make-cache-manager-store.d.ts +0 -13
  74. package/lib/Store/make-cache-manager-store.js +0 -83
  75. package/lib/Store/make-in-memory-store.d.ts +0 -118
  76. package/lib/Store/make-in-memory-store.js +0 -427
  77. package/lib/Store/make-ordered-dictionary.d.ts +0 -13
  78. package/lib/Store/make-ordered-dictionary.js +0 -81
  79. package/lib/Store/object-repository.d.ts +0 -10
  80. package/lib/Store/object-repository.js +0 -27
  81. package/lib/Types/Auth.d.ts +0 -110
  82. package/lib/Types/Auth.js +0 -2
  83. package/lib/Types/Call.d.ts +0 -13
  84. package/lib/Types/Call.js +0 -2
  85. package/lib/Types/Chat.d.ts +0 -102
  86. package/lib/Types/Chat.js +0 -4
  87. package/lib/Types/Contact.d.ts +0 -19
  88. package/lib/Types/Contact.js +0 -2
  89. package/lib/Types/Events.d.ts +0 -157
  90. package/lib/Types/Events.js +0 -2
  91. package/lib/Types/GroupMetadata.d.ts +0 -55
  92. package/lib/Types/GroupMetadata.js +0 -2
  93. package/lib/Types/Label.d.ts +0 -35
  94. package/lib/Types/Label.js +0 -27
  95. package/lib/Types/LabelAssociation.d.ts +0 -29
  96. package/lib/Types/LabelAssociation.js +0 -9
  97. package/lib/Types/Message.d.ts +0 -273
  98. package/lib/Types/Message.js +0 -9
  99. package/lib/Types/Newsletter.d.ts +0 -103
  100. package/lib/Types/Newsletter.js +0 -38
  101. package/lib/Types/Product.d.ts +0 -78
  102. package/lib/Types/Product.js +0 -2
  103. package/lib/Types/Signal.d.ts +0 -57
  104. package/lib/Types/Signal.js +0 -2
  105. package/lib/Types/Socket.d.ts +0 -111
  106. package/lib/Types/Socket.js +0 -2
  107. package/lib/Types/State.d.ts +0 -27
  108. package/lib/Types/State.js +0 -2
  109. package/lib/Types/USync.d.ts +0 -25
  110. package/lib/Types/USync.js +0 -2
  111. package/lib/Types/index.d.ts +0 -57
  112. package/lib/Types/index.js +0 -42
  113. package/lib/Utils/auth-utils.d.ts +0 -18
  114. package/lib/Utils/auth-utils.js +0 -206
  115. package/lib/Utils/baileys-event-stream.d.ts +0 -16
  116. package/lib/Utils/baileys-event-stream.js +0 -63
  117. package/lib/Utils/business.d.ts +0 -22
  118. package/lib/Utils/business.js +0 -234
  119. package/lib/Utils/chat-utils.d.ts +0 -71
  120. package/lib/Utils/chat-utils.js +0 -729
  121. package/lib/Utils/crypto.d.ts +0 -41
  122. package/lib/Utils/crypto.js +0 -151
  123. package/lib/Utils/decode-wa-message.d.ts +0 -19
  124. package/lib/Utils/decode-wa-message.js +0 -198
  125. package/lib/Utils/event-buffer.d.ts +0 -35
  126. package/lib/Utils/event-buffer.js +0 -514
  127. package/lib/Utils/generics.d.ts +0 -92
  128. package/lib/Utils/generics.js +0 -428
  129. package/lib/Utils/history.d.ts +0 -15
  130. package/lib/Utils/history.js +0 -96
  131. package/lib/Utils/index.d.ts +0 -17
  132. package/lib/Utils/index.js +0 -33
  133. package/lib/Utils/link-preview.d.ts +0 -21
  134. package/lib/Utils/link-preview.js +0 -93
  135. package/lib/Utils/logger.d.ts +0 -4
  136. package/lib/Utils/logger.js +0 -7
  137. package/lib/Utils/lt-hash.d.ts +0 -12
  138. package/lib/Utils/lt-hash.js +0 -51
  139. package/lib/Utils/make-mutex.d.ts +0 -7
  140. package/lib/Utils/make-mutex.js +0 -43
  141. package/lib/Utils/messages-media.d.ts +0 -116
  142. package/lib/Utils/messages-media.js +0 -819
  143. package/lib/Utils/messages.d.ts +0 -77
  144. package/lib/Utils/messages.js +0 -816
  145. package/lib/Utils/noise-handler.d.ts +0 -21
  146. package/lib/Utils/noise-handler.js +0 -155
  147. package/lib/Utils/process-message.d.ts +0 -41
  148. package/lib/Utils/process-message.js +0 -321
  149. package/lib/Utils/signal.d.ts +0 -32
  150. package/lib/Utils/signal.js +0 -153
  151. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
  152. package/lib/Utils/use-multi-file-auth-state.js +0 -119
  153. package/lib/Utils/validate-connection.d.ts +0 -11
  154. package/lib/Utils/validate-connection.js +0 -231
  155. package/lib/WABinary/constants.d.ts +0 -30
  156. package/lib/WABinary/constants.js +0 -40
  157. package/lib/WABinary/decode.d.ts +0 -7
  158. package/lib/WABinary/decode.js +0 -252
  159. package/lib/WABinary/encode.d.ts +0 -3
  160. package/lib/WABinary/encode.js +0 -265
  161. package/lib/WABinary/generic-utils.d.ts +0 -17
  162. package/lib/WABinary/generic-utils.js +0 -198
  163. package/lib/WABinary/index.d.ts +0 -5
  164. package/lib/WABinary/index.js +0 -21
  165. package/lib/WABinary/jid-utils.d.ts +0 -31
  166. package/lib/WABinary/jid-utils.js +0 -62
  167. package/lib/WABinary/types.d.ts +0 -18
  168. package/lib/WABinary/types.js +0 -2
  169. package/lib/WAM/BinaryInfo.d.ts +0 -17
  170. package/lib/WAM/BinaryInfo.js +0 -13
  171. package/lib/WAM/constants.d.ts +0 -38
  172. package/lib/WAM/constants.js +0 -15350
  173. package/lib/WAM/encode.d.ts +0 -3
  174. package/lib/WAM/encode.js +0 -155
  175. package/lib/WAM/index.d.ts +0 -3
  176. package/lib/WAM/index.js +0 -19
  177. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
  178. package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -32
  179. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
  180. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -57
  181. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
  182. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -30
  183. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
  184. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -42
  185. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -25
  186. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -53
  187. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -8
  188. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -24
  189. package/lib/WAUSync/Protocols/index.d.ts +0 -4
  190. package/lib/WAUSync/Protocols/index.js +0 -20
  191. package/lib/WAUSync/USyncQuery.d.ts +0 -28
  192. package/lib/WAUSync/USyncQuery.js +0 -89
  193. package/lib/WAUSync/USyncUser.d.ts +0 -12
  194. package/lib/WAUSync/USyncUser.js +0 -26
  195. package/lib/WAUSync/index.d.ts +0 -3
  196. package/lib/WAUSync/index.js +0 -19
  197. package/lib/baileys.d.ts +0 -68
  198. package/lib/baileys.js +0 -266
  199. package/lib/extra/loader.d.ts +0 -16
  200. package/lib/extra/loader.js +0 -37
  201. package/lib/extra/raw.d.ts +0 -43
  202. package/lib/extra/raw.js +0 -131
  203. package/lib/index.d.ts +0 -14
  204. package/require.js +0 -13
@@ -1,12 +0,0 @@
1
- export declare class USyncUser {
2
- id: string;
3
- lid: string;
4
- phone: string;
5
- type: string;
6
- personaId: string;
7
- withId(id: string): this;
8
- withLid(lid: string): this;
9
- withPhone(phone: string): this;
10
- withType(type: string): this;
11
- withPersonaId(personaId: string): this;
12
- }
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.USyncUser = void 0;
4
- class USyncUser {
5
- withId(id) {
6
- this.id = id;
7
- return this;
8
- }
9
- withLid(lid) {
10
- this.lid = lid;
11
- return this;
12
- }
13
- withPhone(phone) {
14
- this.phone = phone;
15
- return this;
16
- }
17
- withType(type) {
18
- this.type = type;
19
- return this;
20
- }
21
- withPersonaId(personaId) {
22
- this.personaId = personaId;
23
- return this;
24
- }
25
- }
26
- exports.USyncUser = USyncUser;
@@ -1,3 +0,0 @@
1
- export * from './Protocols';
2
- export * from './USyncQuery';
3
- export * from './USyncUser';
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./Protocols"), exports);
18
- __exportStar(require("./USyncQuery"), exports);
19
- __exportStar(require("./USyncUser"), exports);
package/lib/baileys.d.ts DELETED
@@ -1,68 +0,0 @@
1
- /// <reference types="node" />
2
- import { EventEmitter } from 'events'
3
-
4
- export interface SerializedQuoted {
5
- mtype: string
6
- text: string
7
- sender: string
8
- id?: string
9
- fromMe?: boolean
10
- mentionedJid?: string[]
11
- raw?: any
12
- download?: () => Promise<Buffer>
13
- }
14
-
15
- export interface SerializedMessage {
16
- id?: string
17
- chat: string
18
- sender: string
19
- fromMe: boolean
20
- isGroup: boolean
21
-
22
- mtype: string
23
- text: string
24
- mentionedJid?: string[]
25
-
26
- quoted?: SerializedQuoted | null
27
-
28
- download?: () => Promise<Buffer>
29
- reply: (text: string, options?: any) => Promise<any>
30
-
31
- msg: any
32
- message: any
33
- key: any
34
- }
35
-
36
- export interface MessageContext {
37
- m: SerializedMessage
38
- sock: any
39
- }
40
-
41
- export interface BaileysOptions {
42
- number?: string
43
- sessionPath?: string
44
- reconnectDelay?: number
45
- pairingDelay?: number
46
- extra?:
47
- | string
48
- | string[]
49
- | ((sock: any) => void)
50
- | Array<(sock: any) => void>
51
- }
52
-
53
- declare class Baileys extends EventEmitter {
54
- constructor(options?: BaileysOptions)
55
-
56
- on(event: 'message', listener: (ctx: MessageContext) => any): this
57
- on(event: 'connect', listener: (ctx: any) => any): this
58
- on(event: 'presence.update', listener: (ctx: any) => any): this
59
- on(event: 'call', listener: (ctx: any) => any): this
60
- on(event: 'group.add', listener: (ctx: any) => any): this
61
- on(event: 'group.remove', listener: (ctx: any) => any): this
62
- on(event: 'group.promote', listener: (ctx: any) => any): this
63
- on(event: 'group.demote', listener: (ctx: any) => any): this
64
- on(event: 'connection.update', listener: (ctx: any) => any): this
65
- on(event: 'error', listener: (ctx: { error: any }) => any): this
66
- }
67
-
68
- export = Baileys
package/lib/baileys.js DELETED
@@ -1,266 +0,0 @@
1
- 'use strict'
2
-
3
- const makeWASocket = require("./Socket").default || require("./Socket")
4
- const {
5
- useMultiFileAuthState
6
- } = require('./Utils/use-multi-file-auth-state')
7
- const chalk = require("chalk");
8
- const {
9
- fetchLatestBaileysVersion
10
- } = require('./Utils/generics')
11
- const {
12
- DisconnectReason
13
- } = require('./Types')
14
- const P = require('pino')
15
- const NodeCache = require('node-cache')
16
- const {
17
- Boom
18
- } = require('@hapi/boom')
19
- const EventEmitter = require('events')
20
- const fs = require('fs')
21
- const {
22
- extra: defaultExtra,
23
- serialize
24
- } = require('./extra/raw')
25
- const {
26
- applyExtras
27
- } = require('./extra/loader')
28
-
29
- class Baileys extends EventEmitter {
30
- constructor(options = {}) {
31
- super()
32
-
33
- this.options = Object.assign({
34
- number: '',
35
- sessionPath: 'sessions',
36
- reconnectDelay: 3000,
37
- pairingDelay: 3500,
38
- extra: []
39
- }, options)
40
-
41
- this.cache = new Map()
42
- this.msgRetry = new NodeCache()
43
- this.sock = null
44
-
45
- this.handlers = {}
46
- this.onceHandlers = {}
47
- this._connecting = false
48
-
49
- this._connect().catch(e => this._emit('error', {
50
- error: e
51
- }))
52
- }
53
-
54
- register(event, fn) {
55
- if (!this.handlers[event]) this.handlers[event] = []
56
- this.handlers[event].push(fn)
57
- }
58
-
59
- once(event, fn) {
60
- this.onceHandlers[event] = fn
61
- }
62
-
63
- async _emit(event, ctx) {
64
- if (this.onceHandlers[event]) {
65
- try {
66
- await this.onceHandlers[event](ctx)
67
- } catch {}
68
- delete this.onceHandlers[event]
69
- }
70
-
71
- if (this.handlers[event]) {
72
- for (const fn of this.handlers[event]) {
73
- try {
74
- await fn(ctx)
75
- } catch {}
76
- }
77
- }
78
-
79
- super.emit(event, ctx)
80
- }
81
-
82
- async _connect() {
83
- if (this._connecting) return
84
- this._connecting = true
85
-
86
- if (!fs.existsSync(this.options.sessionPath)) {
87
- fs.mkdirSync(this.options.sessionPath, {
88
- recursive: true
89
- })
90
- }
91
-
92
- const {
93
- state,
94
- saveCreds
95
- } =
96
- await useMultiFileAuthState(this.options.sessionPath)
97
-
98
- const {
99
- version
100
- } = await fetchLatestBaileysVersion()
101
-
102
- const sock = makeWASocket({
103
- logger: P({
104
- level: 'silent'
105
- }),
106
- version,
107
- auth: state,
108
- browser: ["Linux", "Chrome", "20.0.00"],
109
- printQRInTerminal: !this.options.number,
110
- msgRetryCounterCache: this.msgRetry,
111
- syncFullHistory: true,
112
- markOnlineOnConnect: true
113
- })
114
-
115
- this.sock = sock
116
- defaultExtra(sock)
117
- applyExtras(sock, this.options.extra)
118
- sock.ev.on('creds.update', saveCreds)
119
-
120
- if (!sock.authState.creds.registered && this.options.number) {
121
- const phone = String(this.options.number).replace(/\D/g, '')
122
- setTimeout(async () => {
123
- try {
124
- const raw = await sock.requestPairingCode(phone)
125
- const code = raw?.match(/.{1,4}/g)?.join('-') || raw
126
- console.log(chalk.black(chalk.bgGreen(`Your Pairing Code : `)), chalk.black(chalk.white(code)))
127
- } catch (err) {
128
- this._emit('error', {
129
- error: err
130
- })
131
- }
132
- }, this.options.pairingDelay)
133
- }
134
-
135
- sock.ev.on('messages.upsert', async upsert => {
136
- try {
137
- if (upsert.type !== 'notify') return
138
-
139
- const m = serialize(sock, upsert)
140
- if (!m) return
141
- if (m.chat === 'status@broadcast') return
142
- if (m.fromMe) return
143
-
144
- const body = typeof m.text === 'string' ? m.text.trim() : ''
145
- if (!body) return
146
-
147
- const prefixes = ['.', '!', '#']
148
- const prefix = prefixes.find(p => body.startsWith(p)) || ''
149
-
150
- let command = ''
151
- let args = []
152
- let text = ''
153
-
154
- if (prefix) {
155
- const withoutPrefix = body.slice(prefix.length).trim()
156
- const split = withoutPrefix.split(/\s+/)
157
-
158
- command = split.shift()?.toLowerCase() || ''
159
- args = split
160
- text = args.join(' ')
161
- }
162
-
163
- await this._emit('message', {
164
- m,
165
- sock,
166
- body,
167
- prefix,
168
- command,
169
- args,
170
- text
171
- })
172
- } catch (e) {
173
- this._emit('error', { error: e })
174
- }
175
- })
176
- >
177
- sock.ev.on('presence.update', update => {
178
- this._emit('presence.update', {
179
- id: update.id,
180
- presences: update.presences || {}
181
- })
182
- })
183
-
184
- const callSeen = new Set()
185
- sock.ev.on('call', calls => {
186
- const c = Array.isArray(calls) ? calls[0] : calls
187
- if (!c) return
188
-
189
- if (['reject', 'ended', 'timeout'].includes(c.status)) {
190
- callSeen.delete(c.from)
191
- }
192
-
193
- if (callSeen.has(c.from) && c.status === 'ringing') return
194
- callSeen.add(c.from)
195
-
196
- this._emit('call', {
197
- sock: this.sock,
198
- ...c
199
- })
200
- })
201
- sock.ev.on('group-participants.update', data => {
202
- const ctx = {
203
- sock: this.sock,
204
- id: data.id,
205
- from: data.id,
206
- participants: data.participants,
207
- action: data.action
208
- }
209
-
210
- this._emit('group.participant', ctx)
211
-
212
- if (data.action === 'add') this._emit('group.add', ctx)
213
- if (data.action === 'remove') this._emit('group.remove', ctx)
214
- if (data.action === 'promote') this._emit('group.promote', ctx)
215
- if (data.action === 'demote') this._emit('group.demote', ctx)
216
- })
217
-
218
- sock.ev.on('connection.update', (update) => {
219
- const { connection, lastDisconnect } = update
220
-
221
- if (connection === 'open') {
222
- this._connecting = false
223
-
224
- this._emit('connect', {
225
- sock: this.sock,
226
- user: sock.user,
227
- jid: sock.decodeJid(sock.user?.id || '')
228
- })
229
-
230
- console.log(
231
- chalk.bgGreen.black(' CONNECTED '),
232
- chalk.white(
233
- sock.user?.name ||
234
- sock.decodeJid(sock.user?.id || '')
235
- )
236
- )
237
- return
238
- }
239
-
240
- if (connection === 'close') {
241
- const code = new Boom(lastDisconnect?.error)?.output?.statusCode
242
-
243
- this._emit('error', {
244
- type: 'connection',
245
- code,
246
- error: lastDisconnect?.error
247
- })
248
-
249
- if (code === DisconnectReason.loggedOut) {
250
- process.exit(0)
251
- }
252
-
253
- setTimeout(() => {
254
- this._connecting = false
255
- this._connect()
256
- }, this.options.reconnectDelay)
257
- }
258
- })
259
- }
260
- }
261
-
262
- module.exports = Baileys
263
- module.exports.default = Baileys
264
- Object.defineProperty(module.exports, '__esModule', {
265
- value: true
266
- })
@@ -1,16 +0,0 @@
1
- /// <reference types="node" />
2
-
3
- export type ExtraFunction = (sock: any) => void
4
-
5
- /**
6
- * Apply user-defined extras to socket
7
- */
8
- export function applyExtras(
9
- sock: any,
10
- extra?:
11
- | string
12
- | string[]
13
- | ExtraFunction
14
- | ExtraFunction[],
15
- baseDir?: string
16
- ): void
@@ -1,37 +0,0 @@
1
- 'use strict'
2
-
3
- const path = require('path')
4
-
5
- function normalizeExtras(extra) {
6
- if (!extra) return []
7
- if (typeof extra === 'function') return [extra]
8
- if (typeof extra === 'string') return [extra]
9
- if (Array.isArray(extra)) return extra
10
- throw new TypeError('extra must be function | string | array')
11
- }
12
-
13
- function loadExtra(item, baseDir) {
14
- if (typeof item === 'function') return item
15
- if (typeof item === 'string') {
16
- const file = path.isAbsolute(item)
17
- ? item
18
- : path.join(baseDir, item)
19
- const fn = require(file)
20
- if (typeof fn !== 'function')
21
- throw new TypeError(`Extra file must export a function: ${item}`)
22
- return fn
23
- }
24
- return null
25
- }
26
-
27
- exports.applyExtras = (sock, extra, baseDir = process.cwd()) => {
28
- const list = normalizeExtras(extra)
29
- for (const item of list) {
30
- try {
31
- const fn = loadExtra(item, baseDir)
32
- fn && fn(sock)
33
- } catch (e) {
34
- console.error('[EXTRA ERROR]', e)
35
- }
36
- }
37
- }
@@ -1,43 +0,0 @@
1
- /// <reference types="node" />
2
-
3
- export interface SerializedQuoted {
4
- mtype: string
5
- text: string
6
- sender: string
7
- id?: string
8
- fromMe?: boolean
9
- mentionedJid?: string[]
10
- raw?: any
11
- download?: () => Promise<Buffer>
12
- }
13
-
14
- export interface SerializedMessage {
15
- id?: string
16
- chat: string
17
- sender: string
18
- fromMe: boolean
19
- isGroup: boolean
20
-
21
- mtype: string
22
- text: string
23
- mentionedJid?: string[]
24
-
25
- quoted?: SerializedQuoted | null
26
-
27
- download?: () => Promise<Buffer>
28
- reply: (text: string, options?: any) => Promise<any>
29
-
30
- msg: any
31
- message: any
32
- key: any
33
- }
34
-
35
- /**
36
- * Default extra injected by framework
37
- */
38
- export function extra(sock: any): void
39
-
40
- /**
41
- * Serialize Baileys message or upsert into friendly message
42
- */
43
- export function serialize(sock: any, upsert: any): SerializedMessage | null
package/lib/extra/raw.js DELETED
@@ -1,131 +0,0 @@
1
- 'use strict'
2
-
3
- const { jidNormalizedUser, jidDecode, areJidsSameUser } = require('../WABinary')
4
- const { downloadContentFromMessage } = require('../Utils')
5
-
6
- exports.extra = (sock) => {
7
- sock.decodeJid = (jid) => {
8
- if (!jid) return jid;
9
- if (/:\d+@/gi.test(jid)) {
10
- const decode = jidDecode(jid) || {};
11
- return (
12
- (decode.user && decode.server && decode.user + "@" + decode.server) ||
13
- jid
14
- );
15
- } else return jid;
16
- };
17
- sock.downloadM = async (m, type) => {
18
- if (!m || !(m.url || m.directPath)) return Buffer.alloc(0)
19
- const stream = await downloadContentFromMessage(m, type)
20
- let buffer = Buffer.alloc(0)
21
- for await (const chunk of stream) {
22
- buffer = Buffer.concat([buffer, chunk])
23
- }
24
- return buffer
25
- }
26
- }
27
-
28
- exports.serialize = (sock, upsert) => {
29
- if (!upsert) return null
30
-
31
- let m = upsert.messages?.[0] || upsert
32
- if (!m || typeof m !== 'object') return null
33
- if (!m.key || !m.message) return null
34
-
35
- /* ================= BASIC ================= */
36
- m.id = m.key.id
37
- m.chat = jidNormalizedUser(m.key.remoteJid)
38
- m.isGroup = m.chat.endsWith('@g.us')
39
- m.sender = sock.decodeJid(
40
- (m.key.fromMe && sock.user?.id) ||
41
- m.key.participant ||
42
- m.chat
43
- )
44
- m.fromMe = m.key.fromMe || areJidsSameUser(m.sender, sock.user?.id)
45
-
46
- /* ================= MESSAGE TYPE ================= */
47
- const keys = Object.keys(m.message)
48
- m.mtype = keys.find(k => k !== 'messageContextInfo') || keys[0]
49
- m.msg = m.message[m.mtype]
50
-
51
- /* ================= TEXT ================= */
52
- m.text =
53
- (m.mtype === 'conversation'
54
- ? m.message.conversation
55
- : m.mtype === 'imageMessage'
56
- ? m.message.imageMessage.caption
57
- : m.mtype === 'videoMessage'
58
- ? m.message.videoMessage.caption
59
- : m.mtype === 'extendedTextMessage'
60
- ? m.message.extendedTextMessage.text
61
- : m.mtype === 'buttonsResponseMessage'
62
- ? m.message.buttonsResponseMessage.selectedButtonId
63
- : m.mtype === 'listResponseMessage'
64
- ? m.message.listResponseMessage.singleSelectReply.selectedRowId
65
- : m.mtype === 'templateButtonReplyMessage'
66
- ? m.message.templateButtonReplyMessage.selectedId
67
- : ''
68
- ) || ''
69
-
70
- /* ================= CONTEXT ================= */
71
- const context = m.msg?.contextInfo || {}
72
- m.mentionedJid = context.mentionedJid || []
73
-
74
- /* ================= QUOTED ================= */
75
- m.quoted = null
76
- if (context.quotedMessage) {
77
- const qmsg = context.quotedMessage
78
- const qtype = Object.keys(qmsg)[0]
79
- let quoted = qmsg[qtype]
80
-
81
- // handle special wrapper
82
- if (['productMessage', 'documentWithCaptionMessage'].includes(qtype)) {
83
- const innerKey = Object.keys(quoted.message || quoted)[0]
84
- quoted = quoted.message ? quoted.message[innerKey] : quoted[innerKey]
85
- }
86
-
87
- if (typeof quoted === 'string') quoted = { text: quoted }
88
-
89
- m.quoted = {
90
- mtype: qtype,
91
- id: context.stanzaId,
92
- chat: m.chat,
93
- sender: sock.decodeJid(context.participant),
94
- fromMe: sock.decodeJid(context.participant) === sock.user?.id,
95
- text:
96
- quoted.text ||
97
- quoted.caption ||
98
- quoted.contentText ||
99
- quoted.conversation ||
100
- '',
101
- mentionedJid: quoted.contextInfo?.mentionedJid || [],
102
- raw: quoted
103
- }
104
-
105
- if (quoted.url || quoted.directPath) {
106
- m.quoted.download = (save = false) =>
107
- sock.downloadM(quoted, qtype.replace(/message/i, ''), save)
108
- }
109
- }
110
-
111
- /* ================= DOWNLOAD ================= */
112
- if (m.msg?.url || m.msg?.directPath) {
113
- m.download = (save = false) =>
114
- sock.downloadM(m.msg, m.mtype.replace(/message/i, ''), save)
115
- }
116
-
117
- /* ================= REPLY ================= */
118
- m.reply = async (text, opt = {}) => {
119
- return sock.sendMessage(
120
- m.chat,
121
- {
122
- text,
123
- mentions: sock.parseMention(text),
124
- ...opt
125
- },
126
- { quoted: m }
127
- )
128
- }
129
-
130
- return m
131
- }
package/lib/index.d.ts DELETED
@@ -1,14 +0,0 @@
1
- import makeWASocket from './Socket';
2
- export * from '../WAProto';
3
- export * from './Utils';
4
- export * from './Types';
5
- export * from './Store';
6
- export * from './Defaults';
7
- export * from './WABinary';
8
- export * from './WAM';
9
- export * from './WAUSync';
10
- export type WASocket = ReturnType<typeof makeWASocket>;
11
- import { Baileys } from "./baileys"
12
- export { Baileys };
13
- export { makeWASocket };
14
- export default makeWASocket;
package/require.js DELETED
@@ -1,13 +0,0 @@
1
- const chalk = require("chalk");
2
-
3
- const major = parseInt(process.versions.node.split('.')[0], 10);
4
-
5
- if (major < 20) {
6
- console.log(
7
- chalk.redBright("✖ Node.js version too low.") + "\n" +
8
- chalk.white(` Required : `) + chalk.green("Node.js 20+") + "\n" +
9
- chalk.white(` Current : `) + chalk.yellow(process.versions.node) + "\n" +
10
- chalk.white(" Please upgrade Node.js to continue.\n")
11
- );
12
- process.exit(1);
13
- }