@itznomo/baileys 0.0.0-stage → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/BUTTONS.md +153 -0
  2. package/Example/call-bot.mjs +38 -0
  3. package/Example/example.mjs +36 -0
  4. package/Example/full-bot-commands.mjs +319 -0
  5. package/Example/full-bot.mjs +77 -0
  6. package/LICENSE +21 -0
  7. package/README.md +543 -2
  8. package/WAProto/@dnuzi +1 -0
  9. package/WAProto/index.d.ts +15932 -0
  10. package/WAProto/index.js +113300 -0
  11. package/assets/banner.svg +17 -0
  12. package/assets/devider.svg +1 -0
  13. package/assets/features.svg +21 -0
  14. package/docs/CALLS.md +106 -0
  15. package/docs/FEATURES.md +1152 -0
  16. package/engine-requirements.js +19 -0
  17. package/index.d.ts +815 -0
  18. package/package.json +51 -4
  19. package/src/binary/wa-binary-constants.js +1300 -0
  20. package/src/binary/wa-binary.js +627 -0
  21. package/src/constants.js +147 -0
  22. package/src/defaults.js +106 -0
  23. package/src/foundation/ai-rich.js +654 -0
  24. package/src/foundation/audio-duration.js +470 -0
  25. package/src/foundation/audio-samples.js +250 -0
  26. package/src/foundation/boom.js +39 -0
  27. package/src/foundation/builders.js +851 -0
  28. package/src/foundation/cache.js +134 -0
  29. package/src/foundation/concurrency.js +69 -0
  30. package/src/foundation/curve25519.js +189 -0
  31. package/src/foundation/image-thumb.js +65 -0
  32. package/src/foundation/link-preview.js +278 -0
  33. package/src/foundation/logger.js +78 -0
  34. package/src/foundation/long.js +130 -0
  35. package/src/foundation/performance.js +385 -0
  36. package/src/foundation/protobuf-minimal.js +587 -0
  37. package/src/foundation/qrcode-terminal.js +273 -0
  38. package/src/foundation/sql-database.js +716 -0
  39. package/src/foundation/wa-crypto.js +47 -0
  40. package/src/foundation/zip.js +108 -0
  41. package/src/index.js +67 -0
  42. package/src/signal/libsignal.js +996 -0
  43. package/src/signal/signal-group.js +455 -0
  44. package/src/signal/signal-repository.js +635 -0
  45. package/src/socket/business-communities.js +811 -0
  46. package/src/socket/chats.js +702 -0
  47. package/src/socket/groups-newsletter.js +524 -0
  48. package/src/socket/messages-recv.js +1815 -0
  49. package/src/socket/messages-send.js +1526 -0
  50. package/src/socket/socket-builder.js +131 -0
  51. package/src/socket/socket-core.js +913 -0
  52. package/src/socket/usync.js +287 -0
  53. package/src/socket-client/native-websocket.js +344 -0
  54. package/src/socket-client/websocket-client.js +170 -0
  55. package/src/utils/auth-state-core.js +731 -0
  56. package/src/utils/auth-state-storage.js +594 -0
  57. package/src/utils/chat-sync.js +1046 -0
  58. package/src/utils/check-status.js +159 -0
  59. package/src/utils/cstoken.js +17 -0
  60. package/src/utils/media.js +807 -0
  61. package/src/utils/message-compose.js +1747 -0
  62. package/src/utils/message-processing.js +912 -0
  63. package/src/utils/modern-messages.js +435 -0
  64. package/src/utils/nomo-buttons.js +138 -0
  65. package/src/utils/nomo-commands.js +168 -0
  66. package/src/utils/spam-report-utils.js +136 -0
  67. package/src/utils/use-keyv-auth-state.js +307 -0
  68. package/src/utils/username.js +19 -0
  69. package/src/utils/wa-protocol-core.js +1227 -0
  70. package/src/voip/WaVoipCoordinator.js +158 -0
  71. package/src/voip/app-data/WaAppDataStream.js +193 -0
  72. package/src/voip/app-data/protocol.js +172 -0
  73. package/src/voip/auto.js +139 -0
  74. package/src/voip/bytes.js +63 -0
  75. package/src/voip/call/WaCallManager.js +442 -0
  76. package/src/voip/call/WaCallMediaSession.js +1727 -0
  77. package/src/voip/call/call-state.js +203 -0
  78. package/src/voip/crypto/encryption.js +13 -0
  79. package/src/voip/crypto/primitives.js +21 -0
  80. package/src/voip/crypto/rtcp.js +66 -0
  81. package/src/voip/crypto/srtp.js +180 -0
  82. package/src/voip/crypto/ssrc.js +15 -0
  83. package/src/voip/index.js +730 -0
  84. package/src/voip/media/WaAudioEngine.js +486 -0
  85. package/src/voip/media/WaVideoEngine.js +275 -0
  86. package/src/voip/media/audio-codec.js +0 -0
  87. package/src/voip/media/audio-reorder.js +107 -0
  88. package/src/voip/media/h264.js +246 -0
  89. package/src/voip/media/mlow-codec.js +465 -0
  90. package/src/voip/media/rtcp.js +68 -0
  91. package/src/voip/media/rtp.js +242 -0
  92. package/src/voip/protobuf.js +30 -0
  93. package/src/voip/relay/WaManualRelay.js +609 -0
  94. package/src/voip/relay/datachannel/pre-negotiated.js +25 -0
  95. package/src/voip/relay/dtls/aead.js +46 -0
  96. package/src/voip/relay/dtls/cert-builder.js +102 -0
  97. package/src/voip/relay/dtls/der.js +98 -0
  98. package/src/voip/relay/dtls/ecdhe.js +37 -0
  99. package/src/voip/relay/dtls/handshake-framing.js +100 -0
  100. package/src/voip/relay/dtls/handshake-messages.js +158 -0
  101. package/src/voip/relay/dtls/handshake.js +582 -0
  102. package/src/voip/relay/dtls/prf.js +39 -0
  103. package/src/voip/relay/dtls/record.js +56 -0
  104. package/src/voip/relay/relay-ack.js +141 -0
  105. package/src/voip/relay/sctp/association.js +434 -0
  106. package/src/voip/relay/sctp/crc32c.js +21 -0
  107. package/src/voip/relay/sctp/wire.js +226 -0
  108. package/src/voip/relay/stun.js +463 -0
  109. package/src/voip/shim/baileys-resolve.js +7 -0
  110. package/src/voip/shim/core.js +66 -0
  111. package/src/voip/shim/crypto.js +6 -0
  112. package/src/voip/shim/proto.js +10 -0
  113. package/src/voip/shim/protocol.js +130 -0
  114. package/src/voip/shim/transport.js +82 -0
  115. package/src/voip/shim/util.js +207 -0
  116. package/src/voip/signaling/bridge.js +102 -0
  117. package/src/voip/signaling/screen-share.js +60 -0
  118. package/src/voip/signaling/signaling.js +491 -0
  119. package/src/voip/types.js +69 -0
  120. package/src/voip/voip-deps.js +243 -0
  121. package/src/voip/voipClient.js +314 -0
  122. package/src/wam/wam-constants.js +22852 -0
  123. package/src/wam/wam.js +146 -0
  124. package/voip.d.ts +144 -0
@@ -0,0 +1,131 @@
1
+ /**
2
+ * src/socket/socket-builder.js
3
+ * Wraps makeCommunitiesSocket with the fluent message builder layer.
4
+ * — CJS-compatible: zero top-level await
5
+ */
6
+
7
+ import crypto from 'crypto'
8
+ import { makeCommunitiesSocket } from './business-communities.js'
9
+ import {
10
+ buildDispatch, buildPlugins, norm, handleGroupStatus, handleStatusMention,
11
+ handlePollResult, handleNativeFlow, PRIMITIVE_SHORTCUTS, HANDLER_SHORTCUTS,
12
+ getAutoBuilders, BaseBuilder,
13
+ Button, Interactive, Carousel, Album, Poll, Payment, Order, Event,
14
+ StickerPack, VerticalAlbum, GridImage, VideoGrid, A2UI,
15
+ resolveNativeFlowButtons
16
+ } from '../foundation/builders.js'
17
+ import { attachAIRich } from '../foundation/ai-rich.js'
18
+ import { generateMessageIDV2 } from '../utils/wa-protocol-core.js'
19
+ import { generateWAMessageFromContent } from '../utils/message-compose.js'
20
+
21
+ const ALL_BUILDERS = [Button, Interactive, Carousel, Album, Poll, Payment, Order, Event, StickerPack, VerticalAlbum, GridImage, VideoGrid, A2UI]
22
+
23
+ export const makeMessageBuilderSocket = (config) => {
24
+ const sock = makeCommunitiesSocket(config)
25
+ const _send = sock.sendMessage.bind(sock)
26
+
27
+ const ALL_BUILDERS_FINAL = [...ALL_BUILDERS, ...getAutoBuilders(ALL_BUILDERS)]
28
+
29
+ const DISPATCH = buildDispatch(ALL_BUILDERS_FINAL, {
30
+ groupStatus: (sock, jid, content, opts, cfg) => handleGroupStatus(sock, jid, norm(content.groupStatus), cfg),
31
+ statusMentionMessage: (sock, jid, content, opts, cfg) => handleStatusMention(sock, jid, norm(content.statusMentionMessage), cfg),
32
+ pollResultMessage: (sock, jid, content) => handlePollResult(sock, jid, norm(content.pollResultMessage))
33
+ })
34
+
35
+ const PLUGINS = buildPlugins(ALL_BUILDERS_FINAL, { ...PRIMITIVE_SHORTCUTS, ...HANDLER_SHORTCUTS })
36
+
37
+ const result = { ...sock }
38
+
39
+ // Attach all plugin shortcuts (sendText, sendImage, sendPoll, etc.)
40
+ for (const [name, factory] of Object.entries(PLUGINS)) result[name] = factory(result, config)
41
+
42
+ // ─── Patched sendMessage ───────────────────────────────────────────────────
43
+ result.sendMessage = async (jid, content, options = {}) => {
44
+ if (!options.relay) {
45
+ options.relay = async (message, relayOptions) =>
46
+ result.relayMessage(jid, message, relayOptions)
47
+ }
48
+
49
+ // AI Rich intercept
50
+ const aiData = content.aiRich ?? content.airich ?? content.richResponse ?? content.AIRich ?? content.richMessage
51
+ if (aiData) {
52
+ return result.sendRichFromObject(jid, Array.isArray(aiData) ? { ...content, parts: aiData } : { ...content, ...aiData }, options)
53
+ }
54
+
55
+ // Dispatch known builder keys
56
+ for (const [key, handler] of Object.entries(DISPATCH)) {
57
+ if (key in content) return handler(result, jid, content, options, config)
58
+ }
59
+
60
+ // Legacy templateButtons → nativeFlow upgrade
61
+ if (content.templateButtons) {
62
+ return result.sendMessage(jid, {
63
+ text: content.text ?? content.caption ?? '',
64
+ footer: content.footer,
65
+ ...(content.image ? { image: content.image } : {}),
66
+ nativeFlow: content.templateButtons.map(b =>
67
+ b.url ? { text: b.text, url: b.url }
68
+ : b.call ? { text: b.text, call: b.call }
69
+ : { text: b.text, id: b.id }
70
+ )
71
+ }, options)
72
+ }
73
+
74
+ // Chat theme shortcut
75
+ if (content.chatTheme) {
76
+ return result.setChatTheme(jid, content.chatTheme, options)
77
+ }
78
+
79
+ // cards shorthand → carouselMessage
80
+ if (content.cards && !content.carouselMessage) {
81
+ return result.sendMessage(jid, {
82
+ carouselMessage: { caption: content.text ?? content.caption ?? '', footer: content.footer, cards: content.cards }
83
+ }, options)
84
+ }
85
+
86
+ // nativeFlow shorthand → interactive
87
+ if (content.nativeFlow && !content.interactiveMessage) {
88
+ return handleNativeFlow(result, jid, content, options)
89
+ }
90
+
91
+ // AI label injection
92
+ const { ai, aiLabel: contentAiLabel, ...cleanContent } = content
93
+ const isAi = !!(ai ?? contentAiLabel ?? options.aiLabel ?? options.ai ?? config.aiLabel)
94
+ if (isAi) {
95
+ const secret = cleanContent.messageContextInfo?.messageSecret || crypto.randomBytes(32)
96
+ cleanContent.messageContextInfo = {
97
+ ...(cleanContent.messageContextInfo || {}),
98
+ messageSecret: secret,
99
+ supportPayload: JSON.stringify({
100
+ version: 2,
101
+ is_ai_message: true,
102
+ should_show_system_message: true,
103
+ ticket_id: crypto.randomBytes(16).toString('hex')
104
+ })
105
+ }
106
+ }
107
+
108
+ const { relay: _relay, ...safeContent } = isAi ? cleanContent : content
109
+ return _send(jid, safeContent, { ...options, aiLabel: isAi })
110
+ }
111
+
112
+ // sendAsMimic — send a message appearing to come from another user
113
+ result.sendAsMimic = async (jid, content, mimicJid, options = {}) => {
114
+ if (!options.admin && !options.mimicPermission) throw new Error('sendAsMimic requires admin: true')
115
+ const msgId = generateMessageIDV2(sock.user?.id)
116
+ const full = await generateWAMessageFromContent(jid, content, { userJid: sock.user?.id, ...options })
117
+ full.key = { remoteJid: jid, fromMe: false, id: msgId, participant: mimicJid }
118
+ await sock.relayMessage(jid, full.message, { messageId: msgId, ...(options.additionalAttributes ? { additionalAttributes: options.additionalAttributes } : {}) })
119
+ return full
120
+ }
121
+
122
+ // sendStatus — send to status@broadcast with statusJidList
123
+ result.sendStatus = async (content, options = {}) => {
124
+ const provided = options.statusJidList || content?.statusJidList || sock.statusJidList || []
125
+ if (!provided.length) throw new Error('sendStatus requires statusJidList')
126
+ return result.sendMessage('status@broadcast', { ...content, status: true }, { ...options, broadcast: true, statusJidList: provided })
127
+ }
128
+
129
+ // Attach AIRich methods and return fuzzy-proxy-wrapped result
130
+ return attachAIRich(result, config)
131
+ }