@alannxd/baileys 6.0.6 → 6.0.9

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 (220) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +341 -286
  3. package/WAProto/GenerateStatics.sh +3 -0
  4. package/WAProto/WAProto.proto +6902 -0
  5. package/WAProto/fix-imports.js +85 -0
  6. package/WAProto/index.d.ts +79257 -0
  7. package/WAProto/index.js +205861 -60565
  8. package/engine-requirements.js +1 -1
  9. package/lib/Defaults/index.js +119 -136
  10. package/lib/Signal/Group/ciphertext-message.js +2 -5
  11. package/lib/Signal/Group/group-session-builder.js +7 -41
  12. package/lib/Signal/Group/group_cipher.js +37 -51
  13. package/lib/Signal/Group/index.js +12 -57
  14. package/lib/Signal/Group/keyhelper.js +7 -44
  15. package/lib/Signal/Group/sender-chain-key.js +7 -15
  16. package/lib/Signal/Group/sender-key-distribution-message.js +8 -11
  17. package/lib/Signal/Group/sender-key-message.js +9 -12
  18. package/lib/Signal/Group/sender-key-name.js +2 -5
  19. package/lib/Signal/Group/sender-key-record.js +9 -21
  20. package/lib/Signal/Group/sender-key-state.js +27 -42
  21. package/lib/Signal/Group/sender-message-key.js +4 -7
  22. package/lib/Signal/libsignal.js +347 -90
  23. package/lib/Signal/lid-mapping.js +277 -0
  24. package/lib/Socket/Client/index.js +3 -19
  25. package/lib/Socket/Client/types.js +11 -0
  26. package/lib/Socket/Client/websocket.js +54 -0
  27. package/lib/Socket/business.js +162 -43
  28. package/lib/Socket/chats.js +627 -427
  29. package/lib/Socket/communities.js +90 -80
  30. package/lib/Socket/groups.js +154 -161
  31. package/lib/Socket/index.js +11 -10
  32. package/lib/Socket/luxu.js +315 -469
  33. package/lib/Socket/messages-recv.js +1421 -615
  34. package/lib/Socket/messages-send.js +1150 -799
  35. package/lib/Socket/mex.js +42 -0
  36. package/lib/Socket/newsletter.js +152 -204
  37. package/lib/Socket/socket.js +544 -313
  38. package/lib/Store/index.js +10 -10
  39. package/lib/Store/keyed-db.js +108 -0
  40. package/lib/Store/make-cache-manager-store.js +43 -41
  41. package/lib/Store/make-in-memory-store.js +112 -341
  42. package/lib/Store/make-ordered-dictionary.js +14 -20
  43. package/lib/Store/object-repository.js +11 -6
  44. package/lib/Types/Auth.js +2 -2
  45. package/lib/Types/Bussines.js +2 -0
  46. package/lib/Types/Call.js +2 -2
  47. package/lib/Types/Chat.js +8 -4
  48. package/lib/Types/Contact.js +2 -2
  49. package/lib/Types/Events.js +2 -2
  50. package/lib/Types/GroupMetadata.js +2 -2
  51. package/lib/Types/Label.js +3 -5
  52. package/lib/Types/LabelAssociation.js +3 -5
  53. package/lib/Types/Message.js +11 -9
  54. package/lib/Types/Mex.js +37 -0
  55. package/lib/Types/Product.js +2 -2
  56. package/lib/Types/Signal.js +2 -2
  57. package/lib/Types/Socket.js +3 -2
  58. package/lib/Types/State.js +56 -2
  59. package/lib/Types/USync.js +2 -2
  60. package/lib/Types/index.js +15 -31
  61. package/lib/Utils/auth-utils.js +239 -143
  62. package/lib/Utils/browser-utils.js +48 -0
  63. package/lib/Utils/business.js +66 -69
  64. package/lib/Utils/chat-utils.js +396 -253
  65. package/lib/Utils/companion-reg-client-utils.js +35 -0
  66. package/lib/Utils/crypto.js +57 -90
  67. package/lib/Utils/decode-wa-message.js +236 -84
  68. package/lib/Utils/event-buffer.js +185 -77
  69. package/lib/Utils/generics.js +189 -209
  70. package/lib/Utils/history.js +93 -55
  71. package/lib/Utils/identity-change-handler.js +50 -0
  72. package/lib/Utils/index.js +23 -33
  73. package/lib/Utils/link-preview.js +16 -24
  74. package/lib/Utils/logger.js +3 -7
  75. package/lib/Utils/lt-hash.js +3 -46
  76. package/lib/Utils/make-mutex.js +24 -34
  77. package/lib/Utils/message-composer.js +273 -0
  78. package/lib/Utils/message-retry-manager.js +265 -0
  79. package/lib/Utils/messages-media.js +451 -482
  80. package/lib/Utils/messages.js +795 -369
  81. package/lib/Utils/noise-handler.js +145 -99
  82. package/lib/Utils/offline-node-processor.js +40 -0
  83. package/lib/Utils/pre-key-manager.js +106 -0
  84. package/lib/Utils/process-message.js +459 -150
  85. package/lib/Utils/reporting-utils.js +258 -0
  86. package/lib/Utils/signal.js +120 -72
  87. package/lib/Utils/stanza-ack.js +38 -0
  88. package/lib/Utils/sync-action-utils.js +49 -0
  89. package/lib/Utils/tc-token-utils.js +163 -0
  90. package/lib/Utils/use-multi-file-auth-state.js +29 -27
  91. package/lib/Utils/validate-connection.js +73 -99
  92. package/lib/WABinary/constants.js +1281 -20
  93. package/lib/WABinary/decode.js +52 -42
  94. package/lib/WABinary/encode.js +110 -155
  95. package/lib/WABinary/generic-utils.js +55 -49
  96. package/lib/WABinary/index.js +6 -21
  97. package/lib/WABinary/jid-utils.js +76 -40
  98. package/lib/WABinary/types.js +2 -2
  99. package/lib/WAM/BinaryInfo.js +2 -5
  100. package/lib/WAM/constants.js +19071 -11568
  101. package/lib/WAM/encode.js +17 -22
  102. package/lib/WAM/index.js +4 -19
  103. package/lib/WAUSync/Protocols/USyncContactProtocol.js +33 -13
  104. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +11 -14
  105. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +9 -12
  106. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +9 -13
  107. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
  108. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +20 -22
  109. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +13 -8
  110. package/lib/WAUSync/Protocols/index.js +6 -20
  111. package/lib/WAUSync/USyncQuery.js +44 -35
  112. package/lib/WAUSync/USyncUser.js +10 -5
  113. package/lib/WAUSync/index.js +4 -19
  114. package/lib/index.js +13 -36
  115. package/package.json +85 -51
  116. package/WAProto/fix-import.js +0 -29
  117. package/lib/Defaults/baileys-version.json +0 -3
  118. package/lib/Defaults/index.d.ts +0 -53
  119. package/lib/Defaults/phonenumber-mcc.json +0 -223
  120. package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
  121. package/lib/Signal/Group/group-session-builder.d.ts +0 -14
  122. package/lib/Signal/Group/group_cipher.d.ts +0 -17
  123. package/lib/Signal/Group/index.d.ts +0 -11
  124. package/lib/Signal/Group/keyhelper.d.ts +0 -10
  125. package/lib/Signal/Group/queue-job.d.ts +0 -1
  126. package/lib/Signal/Group/queue-job.js +0 -57
  127. package/lib/Signal/Group/sender-chain-key.d.ts +0 -13
  128. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -16
  129. package/lib/Signal/Group/sender-key-message.d.ts +0 -18
  130. package/lib/Signal/Group/sender-key-name.d.ts +0 -17
  131. package/lib/Signal/Group/sender-key-record.d.ts +0 -30
  132. package/lib/Signal/Group/sender-key-state.d.ts +0 -38
  133. package/lib/Signal/Group/sender-message-key.d.ts +0 -11
  134. package/lib/Signal/libsignal.d.ts +0 -3
  135. package/lib/Socket/Client/abstract-socket-client.d.ts +0 -17
  136. package/lib/Socket/Client/abstract-socket-client.js +0 -13
  137. package/lib/Socket/Client/index.d.ts +0 -3
  138. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
  139. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  140. package/lib/Socket/Client/web-socket-client.d.ts +0 -12
  141. package/lib/Socket/Client/web-socket-client.js +0 -62
  142. package/lib/Socket/business.d.ts +0 -171
  143. package/lib/Socket/chats.d.ts +0 -267
  144. package/lib/Socket/communities.d.ts +0 -180
  145. package/lib/Socket/groups.d.ts +0 -115
  146. package/lib/Socket/index.d.ts +0 -173
  147. package/lib/Socket/luxu.d.ts +0 -266
  148. package/lib/Socket/messages-recv.d.ts +0 -161
  149. package/lib/Socket/messages-send.d.ts +0 -183
  150. package/lib/Socket/newsletter.d.ts +0 -134
  151. package/lib/Socket/registration.d.ts +0 -267
  152. package/lib/Socket/registration.js +0 -166
  153. package/lib/Socket/socket.d.ts +0 -44
  154. package/lib/Socket/usync.d.ts +0 -36
  155. package/lib/Socket/usync.js +0 -70
  156. package/lib/Store/index.d.ts +0 -3
  157. package/lib/Store/make-cache-manager-store.d.ts +0 -13
  158. package/lib/Store/make-in-memory-store.d.ts +0 -118
  159. package/lib/Store/make-ordered-dictionary.d.ts +0 -13
  160. package/lib/Store/object-repository.d.ts +0 -10
  161. package/lib/Types/Auth.d.ts +0 -110
  162. package/lib/Types/Call.d.ts +0 -13
  163. package/lib/Types/Chat.d.ts +0 -102
  164. package/lib/Types/Contact.d.ts +0 -19
  165. package/lib/Types/Events.d.ts +0 -157
  166. package/lib/Types/GroupMetadata.d.ts +0 -55
  167. package/lib/Types/Label.d.ts +0 -35
  168. package/lib/Types/LabelAssociation.d.ts +0 -29
  169. package/lib/Types/Message.d.ts +0 -273
  170. package/lib/Types/Newsletter.d.ts +0 -103
  171. package/lib/Types/Newsletter.js +0 -38
  172. package/lib/Types/Product.d.ts +0 -78
  173. package/lib/Types/Signal.d.ts +0 -57
  174. package/lib/Types/Socket.d.ts +0 -111
  175. package/lib/Types/State.d.ts +0 -27
  176. package/lib/Types/USync.d.ts +0 -25
  177. package/lib/Types/index.d.ts +0 -57
  178. package/lib/Utils/auth-utils.d.ts +0 -18
  179. package/lib/Utils/baileys-event-stream.d.ts +0 -16
  180. package/lib/Utils/baileys-event-stream.js +0 -63
  181. package/lib/Utils/business.d.ts +0 -22
  182. package/lib/Utils/chat-utils.d.ts +0 -71
  183. package/lib/Utils/crypto.d.ts +0 -41
  184. package/lib/Utils/decode-wa-message.d.ts +0 -19
  185. package/lib/Utils/event-buffer.d.ts +0 -35
  186. package/lib/Utils/generics.d.ts +0 -92
  187. package/lib/Utils/history.d.ts +0 -15
  188. package/lib/Utils/index.d.ts +0 -17
  189. package/lib/Utils/link-preview.d.ts +0 -21
  190. package/lib/Utils/logger.d.ts +0 -4
  191. package/lib/Utils/lt-hash.d.ts +0 -12
  192. package/lib/Utils/make-mutex.d.ts +0 -7
  193. package/lib/Utils/messages-media.d.ts +0 -116
  194. package/lib/Utils/messages.d.ts +0 -77
  195. package/lib/Utils/noise-handler.d.ts +0 -21
  196. package/lib/Utils/process-message.d.ts +0 -41
  197. package/lib/Utils/signal.d.ts +0 -32
  198. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
  199. package/lib/Utils/validate-connection.d.ts +0 -11
  200. package/lib/WABinary/constants.d.ts +0 -30
  201. package/lib/WABinary/decode.d.ts +0 -7
  202. package/lib/WABinary/encode.d.ts +0 -3
  203. package/lib/WABinary/generic-utils.d.ts +0 -17
  204. package/lib/WABinary/index.d.ts +0 -5
  205. package/lib/WABinary/jid-utils.d.ts +0 -31
  206. package/lib/WABinary/types.d.ts +0 -18
  207. package/lib/WAM/BinaryInfo.d.ts +0 -17
  208. package/lib/WAM/constants.d.ts +0 -38
  209. package/lib/WAM/encode.d.ts +0 -3
  210. package/lib/WAM/index.d.ts +0 -3
  211. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
  212. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
  213. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
  214. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
  215. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -25
  216. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -8
  217. package/lib/WAUSync/Protocols/index.d.ts +0 -4
  218. package/lib/WAUSync/USyncQuery.d.ts +0 -28
  219. package/lib/WAUSync/USyncUser.d.ts +0 -12
  220. package/lib/index.d.ts +0 -12
@@ -1,103 +0,0 @@
1
- import { proto } from "../../WAProto"
2
-
3
- export type NewsletterReactionMode = "ALL" | "BASIC" | "NONE"
4
- export type NewsletterState = "ACTIVE" | "GEOSUSPENDED" | "SUSPENDED"
5
- export type NewsletterVerification = "VERIFIED" | "UNVERIFIED"
6
- export type NewsletterMute = "ON" | "OFF" | "UNDEFINED"
7
- export type NewsletterViewRole = "ADMIN" | "GUEST" | "OWNER" | "SUBSCRIBER"
8
-
9
- export type NewsletterViewerMetadata = {
10
- mute: NewsletterMute
11
- view_role: NewsletterViewRole
12
- }
13
-
14
- export type NewsletterMetadata = {
15
- /** jid of newsletter */
16
- id: string
17
- /** state of newsletter */
18
- state: NewsletterState
19
- /** creation timestamp of newsletter */
20
- creation_time: number
21
- /** name of newsletter */
22
- name: string
23
- /** timestamp of last name modification of newsletter */
24
- nameTime: number
25
- /** description of newsletter */
26
- description: string
27
- /** timestamp of last description modification of newsletter */
28
- descriptionTime: number
29
- /** invite code of newsletter */
30
- invite: string
31
- /** direct path of picture */
32
- picture: string | null
33
- /** direct path of picture preview (lower quality) */
34
- preview: string | null
35
- /** reaction mode of newsletter */
36
- reaction_codes?: NewsletterReactionMode
37
- /** subscribers count of newsletter */
38
- subscribers: number
39
- /** verification state of newsletter */
40
- verification: NewsletterVerification
41
- /** viewer metadata */
42
- viewer_metadata: NewsletterViewerMetadata
43
- }
44
-
45
- export type SubscriberAction = "promote" | "demote"
46
-
47
- export type ReactionModeUpdate = {
48
- reaction_codes: {
49
- blocked_codes: null
50
- enabled_ts_sec: null
51
- value: NewsletterReactionMode
52
- }
53
- }
54
-
55
- /** only exists reaction mode update */
56
- export type NewsletterSettingsUpdate = ReactionModeUpdate
57
-
58
- export type NewsletterReaction = {
59
- count: number
60
- code: string
61
- }
62
-
63
- export type NewsletterFetchedUpdate = {
64
- /** id of message in newsletter, starts from 100 */
65
- server_id: string
66
- /** count of views in this message */
67
- views?: number
68
- /** reactions in this message */
69
- reactions: NewsletterReaction[]
70
- /** the message, if you requested only updates, you will not receive message */
71
- message?: proto.IWebMessageInfo
72
- }
73
-
74
- export const MexOperations = {
75
- PROMOTE: "NotificationNewsletterAdminPromote",
76
- DEMOTE: "NotificationNewsletterAdminDemote",
77
- UPDATE: "NotificationNewsletterUpdate"
78
- } as const
79
-
80
- export const XWAPaths = {
81
- PROMOTE: "xwa2_notify_newsletter_admin_promote",
82
- DEMOTE: "xwa2_notify_newsletter_admin_demote",
83
- ADMIN_COUNT: "xwa2_newsletter_admin",
84
- CREATE: "xwa2_newsletter_create",
85
- NEWSLETTER: "xwa2_newsletter",
86
- SUBSCRIBED: "xwa2_newsletter_subscribed",
87
- METADATA_UPDATE: "xwa2_notify_newsletter_on_metadata_update"
88
- } as const
89
-
90
- export const QueryIds = {
91
- JOB_MUTATION: "7150902998257522",
92
- METADATA: "6620195908089573",
93
- UNFOLLOW: "7238632346214362",
94
- FOLLOW: "7871414976211147",
95
- UNMUTE: "7337137176362961",
96
- MUTE: "25151904754424642",
97
- CREATE: "6996806640408138",
98
- ADMIN_COUNT: "7130823597031706",
99
- CHANGE_OWNER: "7341777602580933",
100
- DELETE: "8316537688363079",
101
- DEMOTE: "6551828931592903",
102
- SUBSCRIBED: "6388546374527196"
103
- } as const
@@ -1,38 +0,0 @@
1
- "use strict"
2
-
3
- Object.defineProperty(exports, "__esModule", { value: true })
4
-
5
- const MexOperations = {
6
- PROMOTE: "NotificationNewsletterAdminPromote",
7
- DEMOTE: "NotificationNewsletterAdminDemote",
8
- UPDATE: "NotificationNewsletterUpdate"
9
- }
10
-
11
- const XWAPaths = {
12
- PROMOTE: "xwa2_notify_newsletter_admin_promote",
13
- DEMOTE: "xwa2_notify_newsletter_admin_demote",
14
- ADMIN_COUNT: "xwa2_newsletter_admin",
15
- CREATE: "xwa2_newsletter_create",
16
- NEWSLETTER: "xwa2_newsletter",
17
- SUBSCRIBED: "xwa2_newsletter_subscribed",
18
- METADATA_UPDATE: "xwa2_notify_newsletter_on_metadata_update"
19
- }
20
-
21
- const QueryIds = {
22
- JOB_MUTATION: "7150902998257522",
23
- METADATA: "6620195908089573",
24
- UNFOLLOW: "7238632346214362",
25
- FOLLOW: "7871414976211147",
26
- UNMUTE: "7337137176362961",
27
- MUTE: "25151904754424642",
28
- CREATE: "6996806640408138",
29
- ADMIN_COUNT: "7130823597031706",
30
- CHANGE_OWNER: "7341777602580933",
31
- DELETE: "8316537688363079",
32
- DEMOTE: "6551828931592903",
33
- SUBSCRIBED: "6388546374527196"
34
- }
35
-
36
- exports.MexOperations = MexOperations
37
- exports.XWAPaths = XWAPaths
38
- exports.QueryIds = QueryIds
@@ -1,78 +0,0 @@
1
- import { WAMediaUpload } from './Message';
2
- export type CatalogResult = {
3
- data: {
4
- paging: {
5
- cursors: {
6
- before: string;
7
- after: string;
8
- };
9
- };
10
- data: any[];
11
- };
12
- };
13
- export type ProductCreateResult = {
14
- data: {
15
- product: {};
16
- };
17
- };
18
- export type CatalogStatus = {
19
- status: string;
20
- canAppeal: boolean;
21
- };
22
- export type CatalogCollection = {
23
- id: string;
24
- name: string;
25
- products: Product[];
26
- status: CatalogStatus;
27
- };
28
- export type ProductAvailability = 'in stock';
29
- export type ProductBase = {
30
- name: string;
31
- retailerId?: string;
32
- url?: string;
33
- description: string;
34
- price: number;
35
- currency: string;
36
- isHidden?: boolean;
37
- };
38
- export type ProductCreate = ProductBase & {
39
- /** ISO country code for product origin. Set to undefined for no country */
40
- originCountryCode: string | undefined;
41
- /** images of the product */
42
- images: WAMediaUpload[];
43
- };
44
- export type ProductUpdate = Omit<ProductCreate, 'originCountryCode'>;
45
- export type Product = ProductBase & {
46
- id: string;
47
- imageUrls: {
48
- [_: string]: string;
49
- };
50
- reviewStatus: {
51
- [_: string]: string;
52
- };
53
- availability: ProductAvailability;
54
- };
55
- export type OrderPrice = {
56
- currency: string;
57
- total: number;
58
- };
59
- export type OrderProduct = {
60
- id: string;
61
- imageUrl: string;
62
- name: string;
63
- quantity: number;
64
- currency: string;
65
- price: number;
66
- };
67
- export type OrderDetails = {
68
- price: OrderPrice;
69
- products: OrderProduct[];
70
- };
71
- export type CatalogCursor = string;
72
- export type GetCatalogOptions = {
73
- /** cursor to start from */
74
- cursor?: CatalogCursor;
75
- /** number of products to fetch */
76
- limit?: number;
77
- jid?: string;
78
- };
@@ -1,57 +0,0 @@
1
- import { proto } from '../../WAProto';
2
- type DecryptGroupSignalOpts = {
3
- group: string;
4
- authorJid: string;
5
- msg: Uint8Array;
6
- };
7
- type ProcessSenderKeyDistributionMessageOpts = {
8
- item: proto.Message.ISenderKeyDistributionMessage;
9
- authorJid: string;
10
- };
11
- type DecryptSignalProtoOpts = {
12
- jid: string;
13
- type: 'pkmsg' | 'msg';
14
- ciphertext: Uint8Array;
15
- };
16
- type EncryptMessageOpts = {
17
- jid: string;
18
- data: Uint8Array;
19
- };
20
- type EncryptGroupMessageOpts = {
21
- group: string;
22
- data: Uint8Array;
23
- meId: string;
24
- };
25
- type PreKey = {
26
- keyId: number;
27
- publicKey: Uint8Array;
28
- };
29
- type SignedPreKey = PreKey & {
30
- signature: Uint8Array;
31
- };
32
- type E2ESession = {
33
- registrationId: number;
34
- identityKey: Uint8Array;
35
- signedPreKey: SignedPreKey;
36
- preKey: PreKey;
37
- };
38
- type E2ESessionOpts = {
39
- jid: string;
40
- session: E2ESession;
41
- };
42
- export type SignalRepository = {
43
- decryptGroupMessage(opts: DecryptGroupSignalOpts): Promise<Uint8Array>;
44
- processSenderKeyDistributionMessage(opts: ProcessSenderKeyDistributionMessageOpts): Promise<void>;
45
- decryptMessage(opts: DecryptSignalProtoOpts): Promise<Uint8Array>;
46
- encryptMessage(opts: EncryptMessageOpts): Promise<{
47
- type: 'pkmsg' | 'msg';
48
- ciphertext: Uint8Array;
49
- }>;
50
- encryptGroupMessage(opts: EncryptGroupMessageOpts): Promise<{
51
- senderKeyDistributionMessage: Uint8Array;
52
- ciphertext: Uint8Array;
53
- }>;
54
- injectE2ESession(opts: E2ESessionOpts): Promise<void>;
55
- jidToSignalProtocolAddress(jid: string): string;
56
- };
57
- export {};
@@ -1,111 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { AxiosRequestConfig } from 'axios';
4
- import type { Agent } from 'https';
5
- import type { Logger } from 'pino';
6
- import type { URL } from 'url';
7
- import { proto } from '../../WAProto';
8
- import { AuthenticationState, SignalAuthState, TransactionCapabilityOptions } from './Auth';
9
- import { MediaConnInfo } from './Message';
10
- import { SignalRepository } from './Signal';
11
- export type WAVersion = [number, number, number];
12
- export type WABrowserDescription = [string, string, string];
13
- export type CacheStore = {
14
- /** get a cached key and change the stats */
15
- get<T>(key: string): T | undefined;
16
- /** set a key in the cache */
17
- set<T>(key: string, value: T): void;
18
- /** delete a key from the cache */
19
- del(key: string): void;
20
- /** flush all data */
21
- flushAll(): void;
22
- };
23
- export type SocketConfig = {
24
- /** the WS url to connect to WA */
25
- waWebSocketUrl: string | URL;
26
- /** Fails the connection if the socket times out in this interval */
27
- connectTimeoutMs: number;
28
- /** Default timeout for queries, undefined for no timeout */
29
- defaultQueryTimeoutMs: number | undefined;
30
- /** ping-pong interval for WS connection */
31
- keepAliveIntervalMs: number;
32
- /** should baileys use the mobile api instead of the multi device api */
33
- mobile?: boolean;
34
- /** proxy agent */
35
- agent?: Agent;
36
- /** pino logger */
37
- logger: Logger;
38
- /** version to connect with */
39
- version: WAVersion;
40
- /** override browser config */
41
- browser: WABrowserDescription;
42
- /** agent used for fetch requests -- uploading/downloading media */
43
- fetchAgent?: Agent;
44
- /** should the QR be printed in the terminal */
45
- printQRInTerminal: boolean;
46
- /** should events be emitted for actions done by this socket connection */
47
- emitOwnEvents: boolean;
48
- /** custom upload hosts to upload media to */
49
- customUploadHosts: MediaConnInfo['hosts'];
50
- /** time to wait between sending new retry requests */
51
- retryRequestDelayMs: number;
52
- /** max retry count */
53
- maxMsgRetryCount: number;
54
- /** time to wait for the generation of the next QR in ms */
55
- qrTimeout?: number;
56
- /** provide an auth state object to maintain the auth state */
57
- auth: AuthenticationState;
58
- /** manage history processing with this control; by default will sync up everything */
59
- shouldSyncHistoryMessage: (msg: proto.Message.IHistorySyncNotification) => boolean;
60
- /** transaction capability options for SignalKeyStore */
61
- transactionOpts: TransactionCapabilityOptions;
62
- /** marks the client as online whenever the socket successfully connects */
63
- markOnlineOnConnect: boolean;
64
- /** provide a cache to store media, so does not have to be re-uploaded */
65
- mediaCache?: CacheStore;
66
- /**
67
- * map to store the retry counts for failed messages;
68
- * used to determine whether to retry a message or not */
69
- msgRetryCounterCache?: CacheStore;
70
- /** provide a cache to store a user's device list */
71
- userDevicesCache?: CacheStore;
72
- /** cache to store call offers */
73
- callOfferCache?: CacheStore;
74
- /** width for link preview images */
75
- linkPreviewImageThumbnailWidth: number;
76
- /** Should Baileys ask the phone for full history, will be received async */
77
- syncFullHistory: boolean;
78
- /** Should baileys fire init queries automatically, default true */
79
- fireInitQueries: boolean;
80
- /**
81
- * generate a high quality link preview,
82
- * entails uploading the jpegThumbnail to WA
83
- * */
84
- generateHighQualityLinkPreview: boolean;
85
- /**
86
- * Returns if a jid should be ignored,
87
- * no event for that jid will be triggered.
88
- * Messages from that jid will also not be decrypted
89
- * */
90
- shouldIgnoreJid: (jid: string) => boolean | undefined;
91
- /**
92
- * Optionally patch the message before sending out
93
- * */
94
- patchMessageBeforeSending: (msg: proto.IMessage, recipientJids: string[]) => Promise<proto.IMessage> | proto.IMessage;
95
- /** verify app state MACs */
96
- appStateMacVerification: {
97
- patch: boolean;
98
- snapshot: boolean;
99
- };
100
- /** options for axios */
101
- options: AxiosRequestConfig<{}>;
102
- /**
103
- * fetch a message from your store
104
- * implement this so that messages failed to send
105
- * (solves the "this message can take a while" issue) can be retried
106
- * */
107
- getMessage: (key: proto.IMessageKey) => Promise<proto.IMessage | undefined>;
108
- makeSignalRepository: (auth: SignalAuthState) => SignalRepository;
109
- /** Socket passthrough */
110
- socket?: any;
111
- };
@@ -1,27 +0,0 @@
1
- import { Contact } from './Contact';
2
- export type WAConnectionState = 'open' | 'connecting' | 'close';
3
- export type ConnectionState = {
4
- /** connection is now open, connecting or closed */
5
- connection: WAConnectionState;
6
- /** the error that caused the connection to close */
7
- lastDisconnect?: {
8
- error: Error | undefined;
9
- date: Date;
10
- };
11
- /** is this a new login */
12
- isNewLogin?: boolean;
13
- /** the current QR code */
14
- qr?: string;
15
- /** has the device received all pending notifications while it was offline */
16
- receivedPendingNotifications?: boolean;
17
- /** legacy connection options */
18
- legacy?: {
19
- phoneConnected: boolean;
20
- user?: Contact;
21
- };
22
- /**
23
- * if the client is shown as an active, online client.
24
- * If this is false, the primary phone and other devices will receive notifs
25
- * */
26
- isOnline?: boolean;
27
- };
@@ -1,25 +0,0 @@
1
- import { BinaryNode } from '../WABinary';
2
- import { USyncUser } from '../WAUSync';
3
- /**
4
- * Defines the interface for a USyncQuery protocol
5
- */
6
- export interface USyncQueryProtocol {
7
- /**
8
- * The name of the protocol
9
- */
10
- name: string;
11
- /**
12
- * Defines what goes inside the query part of a USyncQuery
13
- */
14
- getQueryElement: () => BinaryNode;
15
- /**
16
- * Defines what goes inside the user part of a USyncQuery
17
- */
18
- getUserElement: (user: USyncUser) => BinaryNode | null;
19
- /**
20
- * Parse the result of the query
21
- * @param data Data from the result
22
- * @returns Whatever the protocol is supposed to return
23
- */
24
- parser: (data: BinaryNode) => unknown;
25
- }
@@ -1,57 +0,0 @@
1
- export * from './Auth';
2
- export * from './GroupMetadata';
3
- export * from './Chat';
4
- export * from './Contact';
5
- export * from './State';
6
- export * from './Message';
7
- export * from './Newsletter';
8
- export * from './Socket';
9
- export * from './Events';
10
- export * from './Product';
11
- export * from './Call';
12
- export * from './Signal';
13
- import { AuthenticationState } from './Auth';
14
- import { SocketConfig } from './Socket';
15
- export type UserFacingSocketConfig = Partial<SocketConfig> & {
16
- auth: AuthenticationState;
17
- };
18
- export declare enum DisconnectReason {
19
- connectionClosed = 428,
20
- connectionLost = 408,
21
- connectionReplaced = 440,
22
- timedOut = 408,
23
- loggedOut = 401,
24
- badSession = 500,
25
- restartRequired = 515,
26
- multideviceMismatch = 411,
27
- forbidden = 403,
28
- unavailableService = 503
29
- }
30
- export type WAInitResponse = {
31
- ref: string;
32
- ttl: number;
33
- status: 200;
34
- };
35
- export type WABusinessHoursConfig = {
36
- day_of_week: string;
37
- mode: string;
38
- open_time?: number;
39
- close_time?: number;
40
- };
41
- export type WABusinessProfile = {
42
- description: string;
43
- email: string | undefined;
44
- business_hours: {
45
- timezone?: string;
46
- config?: WABusinessHoursConfig[];
47
- business_config?: WABusinessHoursConfig[];
48
- };
49
- website: string[];
50
- category?: string;
51
- wid?: string;
52
- address?: string;
53
- };
54
- export type CurveKeyPair = {
55
- private: Uint8Array;
56
- public: Uint8Array;
57
- };
@@ -1,18 +0,0 @@
1
- import type { Logger } from 'pino';
2
- import type { AuthenticationCreds, CacheStore, SignalKeyStore, SignalKeyStoreWithTransaction, TransactionCapabilityOptions } from '../Types';
3
- /**
4
- * Adds caching capability to a SignalKeyStore
5
- * @param store the store to add caching to
6
- * @param logger to log trace events
7
- * @param _cache cache store to use
8
- */
9
- export declare function makeCacheableSignalKeyStore(store: SignalKeyStore, logger: Logger, _cache?: CacheStore): SignalKeyStore;
10
- /**
11
- * Adds DB like transaction capability (https://en.wikipedia.org/wiki/Database_transaction) to the SignalKeyStore,
12
- * this allows batch read & write operations & improves the performance of the lib
13
- * @param state the key store to apply this capability to
14
- * @param logger logger to log events
15
- * @returns SignalKeyStore with transaction capability
16
- */
17
- export declare const addTransactionCapability: (state: SignalKeyStore, logger: Logger, { maxCommitRetries, delayBetweenTriesMs }: TransactionCapabilityOptions) => SignalKeyStoreWithTransaction;
18
- export declare const initAuthCreds: () => AuthenticationCreds;
@@ -1,16 +0,0 @@
1
- import type { BaileysEventEmitter } from '../Types';
2
- /**
3
- * Captures events from a baileys event emitter & stores them in a file
4
- * @param ev The event emitter to read events from
5
- * @param filename File to save to
6
- */
7
- export declare const captureEventStream: (ev: BaileysEventEmitter, filename: string) => void;
8
- /**
9
- * Read event file and emit events from there
10
- * @param filename filename containing event data
11
- * @param delayIntervalMs delay between each event emit
12
- */
13
- export declare const readAndEmitEventStream: (filename: string, delayIntervalMs?: number) => {
14
- ev: BaileysEventEmitter;
15
- task: Promise<void>;
16
- };
@@ -1,63 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.readAndEmitEventStream = exports.captureEventStream = void 0;
7
- const events_1 = __importDefault(require("events"));
8
- const fs_1 = require("fs");
9
- const promises_1 = require("fs/promises");
10
- const readline_1 = require("readline");
11
- const generics_1 = require("./generics");
12
- const make_mutex_1 = require("./make-mutex");
13
- /**
14
- * Captures events from a baileys event emitter & stores them in a file
15
- * @param ev The event emitter to read events from
16
- * @param filename File to save to
17
- */
18
- const captureEventStream = (ev, filename) => {
19
- const oldEmit = ev.emit;
20
- // write mutex so data is appended in order
21
- const writeMutex = (0, make_mutex_1.makeMutex)();
22
- // monkey patch eventemitter to capture all events
23
- ev.emit = function (...args) {
24
- const content = JSON.stringify({ timestamp: Date.now(), event: args[0], data: args[1] }) + '\n';
25
- const result = oldEmit.apply(ev, args);
26
- writeMutex.mutex(async () => {
27
- await (0, promises_1.writeFile)(filename, content, { flag: 'a' });
28
- });
29
- return result;
30
- };
31
- };
32
- exports.captureEventStream = captureEventStream;
33
- /**
34
- * Read event file and emit events from there
35
- * @param filename filename containing event data
36
- * @param delayIntervalMs delay between each event emit
37
- */
38
- const readAndEmitEventStream = (filename, delayIntervalMs = 0) => {
39
- const ev = new events_1.default();
40
- const fireEvents = async () => {
41
- // from: https://stackoverflow.com/questions/6156501/read-a-file-one-line-at-a-time-in-node-js
42
- const fileStream = (0, fs_1.createReadStream)(filename);
43
- const rl = (0, readline_1.createInterface)({
44
- input: fileStream,
45
- crlfDelay: Infinity
46
- });
47
- // Note: we use the crlfDelay option to recognize all instances of CR LF
48
- // ('\r\n') in input.txt as a single line break.
49
- for await (const line of rl) {
50
- if (line) {
51
- const { event, data } = JSON.parse(line);
52
- ev.emit(event, data);
53
- delayIntervalMs && await (0, generics_1.delay)(delayIntervalMs);
54
- }
55
- }
56
- fileStream.close();
57
- };
58
- return {
59
- ev,
60
- task: fireEvents()
61
- };
62
- };
63
- exports.readAndEmitEventStream = readAndEmitEventStream;
@@ -1,22 +0,0 @@
1
- import { CatalogCollection, OrderDetails, Product, ProductCreate, ProductUpdate, WAMediaUpload, WAMediaUploadFunction } from '../Types';
2
- import { BinaryNode } from '../WABinary';
3
- export declare const parseCatalogNode: (node: BinaryNode) => {
4
- products: Product[];
5
- nextPageCursor: string | undefined;
6
- };
7
- export declare const parseCollectionsNode: (node: BinaryNode) => {
8
- collections: CatalogCollection[];
9
- };
10
- export declare const parseOrderDetailsNode: (node: BinaryNode) => OrderDetails;
11
- export declare const toProductNode: (productId: string | undefined, product: ProductCreate | ProductUpdate) => BinaryNode;
12
- export declare const parseProductNode: (productNode: BinaryNode) => Product;
13
- /**
14
- * Uploads images not already uploaded to WA's servers
15
- */
16
- export declare function uploadingNecessaryImagesOfProduct<T extends ProductUpdate | ProductCreate>(product: T, waUploadToServer: WAMediaUploadFunction, timeoutMs?: number): Promise<T>;
17
- /**
18
- * Uploads images not already uploaded to WA's servers
19
- */
20
- export declare const uploadingNecessaryImages: (images: WAMediaUpload[], waUploadToServer: WAMediaUploadFunction, timeoutMs?: number) => Promise<{
21
- url: string;
22
- }[]>;