gifted-baileys 1.5.0 → 1.5.5

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 (222) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1429 -684
  3. package/package.json +11 -26
  4. package/src/Defaults/baileys-version.json +3 -0
  5. package/{lib → src}/Defaults/index.js +16 -8
  6. package/src/Defaults/index.ts +131 -0
  7. package/src/Defaults/phonenumber-mcc.json +223 -0
  8. package/src/Signal/libsignal.js +180 -0
  9. package/src/Signal/libsignal.ts +141 -0
  10. package/src/Socket/Client/abstract-socket-client.ts +19 -0
  11. package/src/Socket/Client/index.ts +3 -0
  12. package/src/Socket/Client/mobile-socket-client.js +78 -0
  13. package/src/Socket/Client/mobile-socket-client.ts +66 -0
  14. package/src/Socket/Client/web-socket-client.js +75 -0
  15. package/src/Socket/Client/web-socket-client.ts +57 -0
  16. package/{lib → src}/Socket/business.js +33 -27
  17. package/src/Socket/business.ts +281 -0
  18. package/{lib → src}/Socket/chats.js +197 -178
  19. package/src/Socket/chats.ts +1030 -0
  20. package/{lib → src}/Socket/groups.js +69 -79
  21. package/src/Socket/groups.ts +356 -0
  22. package/{lib → src}/Socket/index.js +1 -4
  23. package/src/Socket/index.ts +13 -0
  24. package/{lib → src}/Socket/messages-recv.js +160 -108
  25. package/src/Socket/messages-recv.ts +985 -0
  26. package/{lib → src}/Socket/messages-send.js +183 -100
  27. package/src/Socket/messages-send.ts +871 -0
  28. package/src/Socket/newsletter.js +227 -0
  29. package/src/Socket/newsletter.ts +282 -0
  30. package/{lib → src}/Socket/registration.js +55 -63
  31. package/src/Socket/registration.ts +250 -0
  32. package/{lib → src}/Socket/socket.js +107 -66
  33. package/src/Socket/socket.ts +777 -0
  34. package/src/Store/index.ts +3 -0
  35. package/{lib → src}/Store/make-cache-manager-store.js +34 -25
  36. package/src/Store/make-cache-manager-store.ts +100 -0
  37. package/{lib → src}/Store/make-in-memory-store.js +51 -61
  38. package/src/Store/make-in-memory-store.ts +475 -0
  39. package/src/Store/make-ordered-dictionary.ts +86 -0
  40. package/{lib → src}/Store/object-repository.js +1 -1
  41. package/src/Store/object-repository.ts +32 -0
  42. package/src/Tests/test.app-state-sync.js +204 -0
  43. package/src/Tests/test.app-state-sync.ts +207 -0
  44. package/src/Tests/test.event-buffer.js +270 -0
  45. package/src/Tests/test.event-buffer.ts +319 -0
  46. package/src/Tests/test.key-store.js +76 -0
  47. package/src/Tests/test.key-store.ts +92 -0
  48. package/src/Tests/test.libsignal.js +141 -0
  49. package/src/Tests/test.libsignal.ts +186 -0
  50. package/src/Tests/test.media-download.js +93 -0
  51. package/src/Tests/test.media-download.ts +76 -0
  52. package/src/Tests/test.messages.js +33 -0
  53. package/src/Tests/test.messages.ts +37 -0
  54. package/src/Tests/utils.js +34 -0
  55. package/src/Tests/utils.ts +36 -0
  56. package/src/Types/Auth.ts +113 -0
  57. package/src/Types/Call.ts +15 -0
  58. package/src/Types/Chat.ts +106 -0
  59. package/{lib/Types/Contact.d.ts → src/Types/Contact.ts} +9 -8
  60. package/src/Types/Events.ts +93 -0
  61. package/src/Types/GroupMetadata.ts +53 -0
  62. package/{lib → src}/Types/Label.js +1 -1
  63. package/src/Types/Label.ts +36 -0
  64. package/{lib → src}/Types/LabelAssociation.js +1 -1
  65. package/{lib/Types/LabelAssociation.d.ts → src/Types/LabelAssociation.ts} +22 -16
  66. package/src/Types/Message.ts +288 -0
  67. package/src/Types/Newsletter.js +32 -0
  68. package/src/Types/Newsletter.ts +98 -0
  69. package/src/Types/Product.ts +85 -0
  70. package/src/Types/Signal.ts +68 -0
  71. package/{lib/Types/Socket.d.ts → src/Types/Socket.ts} +68 -56
  72. package/src/Types/State.ts +29 -0
  73. package/{lib → src}/Types/index.js +2 -1
  74. package/src/Types/index.ts +59 -0
  75. package/{lib → src}/Utils/auth-utils.js +95 -76
  76. package/src/Utils/auth-utils.ts +222 -0
  77. package/src/Utils/baileys-event-stream.js +92 -0
  78. package/src/Utils/baileys-event-stream.ts +66 -0
  79. package/{lib → src}/Utils/business.js +45 -17
  80. package/src/Utils/business.ts +275 -0
  81. package/{lib → src}/Utils/chat-utils.js +74 -46
  82. package/src/Utils/chat-utils.ts +860 -0
  83. package/{lib → src}/Utils/crypto.js +31 -21
  84. package/src/Utils/crypto.ts +131 -0
  85. package/src/Utils/decode-wa-message.js +211 -0
  86. package/src/Utils/decode-wa-message.ts +228 -0
  87. package/{lib → src}/Utils/event-buffer.js +13 -4
  88. package/src/Utils/event-buffer.ts +613 -0
  89. package/{lib → src}/Utils/generics.js +98 -45
  90. package/src/Utils/generics.ts +434 -0
  91. package/{lib → src}/Utils/history.js +39 -10
  92. package/src/Utils/history.ts +112 -0
  93. package/src/Utils/index.ts +17 -0
  94. package/{lib → src}/Utils/link-preview.js +54 -17
  95. package/src/Utils/link-preview.ts +122 -0
  96. package/src/Utils/logger.ts +3 -0
  97. package/src/Utils/lt-hash.ts +61 -0
  98. package/{lib → src}/Utils/make-mutex.js +13 -4
  99. package/src/Utils/make-mutex.ts +44 -0
  100. package/{lib → src}/Utils/messages-media.js +296 -192
  101. package/src/Utils/messages-media.ts +847 -0
  102. package/{lib → src}/Utils/messages.js +124 -113
  103. package/src/Utils/messages.ts +956 -0
  104. package/{lib → src}/Utils/noise-handler.js +16 -3
  105. package/src/Utils/noise-handler.ts +197 -0
  106. package/{lib → src}/Utils/process-message.js +33 -29
  107. package/src/Utils/process-message.ts +414 -0
  108. package/{lib → src}/Utils/signal.js +23 -14
  109. package/src/Utils/signal.ts +177 -0
  110. package/{lib → src}/Utils/use-multi-file-auth-state.js +28 -19
  111. package/src/Utils/use-multi-file-auth-state.ts +90 -0
  112. package/{lib → src}/Utils/validate-connection.js +25 -42
  113. package/src/Utils/validate-connection.ts +238 -0
  114. package/src/WABinary/constants.ts +42 -0
  115. package/{lib → src}/WABinary/decode.js +17 -7
  116. package/src/WABinary/decode.ts +265 -0
  117. package/{lib → src}/WABinary/encode.js +17 -7
  118. package/src/WABinary/encode.ts +236 -0
  119. package/{lib → src}/WABinary/generic-utils.js +2 -2
  120. package/src/WABinary/generic-utils.ts +121 -0
  121. package/src/WABinary/index.ts +5 -0
  122. package/{lib → src}/WABinary/jid-utils.js +4 -1
  123. package/src/WABinary/jid-utils.ts +68 -0
  124. package/src/WABinary/types.ts +17 -0
  125. package/src/WAM/BinaryInfo.js +13 -0
  126. package/src/WAM/BinaryInfo.ts +12 -0
  127. package/src/WAM/constants.js +15350 -0
  128. package/src/WAM/constants.ts +15382 -0
  129. package/src/WAM/encode.js +155 -0
  130. package/src/WAM/encode.ts +174 -0
  131. package/src/WAM/index.js +19 -0
  132. package/src/WAM/index.ts +3 -0
  133. package/src/gifted +1 -0
  134. package/{lib → src}/index.js +1 -0
  135. package/src/index.ts +13 -0
  136. package/lib/Defaults/baileys-version.json +0 -3
  137. package/lib/Defaults/index.d.ts +0 -284
  138. package/lib/Defaults/phonenumber-mcc.json +0 -223
  139. package/lib/Signal/libsignal.d.ts +0 -3
  140. package/lib/Signal/libsignal.js +0 -152
  141. package/lib/Socket/Client/abstract-socket-client.d.ts +0 -17
  142. package/lib/Socket/Client/index.d.ts +0 -3
  143. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
  144. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  145. package/lib/Socket/Client/web-socket-client.d.ts +0 -12
  146. package/lib/Socket/Client/web-socket-client.js +0 -62
  147. package/lib/Socket/business.d.ts +0 -135
  148. package/lib/Socket/chats.d.ts +0 -79
  149. package/lib/Socket/groups.d.ts +0 -113
  150. package/lib/Socket/index.d.ts +0 -137
  151. package/lib/Socket/messages-recv.d.ts +0 -124
  152. package/lib/Socket/messages-send.d.ts +0 -119
  153. package/lib/Socket/registration.d.ts +0 -232
  154. package/lib/Socket/socket.d.ts +0 -42
  155. package/lib/Store/index.d.ts +0 -3
  156. package/lib/Store/make-cache-manager-store.d.ts +0 -13
  157. package/lib/Store/make-in-memory-store.d.ts +0 -117
  158. package/lib/Store/make-ordered-dictionary.d.ts +0 -13
  159. package/lib/Store/object-repository.d.ts +0 -10
  160. package/lib/Types/Auth.d.ts +0 -108
  161. package/lib/Types/Call.d.ts +0 -13
  162. package/lib/Types/Chat.d.ts +0 -102
  163. package/lib/Types/Events.d.ts +0 -157
  164. package/lib/Types/GroupMetadata.d.ts +0 -52
  165. package/lib/Types/Label.d.ts +0 -35
  166. package/lib/Types/Message.d.ts +0 -261
  167. package/lib/Types/Product.d.ts +0 -78
  168. package/lib/Types/Signal.d.ts +0 -57
  169. package/lib/Types/State.d.ts +0 -27
  170. package/lib/Types/index.d.ts +0 -56
  171. package/lib/Utils/auth-utils.d.ts +0 -18
  172. package/lib/Utils/baileys-event-stream.d.ts +0 -16
  173. package/lib/Utils/baileys-event-stream.js +0 -63
  174. package/lib/Utils/business.d.ts +0 -22
  175. package/lib/Utils/chat-utils.d.ts +0 -71
  176. package/lib/Utils/crypto.d.ts +0 -41
  177. package/lib/Utils/decode-wa-message.d.ts +0 -19
  178. package/lib/Utils/decode-wa-message.js +0 -174
  179. package/lib/Utils/event-buffer.d.ts +0 -35
  180. package/lib/Utils/generics.d.ts +0 -94
  181. package/lib/Utils/history.d.ts +0 -15
  182. package/lib/Utils/index.d.ts +0 -17
  183. package/lib/Utils/link-preview.d.ts +0 -21
  184. package/lib/Utils/logger.d.ts +0 -4
  185. package/lib/Utils/lt-hash.d.ts +0 -12
  186. package/lib/Utils/make-mutex.d.ts +0 -7
  187. package/lib/Utils/messages-media.d.ts +0 -107
  188. package/lib/Utils/messages.d.ts +0 -76
  189. package/lib/Utils/noise-handler.d.ts +0 -20
  190. package/lib/Utils/process-message.d.ts +0 -41
  191. package/lib/Utils/signal.d.ts +0 -32
  192. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -12
  193. package/lib/Utils/validate-connection.d.ts +0 -11
  194. package/lib/WABinary/constants.d.ts +0 -27
  195. package/lib/WABinary/decode.d.ts +0 -7
  196. package/lib/WABinary/encode.d.ts +0 -3
  197. package/lib/WABinary/generic-utils.d.ts +0 -15
  198. package/lib/WABinary/index.d.ts +0 -5
  199. package/lib/WABinary/jid-utils.d.ts +0 -29
  200. package/lib/WABinary/types.d.ts +0 -18
  201. package/lib/index.d.ts +0 -10
  202. /package/{lib → src}/Socket/Client/abstract-socket-client.js +0 -0
  203. /package/{lib → src}/Socket/Client/index.js +0 -0
  204. /package/{lib → src}/Store/index.js +0 -0
  205. /package/{lib → src}/Store/make-ordered-dictionary.js +0 -0
  206. /package/{lib → src}/Types/Auth.js +0 -0
  207. /package/{lib → src}/Types/Call.js +0 -0
  208. /package/{lib → src}/Types/Chat.js +0 -0
  209. /package/{lib → src}/Types/Contact.js +0 -0
  210. /package/{lib → src}/Types/Events.js +0 -0
  211. /package/{lib → src}/Types/GroupMetadata.js +0 -0
  212. /package/{lib → src}/Types/Message.js +0 -0
  213. /package/{lib → src}/Types/Product.js +0 -0
  214. /package/{lib → src}/Types/Signal.js +0 -0
  215. /package/{lib → src}/Types/Socket.js +0 -0
  216. /package/{lib → src}/Types/State.js +0 -0
  217. /package/{lib → src}/Utils/index.js +0 -0
  218. /package/{lib → src}/Utils/logger.js +0 -0
  219. /package/{lib → src}/Utils/lt-hash.js +0 -0
  220. /package/{lib → src}/WABinary/constants.js +0 -0
  221. /package/{lib → src}/WABinary/index.js +0 -0
  222. /package/{lib → src}/WABinary/types.js +0 -0
@@ -0,0 +1,106 @@
1
+ import type { proto } from '../../WAProto'
2
+ import type { AccountSettings } from './Auth'
3
+ import type { BufferedEventData } from './Events'
4
+ import type { ChatLabelAssociationActionBody } from './LabelAssociation'
5
+ import type { MessageLabelAssociationActionBody } from './LabelAssociation'
6
+ import type { MinimalMessage } from './Message'
7
+
8
+ /** privacy settings in WhatsApp Web */
9
+ export type WAPrivacyValue = 'all' | 'contacts' | 'contact_blacklist' | 'none'
10
+
11
+ export type WAPrivacyOnlineValue = 'all' | 'match_last_seen'
12
+
13
+ export type WAReadReceiptsValue = 'all' | 'none'
14
+
15
+ /** set of statuses visible to other people; see updatePresence() in WhatsAppWeb.Send */
16
+ export type WAPresence = 'unavailable' | 'available' | 'composing' | 'recording' | 'paused'
17
+
18
+ export const ALL_WA_PATCH_NAMES = ['critical_block', 'critical_unblock_low', 'regular_high', 'regular_low', 'regular'] as const
19
+
20
+ export type WAPatchName = typeof ALL_WA_PATCH_NAMES[number]
21
+
22
+ export interface PresenceData {
23
+ lastKnownPresence: WAPresence
24
+ lastSeen?: number
25
+ }
26
+
27
+ export type ChatMutation = {
28
+ syncAction: proto.ISyncActionData
29
+ index: string[]
30
+ }
31
+
32
+ export type WAPatchCreate = {
33
+ syncAction: proto.ISyncActionValue
34
+ index: string[]
35
+ type: WAPatchName
36
+ apiVersion: number
37
+ operation: proto.SyncdMutation.SyncdOperation
38
+ }
39
+
40
+ export type Chat = proto.IConversation & {
41
+ /** unix timestamp of when the last message was received in the chat */
42
+ lastMessageRecvTimestamp?: number
43
+ }
44
+
45
+ export type ChatUpdate = Partial<Chat & {
46
+ /**
47
+ * if specified in the update,
48
+ * the EV buffer will check if the condition gets fulfilled before applying the update
49
+ * Right now, used to determine when to release an app state sync event
50
+ *
51
+ * @returns true, if the update should be applied;
52
+ * false if it can be discarded;
53
+ * undefined if the condition is not yet fulfilled
54
+ * */
55
+ conditional: (bufferedData: BufferedEventData) => boolean | undefined
56
+ }>
57
+
58
+ /**
59
+ * the last messages in a chat, sorted reverse-chronologically. That is, the latest message should be first in the chat
60
+ * for MD modifications, the last message in the array (i.e. the earlist message) must be the last message recv in the chat
61
+ * */
62
+ export type LastMessageList = MinimalMessage[] | proto.SyncActionValue.ISyncActionMessageRange
63
+
64
+ export type ChatModification =
65
+ {
66
+ archive: boolean
67
+ lastMessages: LastMessageList
68
+ }
69
+ | { pushNameSetting: string }
70
+ | { pin: boolean }
71
+ | {
72
+ /** mute for duration, or provide timestamp of mute to remove*/
73
+ mute: number | null
74
+ }
75
+ | {
76
+ clear: 'all' | { messages: { id: string, fromMe?: boolean, timestamp: number }[] }
77
+ }
78
+ | {
79
+ star: {
80
+ messages: { id: string, fromMe?: boolean }[]
81
+ star: boolean
82
+ }
83
+ }
84
+ | {
85
+ markRead: boolean
86
+ lastMessages: LastMessageList
87
+ }
88
+ | { delete: true, lastMessages: LastMessageList }
89
+ // Label assosiation
90
+ | { addChatLabel: ChatLabelAssociationActionBody }
91
+ | { removeChatLabel: ChatLabelAssociationActionBody }
92
+ | { addMessageLabel: MessageLabelAssociationActionBody }
93
+ | { removeMessageLabel: MessageLabelAssociationActionBody }
94
+
95
+ export type InitialReceivedChatsState = {
96
+ [jid: string]: {
97
+ /** the last message received from the other party */
98
+ lastMsgRecvTimestamp?: number
99
+ /** the absolute last message in the chat */
100
+ lastMsgTimestamp: number
101
+ }
102
+ }
103
+
104
+ export type InitialAppStateSyncOptions = {
105
+ accountSettings: AccountSettings
106
+ }
@@ -1,12 +1,13 @@
1
1
  export interface Contact {
2
- id: string;
3
- lid?: string;
2
+ id: string
3
+ lid?: string
4
4
  /** name of the contact, you have saved on your WA */
5
- name?: string;
5
+ name?: string
6
6
  /** name of the contact, the contact has set on their own on WA */
7
- notify?: string;
7
+ notify?: string
8
8
  /** I have no idea */
9
- verifiedName?: string;
9
+ verifiedName?: string
10
+ // Baileys Added
10
11
  /**
11
12
  * Url of the profile picture of the contact
12
13
  *
@@ -14,6 +15,6 @@ export interface Contact {
14
15
  * null => if the profile picture has not been set (default profile picture)
15
16
  * any other string => url of the profile picture
16
17
  */
17
- imgUrl?: string | null | 'changed';
18
- status?: string;
19
- }
18
+ imgUrl?: string | null | 'changed'
19
+ status?: string
20
+ }
@@ -0,0 +1,93 @@
1
+ import type { Boom } from '@hapi/boom'
2
+ import { proto } from '../../WAProto'
3
+ import { AuthenticationCreds } from './Auth'
4
+ import { WACallEvent } from './Call'
5
+ import { Chat, ChatUpdate, PresenceData } from './Chat'
6
+ import { Contact } from './Contact'
7
+ import { GroupMetadata, ParticipantAction } from './GroupMetadata'
8
+ import { Label } from './Label'
9
+ import { LabelAssociation } from './LabelAssociation'
10
+ import { MessageUpsertType, MessageUserReceiptUpdate, WAMessage, WAMessageKey, WAMessageUpdate } from './Message'
11
+ import { ConnectionState } from './State'
12
+
13
+ export type BaileysEventMap = {
14
+ /** connection state has been updated -- WS closed, opened, connecting etc. */
15
+ 'connection.update': Partial<ConnectionState>
16
+ /** credentials updated -- some metadata, keys or something */
17
+ 'creds.update': Partial<AuthenticationCreds>
18
+ /** set chats (history sync), everything is reverse chronologically sorted */
19
+ 'messaging-history.set': {
20
+ chats: Chat[]
21
+ contacts: Contact[]
22
+ messages: WAMessage[]
23
+ isLatest: boolean
24
+ }
25
+ /** upsert chats */
26
+ 'chats.upsert': Chat[]
27
+ /** update the given chats */
28
+ 'chats.update': ChatUpdate[]
29
+ 'chats.phoneNumberShare': {lid: string, jid: string}
30
+ /** delete chats with given ID */
31
+ 'chats.delete': string[]
32
+ /** presence of contact in a chat updated */
33
+ 'presence.update': { id: string, presences: { [participant: string]: PresenceData } }
34
+
35
+ 'contacts.upsert': Contact[]
36
+ 'contacts.update': Partial<Contact>[]
37
+
38
+ 'messages.delete': { keys: WAMessageKey[] } | { jid: string, all: true }
39
+ 'messages.update': WAMessageUpdate[]
40
+ 'messages.media-update': { key: WAMessageKey, media?: { ciphertext: Uint8Array, iv: Uint8Array }, error?: Boom }[]
41
+ /**
42
+ * add/update the given messages. If they were received while the connection was online,
43
+ * the update will have type: "notify"
44
+ * */
45
+ 'messages.upsert': { messages: WAMessage[], type: MessageUpsertType }
46
+ /** message was reacted to. If reaction was removed -- then "reaction.text" will be falsey */
47
+ 'messages.reaction': { key: WAMessageKey, reaction: proto.IReaction }[]
48
+
49
+ 'message-receipt.update': MessageUserReceiptUpdate[]
50
+
51
+ 'groups.upsert': GroupMetadata[]
52
+ 'groups.update': Partial<GroupMetadata>[]
53
+ /** apply an action to participants in a group */
54
+ 'group-participants.update': { id: string, author: string, participants: string[], action: ParticipantAction }
55
+
56
+ 'blocklist.set': { blocklist: string[] }
57
+ 'blocklist.update': { blocklist: string[], type: 'add' | 'remove' }
58
+
59
+ /** Receive an update on a call, including when the call was received, rejected, accepted */
60
+ 'call': WACallEvent[]
61
+ 'labels.edit': Label
62
+ 'labels.association': { association: LabelAssociation, type: 'add' | 'remove' }
63
+ }
64
+
65
+ export type BufferedEventData = {
66
+ historySets: {
67
+ chats: { [jid: string]: Chat }
68
+ contacts: { [jid: string]: Contact }
69
+ messages: { [uqId: string]: WAMessage }
70
+ empty: boolean
71
+ isLatest: boolean
72
+ }
73
+ chatUpserts: { [jid: string]: Chat }
74
+ chatUpdates: { [jid: string]: ChatUpdate }
75
+ chatDeletes: Set<string>
76
+ contactUpserts: { [jid: string]: Contact }
77
+ contactUpdates: { [jid: string]: Partial<Contact> }
78
+ messageUpserts: { [key: string]: { type: MessageUpsertType, message: WAMessage } }
79
+ messageUpdates: { [key: string]: WAMessageUpdate }
80
+ messageDeletes: { [key: string]: WAMessageKey }
81
+ messageReactions: { [key: string]: { key: WAMessageKey, reactions: proto.IReaction[] } }
82
+ messageReceipts: { [key: string]: { key: WAMessageKey, userReceipt: proto.IUserReceipt[] } }
83
+ groupUpdates: { [jid: string]: Partial<GroupMetadata> }
84
+ }
85
+
86
+ export type BaileysEvent = keyof BaileysEventMap
87
+
88
+ export interface BaileysEventEmitter {
89
+ on<T extends keyof BaileysEventMap>(event: T, listener: (arg: BaileysEventMap[T]) => void): void
90
+ off<T extends keyof BaileysEventMap>(event: T, listener: (arg: BaileysEventMap[T]) => void): void
91
+ removeAllListeners<T extends keyof BaileysEventMap>(event: T): void
92
+ emit<T extends keyof BaileysEventMap>(event: T, arg: BaileysEventMap[T]): boolean
93
+ }
@@ -0,0 +1,53 @@
1
+ import { Contact } from './Contact'
2
+
3
+ export type GroupParticipant = (Contact & { isAdmin?: boolean, isSuperAdmin?: boolean, admin?: 'admin' | 'superadmin' | null })
4
+
5
+ export type ParticipantAction = 'add' | 'remove' | 'promote' | 'demote'
6
+
7
+ export interface GroupMetadata {
8
+ id: string
9
+ owner: string | undefined
10
+ subject: string
11
+ /** group subject owner */
12
+ subjectOwner?: string
13
+ /** group subject modification date */
14
+ subjectTime?: number
15
+ creation?: number
16
+ desc?: string
17
+ descOwner?: string
18
+ descId?: string
19
+ /** if this group is part of a community, it returns the jid of the community to which it belongs */
20
+ linkedParent?: string
21
+ /** is set when the group only allows admins to change group settings */
22
+ restrict?: boolean
23
+ /** is set when the group only allows admins to write messages */
24
+ announce?: boolean
25
+ /** is set when the group also allows members to add participants */
26
+ memberAddMode?: boolean
27
+ /** Request approval to join the group */
28
+ joinApprovalMode?: boolean
29
+ /** is this a community */
30
+ isCommunity?: boolean
31
+ /** is this the announce of a community */
32
+ isCommunityAnnounce?: boolean
33
+ /** number of group participants */
34
+ size?: number
35
+ // Baileys modified array
36
+ participants: GroupParticipant[]
37
+ ephemeralDuration?: number
38
+ inviteCode?: string
39
+ /** the person who added you to group or changed some setting in group */
40
+ author?: string
41
+ }
42
+
43
+
44
+ export interface WAGroupCreateResponse {
45
+ status: number
46
+ gid?: string
47
+ participants?: [{ [key: string]: {} }]
48
+ }
49
+
50
+ export interface GroupModificationResponse {
51
+ status: number
52
+ participants?: { [key: string]: {} }
53
+ }
@@ -24,4 +24,4 @@ var LabelColor;
24
24
  LabelColor[LabelColor["Color18"] = 17] = "Color18";
25
25
  LabelColor[LabelColor["Color19"] = 18] = "Color19";
26
26
  LabelColor[LabelColor["Color20"] = 19] = "Color20";
27
- })(LabelColor = exports.LabelColor || (exports.LabelColor = {}));
27
+ })(LabelColor || (exports.LabelColor = LabelColor = {}));
@@ -0,0 +1,36 @@
1
+ export interface Label {
2
+ /** Label uniq ID */
3
+ id: string
4
+ /** Label name */
5
+ name: string
6
+ /** Label color ID */
7
+ color: number
8
+ /** Is label has been deleted */
9
+ deleted: boolean
10
+ /** WhatsApp has 5 predefined labels (New customer, New order & etc) */
11
+ predefinedId?: string
12
+ }
13
+
14
+ /** WhatsApp has 20 predefined colors */
15
+ export enum LabelColor {
16
+ Color1 = 0,
17
+ Color2,
18
+ Color3,
19
+ Color4,
20
+ Color5,
21
+ Color6,
22
+ Color7,
23
+ Color8,
24
+ Color9,
25
+ Color10,
26
+ Color11,
27
+ Color12,
28
+ Color13,
29
+ Color14,
30
+ Color15,
31
+ Color16,
32
+ Color17,
33
+ Color18,
34
+ Color19,
35
+ Color20,
36
+ }
@@ -6,4 +6,4 @@ var LabelAssociationType;
6
6
  (function (LabelAssociationType) {
7
7
  LabelAssociationType["Chat"] = "label_jid";
8
8
  LabelAssociationType["Message"] = "label_message";
9
- })(LabelAssociationType = exports.LabelAssociationType || (exports.LabelAssociationType = {}));
9
+ })(LabelAssociationType || (exports.LabelAssociationType = LabelAssociationType = {}));
@@ -1,29 +1,35 @@
1
1
  /** Association type */
2
- export declare enum LabelAssociationType {
3
- Chat = "label_jid",
4
- Message = "label_message"
2
+ export enum LabelAssociationType {
3
+ Chat = 'label_jid',
4
+ Message = 'label_message'
5
5
  }
6
- export type LabelAssociationTypes = `${LabelAssociationType}`;
6
+
7
+ export type LabelAssociationTypes = `${LabelAssociationType}`
8
+
7
9
  /** Association for chat */
8
10
  export interface ChatLabelAssociation {
9
- type: LabelAssociationType.Chat;
10
- chatId: string;
11
- labelId: string;
11
+ type: LabelAssociationType.Chat
12
+ chatId: string
13
+ labelId: string
12
14
  }
15
+
13
16
  /** Association for message */
14
17
  export interface MessageLabelAssociation {
15
- type: LabelAssociationType.Message;
16
- chatId: string;
17
- messageId: string;
18
- labelId: string;
18
+ type: LabelAssociationType.Message
19
+ chatId: string
20
+ messageId: string
21
+ labelId: string
19
22
  }
20
- export type LabelAssociation = ChatLabelAssociation | MessageLabelAssociation;
23
+
24
+ export type LabelAssociation = ChatLabelAssociation | MessageLabelAssociation
25
+
21
26
  /** Body for add/remove chat label association action */
22
27
  export interface ChatLabelAssociationActionBody {
23
- labelId: string;
28
+ labelId: string
24
29
  }
30
+
25
31
  /** body for add/remove message label association action */
26
32
  export interface MessageLabelAssociationActionBody {
27
- labelId: string;
28
- messageId: string;
29
- }
33
+ labelId: string
34
+ messageId: string
35
+ }
@@ -0,0 +1,288 @@
1
+ import { AxiosRequestConfig } from 'axios'
2
+ import type { Logger } from 'pino'
3
+ import type { Readable } from 'stream'
4
+ import type { URL } from 'url'
5
+ import { BinaryNode } from '../WABinary'
6
+ import { proto } from '../../WAProto'
7
+ import { MEDIA_HKDF_KEY_MAPPING } from '../Defaults'
8
+ import type { GroupMetadata } from './GroupMetadata'
9
+ import { CacheStore } from './Socket'
10
+
11
+ // export the WAMessage Prototypes
12
+ export { proto as WAProto }
13
+ export type WAMessage = proto.IWebMessageInfo
14
+ export type WAMessageContent = proto.IMessage
15
+ export type WAContactMessage = proto.Message.IContactMessage
16
+ export type WAContactsArrayMessage = proto.Message.IContactsArrayMessage
17
+ export type WAMessageKey = proto.IMessageKey
18
+ export type WATextMessage = proto.Message.IExtendedTextMessage
19
+ export type WAContextInfo = proto.IContextInfo
20
+ export type WALocationMessage = proto.Message.ILocationMessage
21
+ export type WAGenericMediaMessage = proto.Message.IVideoMessage | proto.Message.IImageMessage | proto.Message.IAudioMessage | proto.Message.IDocumentMessage | proto.Message.IStickerMessage
22
+ // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
23
+ export import WAMessageStubType = proto.WebMessageInfo.StubType
24
+ // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
25
+ export import WAMessageStatus = proto.WebMessageInfo.Status
26
+ export type WAMediaUpload = Buffer | { url: URL | string } | { stream: Readable }
27
+ /** Set of message types that are supported by the library */
28
+ export type MessageType = keyof proto.Message
29
+
30
+ export type DownloadableMessage = { mediaKey?: Uint8Array | null, directPath?: string | null, url?: string | null }
31
+
32
+ export type MessageReceiptType = 'read' | 'read-self' | 'hist_sync' | 'peer_msg' | 'sender' | 'inactive' | 'played' | undefined
33
+
34
+ export type MediaConnInfo = {
35
+ auth: string
36
+ ttl: number
37
+ hosts: { hostname: string, maxContentLengthBytes: number }[]
38
+ fetchDate: Date
39
+ }
40
+
41
+ export interface WAUrlInfo {
42
+ 'canonical-url': string
43
+ 'matched-text': string
44
+ title: string
45
+ description?: string
46
+ jpegThumbnail?: Buffer
47
+ highQualityThumbnail?: proto.Message.IImageMessage
48
+ originalThumbnailUrl?: string
49
+ }
50
+
51
+ // types to generate WA messages
52
+ type Mentionable = {
53
+ /** list of jids that are mentioned in the accompanying text */
54
+ mentions?: string[]
55
+ }
56
+ type Contextable = {
57
+ /** add contextInfo to the message */
58
+ contextInfo?: proto.IContextInfo
59
+ }
60
+ type ViewOnce = {
61
+ viewOnce?: boolean
62
+ }
63
+
64
+ type Buttonable = {
65
+ /** add buttons to the message */
66
+ buttons?: proto.Message.ButtonsMessage.IButton[]
67
+ }
68
+ type Templatable = {
69
+ /** add buttons to the message (conflicts with normal buttons)*/
70
+ templateButtons?: proto.IHydratedTemplateButton[]
71
+
72
+ footer?: string
73
+ }
74
+ type Editable = {
75
+ edit?: WAMessageKey
76
+ }
77
+ type Listable = {
78
+ /** Sections of the List */
79
+ sections?: proto.Message.ListMessage.ISection[]
80
+
81
+ /** Title of a List Message only */
82
+ title?: string
83
+
84
+ /** Text of the bnutton on the list (required) */
85
+ buttonText?: string
86
+ }
87
+ type WithDimensions = {
88
+ width?: number
89
+ height?: number
90
+ }
91
+
92
+ export type PollMessageOptions = {
93
+ name: string
94
+ selectableCount?: number
95
+ values: string[]
96
+ /** 32 byte message secret to encrypt poll selections */
97
+ messageSecret?: Uint8Array
98
+ }
99
+
100
+ type SharePhoneNumber = {
101
+ sharePhoneNumber: boolean
102
+ }
103
+
104
+ type RequestPhoneNumber = {
105
+ requestPhoneNumber: boolean
106
+ }
107
+
108
+ export type MediaType = keyof typeof MEDIA_HKDF_KEY_MAPPING
109
+ export type AnyMediaMessageContent = (
110
+ ({
111
+ image: WAMediaUpload
112
+ caption?: string
113
+ jpegThumbnail?: string
114
+ } & Mentionable & Contextable & Buttonable & Templatable & WithDimensions)
115
+ | ({
116
+ video: WAMediaUpload
117
+ caption?: string
118
+ gifPlayback?: boolean
119
+ jpegThumbnail?: string
120
+ /** if set to true, will send as a `video note` */
121
+ ptv?: boolean
122
+ } & Mentionable & Contextable & Buttonable & Templatable & WithDimensions)
123
+ | {
124
+ audio: WAMediaUpload
125
+ /** if set to true, will send as a `voice note` */
126
+ ptt?: boolean
127
+ /** optionally tell the duration of the audio */
128
+ seconds?: number
129
+ }
130
+ | ({
131
+ sticker: WAMediaUpload
132
+ isAnimated?: boolean
133
+ } & WithDimensions) | ({
134
+ document: WAMediaUpload
135
+ mimetype: string
136
+ fileName?: string
137
+ caption?: string
138
+ } & Contextable & Buttonable & Templatable))
139
+ & { mimetype?: string } & Editable
140
+
141
+ export type ButtonReplyInfo = {
142
+ displayText: string
143
+ id: string
144
+ index: number
145
+ }
146
+
147
+ export type WASendableProduct = Omit<proto.Message.ProductMessage.IProductSnapshot, 'productImage'> & {
148
+ productImage: WAMediaUpload
149
+ }
150
+
151
+ export type AnyRegularMessageContent = (
152
+ ({
153
+ text: string
154
+ linkPreview?: WAUrlInfo | null
155
+ }
156
+ & Mentionable & Contextable & Buttonable & Templatable & Listable & Editable)
157
+ | AnyMediaMessageContent
158
+ | ({
159
+ poll: PollMessageOptions
160
+ } & Mentionable & Contextable & Buttonable & Templatable & Editable)
161
+ | {
162
+ contacts: {
163
+ displayName?: string
164
+ contacts: proto.Message.IContactMessage[]
165
+ }
166
+ }
167
+ | {
168
+ location: WALocationMessage
169
+ }
170
+ | { react: proto.Message.IReactionMessage }
171
+ | {
172
+ buttonReply: ButtonReplyInfo
173
+ type: 'template' | 'plain'
174
+ }
175
+ | {
176
+ listReply: Omit<proto.Message.IListResponseMessage, 'contextInfo'>
177
+ }
178
+ | {
179
+ product: WASendableProduct
180
+ businessOwnerJid?: string
181
+ body?: string
182
+ footer?: string
183
+ } | SharePhoneNumber | RequestPhoneNumber
184
+ ) & ViewOnce
185
+
186
+ export type AnyMessageContent = AnyRegularMessageContent | {
187
+ forward: WAMessage
188
+ force?: boolean
189
+ } | {
190
+ /** Delete your message or anyone's message in a group (admin required) */
191
+ delete: WAMessageKey
192
+ } | {
193
+ disappearingMessagesInChat: boolean | number
194
+ }
195
+
196
+ export type GroupMetadataParticipants = Pick<GroupMetadata, 'participants'>
197
+
198
+ type MinimalRelayOptions = {
199
+ /** override the message ID with a custom provided string */
200
+ messageId?: string
201
+ /** cached group metadata, use to prevent redundant requests to WA & speed up msg sending */
202
+ cachedGroupMetadata?: (jid: string) => Promise<GroupMetadataParticipants | undefined>
203
+ }
204
+
205
+ export type MessageRelayOptions = MinimalRelayOptions & {
206
+ /** only send to a specific participant; used when a message decryption fails for a single user */
207
+ participant?: { jid: string, count: number }
208
+ /** additional attributes to add to the WA binary node */
209
+ additionalAttributes?: { [_: string]: string }
210
+ additionalNodes?: BinaryNode[];
211
+ /** should we use the devices cache, or fetch afresh from the server; default assumed to be "true" */
212
+ useUserDevicesCache?: boolean
213
+ /** jid list of participants for status@broadcast */
214
+ statusJidList?: string[]
215
+ }
216
+
217
+ export type MiscMessageGenerationOptions = MinimalRelayOptions & {
218
+ /** optional, if you want to manually set the timestamp of the message */
219
+ timestamp?: Date
220
+ /** the message you want to quote */
221
+ quoted?: WAMessage
222
+ additionalNodes?: BinaryNode[];
223
+ /** disappearing messages settings */
224
+ ephemeralExpiration?: number | string
225
+ /** timeout for media upload to WA server */
226
+ mediaUploadTimeoutMs?: number
227
+ /** jid list of participants for status@broadcast */
228
+ statusJidList?: string[]
229
+ /** backgroundcolor for status */
230
+ backgroundColor?: string
231
+ /** font type for status */
232
+ font?: number
233
+ /** if it is broadcast */
234
+ broadcast?: boolean
235
+ }
236
+ export type MessageGenerationOptionsFromContent = MiscMessageGenerationOptions & {
237
+ userJid: string
238
+ }
239
+
240
+ export type WAMediaUploadFunctionOpts = { fileEncSha256B64: string, mediaType: MediaType, newsletter?: boolean, timeoutMs?: number }
241
+
242
+ export type WAMediaUploadFunction = (readStream: Readable | Buffer, opts: WAMediaUploadFunctionOpts) => Promise<{ mediaUrl: string, directPath: string, handle?: string }>
243
+
244
+ export type MediaGenerationOptions = {
245
+ logger?: Logger
246
+ mediaTypeOverride?: MediaType
247
+ upload: WAMediaUploadFunction
248
+ /** cache media so it does not have to be uploaded again */
249
+ mediaCache?: CacheStore
250
+
251
+ mediaUploadTimeoutMs?: number
252
+
253
+ options?: AxiosRequestConfig
254
+
255
+ backgroundColor?: string
256
+
257
+ font?: number
258
+
259
+ /** The message is for newsletter? */
260
+ newsletter?: boolean
261
+ }
262
+ export type MessageContentGenerationOptions = MediaGenerationOptions & {
263
+ getUrlInfo?: (text: string) => Promise<WAUrlInfo | undefined>
264
+ }
265
+ export type MessageGenerationOptions = MessageContentGenerationOptions & MessageGenerationOptionsFromContent
266
+
267
+ /**
268
+ * Type of message upsert
269
+ * 1. notify => notify the user, this message was just received
270
+ * 2. append => append the message to the chat history, no notification required
271
+ */
272
+ export type MessageUpsertType = 'append' | 'notify'
273
+
274
+ export type MessageUserReceipt = proto.IUserReceipt
275
+
276
+ export type WAMessageUpdate = { update: Partial<WAMessage>, key: proto.IMessageKey }
277
+
278
+ export type WAMessageCursor = { before: WAMessageKey | undefined } | { after: WAMessageKey | undefined }
279
+
280
+ export type MessageUserReceiptUpdate = { key: proto.IMessageKey, receipt: MessageUserReceipt }
281
+
282
+ export type MediaDecryptionKeyInfo = {
283
+ iv: Buffer
284
+ cipherKey: Buffer
285
+ macKey?: Buffer
286
+ }
287
+
288
+ export type MinimalMessage = Pick<proto.IWebMessageInfo, 'key' | 'messageTimestamp'>