@hansaka02/baileys 7.3.2 → 7.3.4

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 (202) hide show
  1. package/README.md +247 -203
  2. package/lib/Defaults/connection.js +51 -0
  3. package/lib/Defaults/constants.js +62 -0
  4. package/lib/Defaults/history.js +17 -0
  5. package/lib/Defaults/index.js +36 -142
  6. package/lib/Defaults/media.js +48 -0
  7. package/lib/Defaults/prefix.js +18 -0
  8. package/lib/Signal/Group/group-session-builder.js +10 -42
  9. package/lib/Signal/Group/group_cipher.js +9 -6
  10. package/lib/Signal/Group/index.js +39 -53
  11. package/lib/Signal/Group/keyhelper.js +8 -41
  12. package/lib/Signal/Group/sender-chain-key.js +4 -4
  13. package/lib/Signal/Group/sender-key-distribution-message.js +5 -5
  14. package/lib/Signal/Group/sender-key-message.js +12 -8
  15. package/lib/Signal/Group/sender-key-record.js +7 -7
  16. package/lib/Signal/Group/sender-key-state.js +4 -4
  17. package/lib/Signal/Group/sender-message-key.js +2 -2
  18. package/lib/Signal/libsignal.js +45 -69
  19. package/lib/Signal/lid-mapping.js +15 -11
  20. package/lib/Socket/Client/types.js +2 -2
  21. package/lib/Socket/Client/websocket.js +16 -14
  22. package/lib/Socket/business.js +41 -32
  23. package/lib/Socket/chats.js +123 -98
  24. package/lib/Socket/community.js +50 -40
  25. package/lib/Socket/groups.js +59 -47
  26. package/lib/Socket/index.js +4 -4
  27. package/lib/Socket/messages-recv.js +219 -172
  28. package/lib/Socket/messages-send.js +187 -143
  29. package/lib/Socket/newsletter.js +61 -47
  30. package/lib/Socket/socket.js +133 -90
  31. package/lib/Socket/usync.js +6 -6
  32. package/lib/Store/index.js +27 -11
  33. package/lib/Store/make-cache-manager-store.js +14 -15
  34. package/lib/Store/make-in-memory-store.js +28 -24
  35. package/lib/Types/LabelAssociation.js +2 -2
  36. package/lib/Types/Message.js +6 -6
  37. package/lib/Types/MexUpdates.js +5 -5
  38. package/lib/Types/State.js +4 -4
  39. package/lib/Types/index.js +28 -12
  40. package/lib/Utils/auth-utils.js +28 -26
  41. package/lib/Utils/baileys-event-stream.js +68 -69
  42. package/lib/Utils/business.js +63 -53
  43. package/lib/Utils/chat-utils.js +81 -71
  44. package/lib/Utils/crypto.js +25 -45
  45. package/lib/Utils/decode-wa-message.js +319 -311
  46. package/lib/Utils/event-buffer.js +21 -22
  47. package/lib/Utils/generics.js +65 -82
  48. package/lib/Utils/history.js +21 -21
  49. package/lib/Utils/index.js +27 -13
  50. package/lib/Utils/link-preview.js +7 -30
  51. package/lib/Utils/logger.js +5 -5
  52. package/lib/Utils/lt-hash.js +3 -3
  53. package/lib/Utils/message-retry-manager.js +4 -4
  54. package/lib/Utils/messages-media.js +104 -109
  55. package/lib/Utils/messages.js +203 -171
  56. package/lib/Utils/noise-handler.js +28 -19
  57. package/lib/Utils/process-message.js +111 -96
  58. package/lib/Utils/signal.js +36 -25
  59. package/lib/Utils/use-multi-file-auth-state.js +18 -22
  60. package/lib/Utils/validate-connection.js +52 -45
  61. package/lib/WABinary/decode.js +6 -32
  62. package/lib/WABinary/encode.js +3 -29
  63. package/lib/WABinary/generic-utils.js +4 -4
  64. package/lib/WABinary/index.js +27 -11
  65. package/lib/WAM/encode.js +16 -8
  66. package/lib/WAM/index.js +27 -11
  67. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +20 -16
  68. package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
  69. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +7 -4
  70. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
  71. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -2
  72. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -2
  73. package/lib/WAUSync/Protocols/index.js +27 -11
  74. package/lib/WAUSync/USyncQuery.js +17 -10
  75. package/lib/WAUSync/index.js +27 -11
  76. package/lib/index.js +60 -31
  77. package/package.json +8 -14
  78. package/WAProto/AICommon/AICommon.d.ts +0 -11702
  79. package/WAProto/Adv/Adv.d.ts +0 -643
  80. package/WAProto/BotMetadata/BotMetadata.d.ts +0 -5654
  81. package/WAProto/Cert/Cert.d.ts +0 -613
  82. package/WAProto/ChatLockSettings/ChatLockSettings.d.ts +0 -476
  83. package/WAProto/CompanionReg/CompanionReg.d.ts +0 -1361
  84. package/WAProto/DeviceCapabilities/DeviceCapabilities.d.ts +0 -577
  85. package/WAProto/E2E/E2E.d.ts +0 -41724
  86. package/WAProto/Ephemeral/Ephemeral.d.ts +0 -114
  87. package/WAProto/HistorySync/HistorySync.d.ts +0 -51700
  88. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.d.ts +0 -229
  89. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.d.ts +0 -583
  90. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +0 -42897
  91. package/WAProto/MmsRetry/MmsRetry.d.ts +0 -243
  92. package/WAProto/Protocol/Protocol.d.ts +0 -270
  93. package/WAProto/Reporting/Reporting.d.ts +0 -371
  94. package/WAProto/ServerSync/ServerSync.d.ts +0 -1285
  95. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.d.ts +0 -1868
  96. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.d.ts +0 -767
  97. package/WAProto/StatusAttributions/StatusAttributions.d.ts +0 -1027
  98. package/WAProto/SyncAction/SyncAction.d.ts +0 -11193
  99. package/WAProto/UserPassword/UserPassword.d.ts +0 -363
  100. package/WAProto/VnameCert/VnameCert.d.ts +0 -821
  101. package/WAProto/Wa6/Wa6.d.ts +0 -2128
  102. package/WAProto/Web/Web.d.ts +0 -46383
  103. package/WAProto/index.d.ts +0 -55
  104. package/lib/Defaults/index.d.ts +0 -77
  105. package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
  106. package/lib/Signal/Group/group-session-builder.d.ts +0 -17
  107. package/lib/Signal/Group/group_cipher.d.ts +0 -19
  108. package/lib/Signal/Group/index.d.ts +0 -11
  109. package/lib/Signal/Group/keyhelper.d.ts +0 -16
  110. package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
  111. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
  112. package/lib/Signal/Group/sender-key-message.d.ts +0 -19
  113. package/lib/Signal/Group/sender-key-name.d.ts +0 -19
  114. package/lib/Signal/Group/sender-key-record.d.ts +0 -32
  115. package/lib/Signal/Group/sender-key-state.d.ts +0 -44
  116. package/lib/Signal/Group/sender-message-key.d.ts +0 -11
  117. package/lib/Signal/libsignal.d.ts +0 -8
  118. package/lib/Signal/lid-mapping.d.ts +0 -28
  119. package/lib/Socket/Client/index.d.ts +0 -2
  120. package/lib/Socket/Client/types.d.ts +0 -16
  121. package/lib/Socket/Client/websocket.d.ts +0 -13
  122. package/lib/Socket/business.d.ts +0 -187
  123. package/lib/Socket/chats.d.ts +0 -97
  124. package/lib/Socket/community.d.ts +0 -129
  125. package/lib/Socket/groups.d.ts +0 -129
  126. package/lib/Socket/index.d.ts +0 -191
  127. package/lib/Socket/messages-recv.d.ts +0 -174
  128. package/lib/Socket/messages-send.d.ts +0 -165
  129. package/lib/Socket/newsletter.d.ts +0 -145
  130. package/lib/Socket/socket.d.ts +0 -45
  131. package/lib/Socket/usync.d.ts +0 -37
  132. package/lib/Store/index.d.ts +0 -4
  133. package/lib/Store/make-cache-manager-store.d.ts +0 -14
  134. package/lib/Store/make-in-memory-store.d.ts +0 -123
  135. package/lib/Store/make-ordered-dictionary.d.ts +0 -12
  136. package/lib/Store/object-repository.d.ts +0 -10
  137. package/lib/Types/Auth.d.ts +0 -121
  138. package/lib/Types/Bussiness.d.ts +0 -28
  139. package/lib/Types/Call.d.ts +0 -14
  140. package/lib/Types/Chat.d.ts +0 -143
  141. package/lib/Types/Contact.d.ts +0 -23
  142. package/lib/Types/Events.d.ts +0 -226
  143. package/lib/Types/GroupMetadata.d.ts +0 -66
  144. package/lib/Types/Label.d.ts +0 -48
  145. package/lib/Types/LabelAssociation.d.ts +0 -35
  146. package/lib/Types/Message.d.ts +0 -484
  147. package/lib/Types/MexUpdates.d.ts +0 -9
  148. package/lib/Types/Newsletter.d.ts +0 -109
  149. package/lib/Types/Product.d.ts +0 -92
  150. package/lib/Types/Signal.d.ts +0 -98
  151. package/lib/Types/Socket.d.ts +0 -141
  152. package/lib/Types/State.d.ts +0 -41
  153. package/lib/Types/USync.d.ts +0 -26
  154. package/lib/Types/index.d.ts +0 -80
  155. package/lib/Utils/auth-utils.d.ts +0 -21
  156. package/lib/Utils/baileys-event-stream.d.ts +0 -18
  157. package/lib/Utils/business.d.ts +0 -29
  158. package/lib/Utils/chat-utils.d.ts +0 -82
  159. package/lib/Utils/crypto.d.ts +0 -56
  160. package/lib/Utils/decode-wa-message.d.ts +0 -53
  161. package/lib/Utils/event-buffer.d.ts +0 -39
  162. package/lib/Utils/generics.d.ts +0 -117
  163. package/lib/Utils/history.d.ts +0 -23
  164. package/lib/Utils/index.d.ts +0 -20
  165. package/lib/Utils/link-preview.d.ts +0 -23
  166. package/lib/Utils/logger.d.ts +0 -13
  167. package/lib/Utils/lt-hash.d.ts +0 -14
  168. package/lib/Utils/make-mutex.d.ts +0 -9
  169. package/lib/Utils/message-retry-manager.d.ts +0 -88
  170. package/lib/Utils/messages-media.d.ts +0 -135
  171. package/lib/Utils/messages.d.ts +0 -105
  172. package/lib/Utils/noise-handler.d.ts +0 -20
  173. package/lib/Utils/process-message.d.ts +0 -49
  174. package/lib/Utils/signal.d.ts +0 -42
  175. package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
  176. package/lib/Utils/use-mongo-file-auth-state.js +0 -84
  177. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
  178. package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
  179. package/lib/Utils/use-single-file-auth-state.js +0 -80
  180. package/lib/Utils/validate-connection.d.ts +0 -13
  181. package/lib/WABinary/constants.d.ts +0 -30
  182. package/lib/WABinary/decode.d.ts +0 -9
  183. package/lib/WABinary/encode.d.ts +0 -3
  184. package/lib/WABinary/generic-utils.d.ts +0 -28
  185. package/lib/WABinary/index.d.ts +0 -5
  186. package/lib/WABinary/jid-utils.d.ts +0 -58
  187. package/lib/WABinary/types.d.ts +0 -22
  188. package/lib/WAM/BinaryInfo.d.ts +0 -16
  189. package/lib/WAM/constants.d.ts +0 -47
  190. package/lib/WAM/encode.d.ts +0 -3
  191. package/lib/WAM/index.d.ts +0 -3
  192. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +0 -28
  193. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
  194. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -26
  195. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -14
  196. package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +0 -10
  197. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -14
  198. package/lib/WAUSync/Protocols/index.d.ts +0 -6
  199. package/lib/WAUSync/USyncQuery.d.ts +0 -31
  200. package/lib/WAUSync/USyncUser.d.ts +0 -12
  201. package/lib/WAUSync/index.d.ts +0 -3
  202. package/lib/index.d.ts +0 -13
@@ -1,39 +0,0 @@
1
- import { BaileysEventEmitter, BaileysEventMap } from '../Types'
2
- import { ILogger } from './logger'
3
-
4
- /**
5
- * A map that contains a list of all events that have been triggered
6
- *
7
- * Note, this can contain different type of events
8
- * this can make processing events extremely efficient -- since everything
9
- * can be done in a single transaction
10
- */
11
- type BaileysEventData = Partial<BaileysEventMap>
12
-
13
- type BaileysBufferableEventEmitter = BaileysEventEmitter & {
14
- /** Use to process events in a batch */
15
- process(handler: (events: BaileysEventData) => void | Promise<void>): (() => void)
16
- /**
17
- * starts buffering events, call flush() to release them
18
- * */
19
- buffer(): void
20
- /** buffers all events till the promise completes */
21
- createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>)
22
- /**
23
- * flushes all buffered events
24
- * @param force if true, will flush all data regardless of any pending buffers
25
- * @returns returns true if the flush actually happened, otherwise false
26
- */
27
- flush(force?: boolean): boolean
28
- /** is there an ongoing buffer */
29
- isBuffering(): boolean
30
- }
31
-
32
- /**
33
- * The event buffer logically consolidates different events into a single event
34
- * making the data processing more efficient.
35
- * @param ev the baileys event emitter
36
- */
37
- export declare const makeEventBuffer: (logger: ILogger) => BaileysBufferableEventEmitter
38
-
39
- export {}
@@ -1,117 +0,0 @@
1
- import { AxiosRequestConfig } from 'axios'
2
- import { ILogger } from './logger'
3
- import { proto } from '../../WAProto'
4
- import { BaileysEventEmitter, BaileysEventMap, BrowsersMap, ConnectionState, WACallUpdateType, WAVersion } from '../Types'
5
- import { BinaryNode } from '../WABinary'
6
-
7
- export declare const Browsers: BrowsersMap
8
-
9
- export declare const getPlatformId: (browser: string) => any
10
-
11
- export declare const BufferJSON: {
12
- replacer: (k: any, value: any) => any
13
- reviver: (_: any, value: any) => any
14
- }
15
-
16
- export declare const getKeyAuthor: (key: proto.IMessageKey | undefined | null, meId?: string) => string
17
-
18
- export declare const writeRandomPadMax16: (msg: Uint8Array) => Buffer
19
-
20
- export declare const unpadRandomMax16: (e: Uint8Array | Buffer) => Uint8Array
21
-
22
- export declare const encodeWAMessage: (message: proto.IMessage) => Buffer
23
-
24
- export declare const encodeNewsletterMessage: (message: proto.IMessage) => Uint8Array
25
-
26
- export declare const generateRegistrationId: () => number
27
-
28
- export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array
29
-
30
- export declare const toNumber: (t: Long | number | null | undefined) => number
31
-
32
- /** unix timestamp of a date in seconds */
33
- export declare const unixTimestampSeconds: (date?: Date) => number
34
-
35
- export type DebouncedTimeout = ReturnType<typeof debouncedTimeout>
36
-
37
- export declare const debouncedTimeout: (intervalMs?: number, task?: () => void) => {
38
- start: (newIntervalMs?: number, newTask?: () => void) => void
39
- cancel: () => void
40
- setTask: (newTask: () => void) => () => void
41
- setInterval: (newInterval: number) => number
42
- }
43
-
44
- export declare const delay: (ms: number) => Promise<void>
45
-
46
- export declare const delayCancellable: (ms: number) => {
47
- delay: Promise<void>
48
- cancel: () => void
49
- }
50
-
51
- export declare function promiseTimeout<T>(ms: number | undefined, promise: (resolve: (v: T) => void, reject: (error: any) => void) => void): Promise<T>
52
-
53
- export declare const generateMessageID: (userId?: string) => string
54
-
55
- export declare const generateParticipantHashV2: (participants: string[]) => string
56
-
57
- export declare function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: BaileysEventEmitter, event: T): (check: (u: BaileysEventMap[T]) => boolean | undefined, timeoutMs?: number) => Promise<void>
58
-
59
- export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>
60
-
61
- export declare const printQRIfNecessaryListener: (ev: BaileysEventEmitter, logger: ILogger) => void
62
- /**
63
- * utility that fetches latest baileys version from the master branch.
64
- * Use to ensure your WA connection is always on the latest version
65
- */
66
-
67
- export declare const fetchLatestBaileysVersion: (options?: AxiosRequestConfig<{}>) => Promise<{
68
- version: WAVersion
69
- isLatest: boolean
70
- error?: undefined
71
- } | {
72
- version: WAVersion
73
- isLatest: boolean
74
- error: any
75
- }>
76
-
77
- /** unique message tag prefix for MD clients */
78
- export declare const generateMdTagPrefix: () => string
79
- /**
80
- * Given a type of receipt, returns what the new status of the message should be
81
- * @param type type from receipt
82
- */
83
-
84
- export declare const getStatusFromReceiptType: (type: string | undefined) => proto.WebMessageInfo.Status
85
- /**
86
- * Stream errors generally provide a reason, map that to a baileys DisconnectReason
87
- * @param reason the string reason given, eg. "conflict"
88
- */
89
- export declare const getErrorCodeFromStreamError: (node: BinaryNode) => {
90
- reason: string
91
- statusCode: number
92
- }
93
-
94
- export declare const getCallStatusFromNode: ({ tag, attrs }: BinaryNode) => WACallUpdateType
95
-
96
- export declare const getCodeFromWSError: (error: Error) => number
97
- /**
98
- * Is the given platform WA business
99
- * @param platform AuthenticationCreds.platform
100
- */
101
- export declare const isWABusinessPlatform: (platform: string) => boolean
102
-
103
- export declare function trimUndefined(obj: {
104
- [_: string]: any
105
- }): {
106
- [_: string]: any
107
- }
108
-
109
- export declare function bytesToCrockford(buffer: Buffer): string
110
-
111
- export declare function toUnicodeEscape(text: string): string
112
-
113
- export declare function fromUnicodeEscape(escapedText: string): string
114
-
115
- export declare function asciiEncode(text: string): string
116
-
117
- export declare function asciiDecode(...codes: string[]): string[]
@@ -1,23 +0,0 @@
1
- import { AxiosRequestConfig } from 'axios'
2
- import { proto } from '../../WAProto'
3
- import { Chat, Contact } from '../Types'
4
-
5
- export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<{}>) => Promise<proto.HistorySync>
6
-
7
- export declare const processHistoryMessage: (item: proto.IHistorySync) => {
8
- chats: Chat[]
9
- contacts: Contact[]
10
- messages: proto.IWebMessageInfo[]
11
- syncType: proto.HistorySync.HistorySyncType
12
- progress: number | null | undefined
13
- }
14
-
15
- export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<{}>) => Promise<{
16
- chats: Chat[]
17
- contacts: Contact[]
18
- messages: proto.IWebMessageInfo[]
19
- syncType: proto.HistorySync.HistorySyncType
20
- progress: number | null | undefined
21
- }>
22
-
23
- export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification | null | undefined
@@ -1,20 +0,0 @@
1
- export * from './generics'
2
- export * from './decode-wa-message'
3
- export * from './messages'
4
- export * from './messages-media'
5
- export * from './message-retry-manager'
6
- export * from './validate-connection'
7
- export * from './crypto'
8
- export * from './signal'
9
- export * from './noise-handler'
10
- export * from './history'
11
- export * from './chat-utils'
12
- export * from './lt-hash'
13
- export * from './auth-utils'
14
- export * from './baileys-event-stream'
15
- export * from './use-mongo-file-auth-state'
16
- export * from './use-single-file-auth-state'
17
- export * from './use-multi-file-auth-state'
18
- export * from './link-preview'
19
- export * from './event-buffer'
20
- export * from './process-message'
@@ -1,23 +0,0 @@
1
- import { AxiosRequestConfig } from 'axios'
2
- import { WAMediaUploadFunction, WAUrlInfo } from '../Types'
3
- import { ILogger } from './logger'
4
-
5
- export type URLGenerationOptions = {
6
- thumbnailWidth: number
7
- fetchOpts: {
8
- /** Timeout in ms */
9
- timeout: number
10
- proxyUrl?: string
11
- headers?: AxiosRequestConfig<{}>['headers']
12
- }
13
- uploadImage?: WAMediaUploadFunction
14
- logger?: ILogger
15
- }
16
-
17
- /**
18
- * Given a piece of text, checks for any URL present, generates link preview for the same and returns it
19
- * Return undefined if the fetch failed or no URL was found
20
- * @param text first matched URL in text
21
- * @returns the URL info required to generate link preview
22
- */
23
- export declare const getUrlInfo: (text: string, opts?: URLGenerationOptions) => Promise<WAUrlInfo | undefined>
@@ -1,13 +0,0 @@
1
- export interface ILogger {
2
- level: string
3
- child(obj: Record<string, unknown>): ILogger
4
- trace(obj: unknown, msg?: string): any
5
- debug(obj: unknown, msg?: string): any
6
- info(obj: unknown, msg?: string): any
7
- warn(obj: unknown, msg?: string): any
8
- error(obj: unknown, msg?: string): any
9
- }
10
-
11
- declare const _default: import("pino").Logger<never, boolean>
12
-
13
- export default _default
@@ -1,14 +0,0 @@
1
- declare class d {
2
- salt: string
3
- constructor(e: string)
4
- add(e: any, t: any): any
5
- subtract(e: any, t: any): any
6
- subtractThenAdd(e: any, t: any, r: any): any
7
- _addSingle(e: any, t: any): Promise<ArrayBuffer>
8
- _subtractSingle(e: any, t: any): Promise<ArrayBuffer>
9
- performPointwiseWithOverflow(e: any, t: any, r: any): ArrayBuffer
10
- }
11
-
12
- export declare const LT_HASH_ANTI_TAMPERING: d
13
-
14
- export {}
@@ -1,9 +0,0 @@
1
- export declare const makeMutex: () => {
2
- mutex<T>(code: () => T | Promise<T>): Promise<T>
3
- }
4
-
5
- export type Mutex = ReturnType<typeof makeMutex>
6
-
7
- export declare const makeKeyedMutex: () => {
8
- mutex<T>(key: string, task: () => T | Promise<T>): Promise<T>
9
- }
@@ -1,88 +0,0 @@
1
- import { proto } from '../../WAProto'
2
- import { ILogger } from './logger'
3
-
4
- export interface RecentMessageKey {
5
- to: string
6
- id: string
7
- }
8
-
9
- export interface RecentMessage {
10
- message: proto.IMessage
11
- timestamp: number
12
- }
13
-
14
- export interface SessionRecreateHistory {
15
- [jid: string]: number
16
- }
17
-
18
- export interface RetryCounter {
19
- [messageId: string]: number
20
- }
21
-
22
- export interface PendingPhoneRequest {
23
- [messageId: string]: NodeJS.Timeout
24
- }
25
-
26
- export interface RetryStatistics {
27
- totalRetries: number
28
- successfulRetries: number
29
- failedRetries: number
30
- mediaRetries: number
31
- sessionRecreations: number
32
- phoneRequests: number
33
- }
34
-
35
- export declare class MessageRetryManager {
36
- private logger
37
- private recentMessagesMap
38
- private sessionRecreateHistory
39
- private retryCounters
40
- private pendingPhoneRequests
41
- private readonly maxMsgRetryCount
42
- private statistics
43
- constructor(logger: ILogger, maxMsgRetryCount: number)
44
- /**
45
- * Add a recent message to the cache for retry handling
46
- */
47
- addRecentMessage(to: string, id: string, message: proto.IMessage): void
48
- /**
49
- * Get a recent message from the cache
50
- */
51
- getRecentMessage(to: string, id: string): RecentMessage | undefined
52
- /**
53
- * Check if a session should be recreated based on retry count and history
54
- */
55
- shouldRecreateSession(jid: string, retryCount: number, hasSession: boolean): {
56
- reason: string
57
- recreate: boolean
58
- }
59
- /**
60
- * Increment retry counter for a message
61
- */
62
- incrementRetryCount(messageId: string): number
63
- /**
64
- * Get retry count for a message
65
- */
66
- getRetryCount(messageId: string): number
67
- /**
68
- * Check if message has exceeded maximum retry attempts
69
- */
70
- hasExceededMaxRetries(messageId: string): boolean
71
- /**
72
- * Mark retry as successful
73
- */
74
- markRetrySuccess(messageId: string): void
75
- /**
76
- * Mark retry as failed
77
- */
78
- markRetryFailed(messageId: string): void
79
- /**
80
- * Schedule a phone request with delay
81
- */
82
- schedulePhoneRequest(messageId: string, callback: () => void, delay?: number): void
83
- /**
84
- * Cancel pending phone request
85
- */
86
- cancelPendingPhoneRequest(messageId: string): void
87
- private keyToString
88
- }
@@ -1,135 +0,0 @@
1
- import { Boom } from '@hapi/boom'
2
- import { AxiosRequestConfig } from 'axios'
3
- import { Readable, Transform } from 'stream'
4
- import { URL } from 'url'
5
- import { proto } from '../../WAProto'
6
- import { DownloadableMessage, MediaConnInfo, MediaDecryptionKeyInfo, MediaType, SocketConfig, WAMediaUpload, WAMediaUploadFunction, WAMessageContent } from '../Types'
7
- import { BinaryNode } from '../WABinary'
8
- import { ILogger } from './logger'
9
-
10
- export declare const hkdfInfoKey: (type: MediaType) => string
11
-
12
- export declare const getRawMediaUploadData: (media: WAMediaUpload, mediaType: MediaType, logger?: ILogger) => Promise<{
13
- filePath: string
14
- fileSha256: Buffer<ArrayBufferLike>
15
- fileLength: number
16
- }>
17
-
18
- /** generates all the keys required to encrypt/decrypt & sign a media message */
19
- export declare function getMediaKeys(buffer: Uint8Array | string | null | undefined, mediaType: MediaType): MediaDecryptionKeyInfo
20
-
21
- export declare const extractImageThumb: (bufferOrFilePath: Readable | Buffer | string, width?: number) => Promise<{
22
- buffer: Buffer
23
- original: {
24
- width: number | undefined
25
- height: number | undefined
26
- }
27
- }>
28
-
29
- export declare const encodeBase64EncodedStringForUpload: (b64: string) => string
30
-
31
- export declare const generateProfilePicture: (mediaUpload: WAMediaUpload) => Promise<{
32
- img: Buffer
33
- }>
34
-
35
- /** gets the SHA256 of the given media message */
36
- export declare const mediaMessageSHA256B64: (message: WAMessageContent) => string | null | undefined
37
-
38
- export declare function getAudioDuration(buffer: Buffer | string | Readable): Promise<number | undefined>
39
-
40
- /**
41
- referenced from and modifying https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareAudioWaveform.ts
42
- */
43
- export declare function getAudioWaveform(buffer: Buffer | string | Readable, logger?: ILogger): Promise<Uint8Array | undefined>
44
-
45
- export declare const toReadable: (buffer: Buffer) => Readable
46
-
47
- export declare const toBuffer: (stream: Readable) => Promise<Buffer>
48
-
49
- export declare const getStream: (item: WAMediaUpload, opts?: AxiosRequestConfig) => Promise<{
50
- readonly stream: Readable
51
- readonly type: "buffer"
52
- } | {
53
- readonly stream: Readable
54
- readonly type: "readable"
55
- } | {
56
- readonly stream: Readable
57
- readonly type: "remote"
58
- } | {
59
- readonly stream: import("fs").ReadStream
60
- readonly type: "file"
61
- }>
62
-
63
- /** generates a thumbnail for a given media, if required */
64
- export declare function generateThumbnail(file: string, mediaType: 'video' | 'image', options: {
65
- logger?: Logger
66
- }): Promise<{
67
- thumbnail: string | undefined
68
- originalImageDimensions: {
69
- width: number
70
- height: number
71
- } | undefined
72
- }>
73
-
74
- export declare const getHttpStream: (url: string | URL, options?: AxiosRequestConfig & {
75
- isStream?: true
76
- }) => Promise<Readable>
77
-
78
- type EncryptedStreamOptions = {
79
- saveOriginalFileIfRequired?: boolean
80
- logger?: Logger
81
- opts?: AxiosRequestConfig
82
- }
83
-
84
- export declare const encryptedStream: (media: WAMediaUpload, mediaType: MediaType, { logger, saveOriginalFileIfRequired, opts }?: EncryptedStreamOptions) => Promise<{
85
- mediaKey: Buffer
86
- encWriteStream: Readable
87
- bodyPath: string | undefined
88
- mac: Buffer
89
- fileEncSha256: Buffer
90
- fileSha256: Buffer
91
- fileLength: number
92
- didSaveToTmpPath: boolean
93
- }>
94
-
95
- export type MediaDownloadOptions = {
96
- startByte?: number
97
- endByte?: number
98
- options?: AxiosRequestConfig<{}>
99
- }
100
-
101
- export declare const getUrlFromDirectPath: (directPath: string) => string
102
-
103
- export declare const downloadContentFromMessage: ({ mediaKey, directPath, url }: DownloadableMessage, type: MediaType, opts?: MediaDownloadOptions) => Promise<Transform>
104
-
105
- /**
106
- * Decrypts and downloads an AES256-CBC encrypted file given the keys.
107
- * Assumes the SHA256 of the plaintext is appended to the end of the ciphertext
108
- * */
109
- export declare const downloadEncryptedContent: (downloadUrl: string, { cipherKey, iv }: MediaDecryptionKeyInfo, { startByte, endByte, options }?: MediaDownloadOptions) => Promise<Transform>
110
-
111
- export declare function extensionForMediaMessage(message: WAMessageContent): string
112
-
113
- export declare const getWAUploadToServer: ({ customUploadHosts, fetchAgent, logger, options }: SocketConfig, refreshMediaConn: (force: boolean) => Promise<MediaConnInfo>) => WAMediaUploadFunction
114
- /**
115
- * Generate a binary node that will request the phone to re-upload the media & return the newly uploaded URL
116
- */
117
- export declare const encryptMediaRetryRequest: (key: proto.IMessageKey, mediaKey: Buffer | Uint8Array, meId: string) => BinaryNode
118
-
119
- export declare const decodeMediaRetryNode: (node: BinaryNode) => {
120
- key: proto.IMessageKey
121
- media?: {
122
- ciphertext: Uint8Array
123
- iv: Uint8Array
124
- } | undefined
125
- error?: Boom<any> | undefined
126
- }
127
-
128
- export declare const decryptMediaRetryData: ({ ciphertext, iv }: {
129
- ciphertext: Uint8Array
130
- iv: Uint8Array
131
- }, mediaKey: Uint8Array, msgId: string) => Promise<proto.MediaRetryNotification>
132
-
133
- export declare const getStatusCodeForMediaRetry: (code: number) => any
134
-
135
- export {}
@@ -1,105 +0,0 @@
1
- import { ILogger } from './logger'
2
- import { type Transform } from 'stream'
3
- import { proto } from '../../WAProto'
4
- import { AnyMediaMessageContent, AnyMessageContent, MediaGenerationOptions, MessageContentGenerationOptions, MessageGenerationOptions, MessageGenerationOptionsFromContent, MessageUserReceipt, WAMessage, WAMessageContent, WAProto } from '../Types'
5
- import { MediaDownloadOptions } from './messages-media'
6
-
7
- /**
8
- * Uses a regex to test whether the string contains a URL, and returns the URL if it does.
9
- * @param text eg. hello https://google.com
10
- * @returns the URL, eg. https://google.com
11
- */
12
- export declare const extractUrlFromText: (text: string) => string | undefined
13
-
14
- export declare const generateLinkPreviewIfRequired: (text: string, getUrlInfo: MessageGenerationOptions['getUrlInfo'], logger: MessageGenerationOptions['logger']) => Promise<import("../Types").WAUrlInfo | undefined>
15
-
16
- export declare const prepareWAMessageMedia: (message: AnyMediaMessageContent, options: MediaGenerationOptions) => Promise<proto.Message>
17
-
18
- export declare const prepareAlbumMessageContent: (jid: string, albums: WAProto.IMessage, options: MessageContentGenerationOptions) => Promise<proto.Message[]>
19
-
20
- export declare const prepareDisappearingMessageSettingContent: (ephemeralExpiration?: number) => proto.Message
21
-
22
- /**
23
- * Generate forwarded message content like WA does
24
- * @param message the message to forward
25
- * @param options.forceForward will show the message as forwarded even if it is from you
26
- */
27
- export declare const generateForwardMessageContent: (message: WAMessage, forceForward?: boolean) => proto.IMessage
28
-
29
- export declare const generateWAMessageContent: (message: AnyMessageContent, options: MessageContentGenerationOptions) => Promise<proto.Message>
30
-
31
- export declare const generateWAMessageFromContent: (jid: string, message: WAMessageContent, options: MessageGenerationOptionsFromContent) => proto.WebMessageInfo
32
-
33
- export declare const generateWAMessage: (jid: string, content: AnyMessageContent, options: MessageGenerationOptions) => Promise<proto.WebMessageInfo>
34
-
35
- /** Get the key to access the true type of content */
36
- export declare const getContentType: (content: WAProto.IMessage | undefined) => keyof proto.IMessage | undefined
37
-
38
- /**
39
- * Normalizes ephemeral, view once messages to regular message content
40
- * Eg. image messages in ephemeral messages, in view once messages etc.
41
- * @param content
42
- * @returns
43
- */
44
- export declare const normalizeMessageContent: (content: WAMessageContent | null | undefined) => WAMessageContent | undefined
45
-
46
- /**
47
- * Extract the true message content from a message
48
- * Eg. extracts the inner message from a disappearing message/view once message
49
- */
50
- export declare const extractMessageContent: (content: WAMessageContent | undefined | null) => WAMessageContent | undefined
51
-
52
- /**
53
- * Returns the device predicted by message ID
54
- */
55
- export declare const getDevice: (id: string) => "android" | "unknown" | "web" | "ios" | "desktop"
56
-
57
- /** Upserts a receipt in the message */
58
- export declare const updateMessageWithReceipt: (msg: Pick<WAMessage, 'userReceipt'>, receipt: MessageUserReceipt) => void
59
-
60
- /** Update the message with a new reaction */
61
- export declare const updateMessageWithReaction: (msg: Pick<WAMessage, 'reactions'>, reaction: proto.IReaction) => void
62
-
63
- /** Update the message with a new poll update */
64
- export declare const updateMessageWithPollUpdate: (msg: Pick<WAMessage, 'pollUpdates'>, update: proto.IPollUpdate) => void
65
-
66
- type VoteAggregation = {
67
- name: string
68
- voters: string[]
69
- }
70
-
71
- /**
72
- * Aggregates all poll updates in a poll.
73
- * @param msg the poll creation message
74
- * @param meId your jid
75
- * @returns A list of options & their voters
76
- */
77
- export declare function getAggregateVotesInPollMessage({ message, pollUpdates }: Pick<WAMessage, 'pollUpdates' | 'message'>, meId?: string): VoteAggregation[]
78
-
79
- /** Given a list of message keys, aggregates them by chat & sender. Useful for sending read receipts in bulk */
80
- export declare const aggregateMessageKeysNotFromMe: (keys: proto.IMessageKey[]) => {
81
- jid: string
82
- participant: string | undefined
83
- messageIds: string[]
84
- }[]
85
-
86
- type DownloadMediaMessageContext = {
87
- reuploadRequest: (msg: WAMessage) => Promise<WAMessage>
88
- logger: ILogger
89
- }
90
-
91
- /**
92
- * Downloads the given message. Throws an error if it's not a media message
93
- */
94
- export declare const downloadMediaMessage: <Type extends "stream" | "buffer">(message: WAMessage, type: Type, options: MediaDownloadOptions, ctx?: DownloadMediaMessageContext) => Promise<Type extends "buffer" ? Buffer : Transform>
95
-
96
- /** Checks whether the given message is a media message if it is returns the inner content */
97
- export declare const assertMediaContent: (content: proto.IMessage | null | undefined) => proto.Message.IVideoMessage | proto.Message.IImageMessage | proto.Message.IAudioMessage | proto.Message.IDocumentMessage | proto.Message.IStickerMessage
98
-
99
- /**
100
- * this is an experimental patch to make buttons work
101
- * Don't know how it works, but it does for now
102
- */
103
- export declare const patchMessageForMdIfRequired: (message: proto.IMessage) => proto.IMessage
104
-
105
- export {}
@@ -1,20 +0,0 @@
1
- import { proto } from '../../WAProto'
2
- import { KeyPair } from '../Types'
3
- import { BinaryNode } from '../WABinary'
4
- import { ILogger } from './logger'
5
-
6
- export declare const makeNoiseHandler: ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, logger, routingInfo }: {
7
- keyPair: KeyPair
8
- NOISE_HEADER: Uint8Array
9
- logger: ILogger
10
- routingInfo?: Buffer | undefined
11
- }) => {
12
- encrypt: (plaintext: Uint8Array) => Buffer
13
- decrypt: (ciphertext: Uint8Array) => Buffer
14
- authenticate: (data: Uint8Array) => void
15
- mixIntoKey: (data: Uint8Array) => Promise<void>
16
- finishInit: () => Promise<void>
17
- processHandshake: ({ serverHello }: proto.HandshakeMessage, noiseKey: KeyPair) => Promise<Buffer>
18
- encodeFrame: (data: Buffer | Uint8Array) => Buffer
19
- decodeFrame: (newData: Buffer | Uint8Array, onFrame: (buff: Uint8Array | BinaryNode) => void) => Promise<void>
20
- }
@@ -1,49 +0,0 @@
1
- import { AxiosRequestConfig } from 'axios'
2
- import { proto } from '../../WAProto'
3
- import { AuthenticationCreds, BaileysEventEmitter, CacheStore, SignalKeyStoreWithTransaction, SocketConfig } from '../Types'
4
- import { ILogger } from './logger'
5
-
6
- type ProcessMessageContext = {
7
- shouldProcessHistoryMsg: boolean
8
- placeholderResendCache?: CacheStore
9
- creds: AuthenticationCreds
10
- keyStore: SignalKeyStoreWithTransaction
11
- ev: BaileysEventEmitter
12
- getMessage: SocketConfig['getMessage']
13
- logger?: ILogger
14
- options: AxiosRequestConfig<{}>
15
- }
16
-
17
- /** Cleans a received message to further processing */
18
- export declare const cleanMessage: (message: proto.IWebMessageInfo, meId: string) => void
19
-
20
- export declare const isRealMessage: (message: proto.IWebMessageInfo, meId: string) => boolean | undefined
21
-
22
- export declare const shouldIncrementChatUnread: (message: proto.IWebMessageInfo) => boolean
23
-
24
- /**
25
- * Get the ID of the chat from the given key.
26
- * Typically -- that'll be the remoteJid, but for broadcasts, it'll be the participant
27
- */
28
- export declare const getChatId: ({ remoteJid, participant, fromMe }: proto.IMessageKey) => string
29
-
30
- type PollContext = {
31
- /** normalised jid of the person that created the poll */
32
- pollCreatorJid: string
33
- /** ID of the poll creation message */
34
- pollMsgId: string
35
- /** poll creation message enc key */
36
- pollEncKey: Uint8Array
37
- /** jid of the person that voted */
38
- voterJid: string
39
- }
40
-
41
- /**
42
- * Decrypt a poll vote
43
- * @param vote encrypted vote
44
- * @param ctx additional info about the poll required for decryption
45
- * @returns list of SHA256 options
46
- */
47
- export declare function decryptPollVote({ encPayload, encIv }: proto.Message.IPollEncValue, { pollCreatorJid, pollMsgId, pollEncKey, voterJid, }: PollContext): proto.Message.PollVoteMessage
48
-
49
- export declare const processMessage: (message: proto.IWebMessageInfo, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, keyStore, logger, options, getMessage }: ProcessMessageContext) => Promise<void>