ruby-baileys 0.0.0-stage → 1.5.17

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 (296) hide show
  1. package/EXPERIMENTAL.md +350 -0
  2. package/LICENSE +23 -0
  3. package/NOTICE.md +14 -0
  4. package/README.md +6265 -2
  5. package/WAProto/GenerateStatics.sh +3 -0
  6. package/WAProto/WAProto.proto +5479 -0
  7. package/WAProto/fix-imports.js +81 -0
  8. package/WAProto/index.d.ts +16877 -0
  9. package/WAProto/index.js +122159 -0
  10. package/assets/ruby_aspirant.jpg +0 -0
  11. package/assets/ruby_aspirant_4k.jpg +88 -0
  12. package/assets/ruby_aspirant_full.jpg +0 -0
  13. package/assets/ruby_aspirant_render.png +1 -0
  14. package/assets/ruby_aspirants_hd.jpg +0 -0
  15. package/assets/thumb.jpg +0 -0
  16. package/engine-requirements.js +14 -0
  17. package/index.cjs +29 -0
  18. package/index.d.ts +2 -0
  19. package/package.json +178 -4
  20. package/src/Defaults/index.d.ts +153 -0
  21. package/src/Defaults/index.js +165 -0
  22. package/src/MessageBuilder/bot-signature.d.ts +22 -0
  23. package/src/MessageBuilder/bot-signature.js +123 -0
  24. package/src/MessageBuilder/extras.d.ts +396 -0
  25. package/src/MessageBuilder/extras.js +1229 -0
  26. package/src/MessageBuilder/index.d.ts +210 -0
  27. package/src/MessageBuilder/index.js +3521 -0
  28. package/src/MessageBuilder/metaai.d.ts +438 -0
  29. package/src/MessageBuilder/metaai.js +891 -0
  30. package/src/Signal/Group/ciphertext-message.d.ts +10 -0
  31. package/src/Signal/Group/ciphertext-message.js +12 -0
  32. package/src/Signal/Group/group-session-builder.d.ts +8 -0
  33. package/src/Signal/Group/group-session-builder.js +28 -0
  34. package/src/Signal/Group/group_cipher.d.ts +11 -0
  35. package/src/Signal/Group/group_cipher.js +79 -0
  36. package/src/Signal/Group/index.d.ts +12 -0
  37. package/src/Signal/Group/index.js +12 -0
  38. package/src/Signal/Group/keyhelper.d.ts +7 -0
  39. package/src/Signal/Group/keyhelper.js +18 -0
  40. package/src/Signal/Group/sender-chain-key.d.ts +14 -0
  41. package/src/Signal/Group/sender-chain-key.js +26 -0
  42. package/src/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  43. package/src/Signal/Group/sender-key-distribution-message.js +63 -0
  44. package/src/Signal/Group/sender-key-message.d.ts +19 -0
  45. package/src/Signal/Group/sender-key-message.js +66 -0
  46. package/src/Signal/Group/sender-key-name.d.ts +12 -0
  47. package/src/Signal/Group/sender-key-name.js +48 -0
  48. package/src/Signal/Group/sender-key-record.d.ts +13 -0
  49. package/src/Signal/Group/sender-key-record.js +41 -0
  50. package/src/Signal/Group/sender-key-state.d.ts +17 -0
  51. package/src/Signal/Group/sender-key-state.js +84 -0
  52. package/src/Signal/Group/sender-message-key.d.ts +12 -0
  53. package/src/Signal/Group/sender-message-key.js +26 -0
  54. package/src/Signal/libsignal.d.ts +55 -0
  55. package/src/Signal/libsignal.js +429 -0
  56. package/src/Signal/lid-mapping.d.ts +21 -0
  57. package/src/Signal/lid-mapping.js +275 -0
  58. package/src/Socket/Client/index.d.ts +3 -0
  59. package/src/Socket/Client/index.js +3 -0
  60. package/src/Socket/Client/types.d.ts +6 -0
  61. package/src/Socket/Client/types.js +10 -0
  62. package/src/Socket/Client/websocket.d.ts +13 -0
  63. package/src/Socket/Client/websocket.js +54 -0
  64. package/src/Socket/business.d.ts +432 -0
  65. package/src/Socket/business.js +380 -0
  66. package/src/Socket/chats.d.ts +248 -0
  67. package/src/Socket/chats.js +1485 -0
  68. package/src/Socket/communities.d.ts +599 -0
  69. package/src/Socket/communities.js +422 -0
  70. package/src/Socket/groups.d.ts +299 -0
  71. package/src/Socket/groups.js +340 -0
  72. package/src/Socket/index.d.ts +582 -0
  73. package/src/Socket/index.js +48 -0
  74. package/src/Socket/messages-recv.d.ts +371 -0
  75. package/src/Socket/messages-recv.js +1803 -0
  76. package/src/Socket/messages-send.d.ts +391 -0
  77. package/src/Socket/messages-send.js +1575 -0
  78. package/src/Socket/mex.d.ts +2 -0
  79. package/src/Socket/mex.js +45 -0
  80. package/src/Socket/newsletter.d.ts +469 -0
  81. package/src/Socket/newsletter.js +643 -0
  82. package/src/Socket/socket.d.ts +78 -0
  83. package/src/Socket/socket.js +1088 -0
  84. package/src/Store/index.d.ts +4 -0
  85. package/src/Store/index.js +4 -0
  86. package/src/Store/make-in-memory-store.d.ts +63 -0
  87. package/src/Store/make-in-memory-store.js +398 -0
  88. package/src/Store/make-ordered-dictionary.d.ts +13 -0
  89. package/src/Store/make-ordered-dictionary.js +79 -0
  90. package/src/Store/object-repository.d.ts +11 -0
  91. package/src/Store/object-repository.js +24 -0
  92. package/src/Types/Auth.d.ts +2 -0
  93. package/src/Types/Auth.js +2 -0
  94. package/src/Types/Bussines.d.ts +2 -0
  95. package/src/Types/Bussines.js +2 -0
  96. package/src/Types/Call.d.ts +2 -0
  97. package/src/Types/Call.js +2 -0
  98. package/src/Types/Chat.d.ts +3 -0
  99. package/src/Types/Chat.js +25 -0
  100. package/src/Types/Contact.d.ts +2 -0
  101. package/src/Types/Contact.js +2 -0
  102. package/src/Types/Events.d.ts +2 -0
  103. package/src/Types/Events.js +1 -0
  104. package/src/Types/GroupMetadata.d.ts +6 -0
  105. package/src/Types/GroupMetadata.js +7 -0
  106. package/src/Types/Label.d.ts +3 -0
  107. package/src/Types/Label.js +25 -0
  108. package/src/Types/LabelAssociation.d.ts +3 -0
  109. package/src/Types/LabelAssociation.js +7 -0
  110. package/src/Types/Message.d.ts +14 -0
  111. package/src/Types/Message.js +24 -0
  112. package/src/Types/Mex.d.ts +3 -0
  113. package/src/Types/Mex.js +96 -0
  114. package/src/Types/Product.d.ts +2 -0
  115. package/src/Types/Product.js +2 -0
  116. package/src/Types/Signal.d.ts +2 -0
  117. package/src/Types/Signal.js +1 -0
  118. package/src/Types/Socket.d.ts +2 -0
  119. package/src/Types/Socket.js +1 -0
  120. package/src/Types/State.d.ts +6 -0
  121. package/src/Types/State.js +55 -0
  122. package/src/Types/USync.d.ts +2 -0
  123. package/src/Types/USync.js +1 -0
  124. package/src/Types/index.d.ts +14 -0
  125. package/src/Types/index.js +26 -0
  126. package/src/Utils/auth-store.d.ts +30 -0
  127. package/src/Utils/auth-store.js +77 -0
  128. package/src/Utils/auth-utils.d.ts +59 -0
  129. package/src/Utils/auth-utils.js +274 -0
  130. package/src/Utils/browser-utils.d.ts +10 -0
  131. package/src/Utils/browser-utils.js +29 -0
  132. package/src/Utils/business.d.ts +50 -0
  133. package/src/Utils/business.js +227 -0
  134. package/src/Utils/chat-utils.d.ts +409 -0
  135. package/src/Utils/chat-utils.js +847 -0
  136. package/src/Utils/companion-reg-client-utils.d.ts +5 -0
  137. package/src/Utils/companion-reg-client-utils.js +40 -0
  138. package/src/Utils/crypto.d.ts +40 -0
  139. package/src/Utils/crypto.js +111 -0
  140. package/src/Utils/decode-wa-message.d.ts +100 -0
  141. package/src/Utils/decode-wa-message.js +374 -0
  142. package/src/Utils/event-buffer.d.ts +23 -0
  143. package/src/Utils/event-buffer.js +625 -0
  144. package/src/Utils/generics.d.ts +64 -0
  145. package/src/Utils/generics.js +376 -0
  146. package/src/Utils/group-metadata-cache.d.ts +5 -0
  147. package/src/Utils/group-metadata-cache.js +26 -0
  148. package/src/Utils/history.d.ts +76 -0
  149. package/src/Utils/history.js +132 -0
  150. package/src/Utils/html-app.d.ts +19 -0
  151. package/src/Utils/html-app.js +97 -0
  152. package/src/Utils/html-multiplayer.d.ts +10 -0
  153. package/src/Utils/html-multiplayer.js +95 -0
  154. package/src/Utils/identity-change-handler.d.ts +14 -0
  155. package/src/Utils/identity-change-handler.js +49 -0
  156. package/src/Utils/index.d.ts +45 -0
  157. package/src/Utils/index.js +45 -0
  158. package/src/Utils/link-preview-metadata.d.ts +47 -0
  159. package/src/Utils/link-preview-metadata.js +89 -0
  160. package/src/Utils/link-preview.d.ts +13 -0
  161. package/src/Utils/link-preview.js +80 -0
  162. package/src/Utils/logger.d.ts +3 -0
  163. package/src/Utils/logger.js +3 -0
  164. package/src/Utils/lt-hash.d.ts +7 -0
  165. package/src/Utils/lt-hash.js +4 -0
  166. package/src/Utils/make-mutex.d.ts +7 -0
  167. package/src/Utils/make-mutex.js +33 -0
  168. package/src/Utils/message-retry-manager.d.ts +80 -0
  169. package/src/Utils/message-retry-manager.js +256 -0
  170. package/src/Utils/messages-media.d.ts +137 -0
  171. package/src/Utils/messages-media.js +815 -0
  172. package/src/Utils/messages.d.ts +63 -0
  173. package/src/Utils/messages.js +2149 -0
  174. package/src/Utils/modern-messages.d.ts +150 -0
  175. package/src/Utils/modern-messages.js +496 -0
  176. package/src/Utils/native-flow.d.ts +11 -0
  177. package/src/Utils/native-flow.js +116 -0
  178. package/src/Utils/newsletter-status.d.ts +158 -0
  179. package/src/Utils/newsletter-status.js +651 -0
  180. package/src/Utils/noise-handler.d.ts +21 -0
  181. package/src/Utils/noise-handler.js +201 -0
  182. package/src/Utils/offline-node-processor.d.ts +10 -0
  183. package/src/Utils/offline-node-processor.js +34 -0
  184. package/src/Utils/optional-media.d.ts +3 -0
  185. package/src/Utils/optional-media.js +46 -0
  186. package/src/Utils/payment-messages.d.ts +66 -0
  187. package/src/Utils/payment-messages.js +161 -0
  188. package/src/Utils/pre-key-manager.d.ts +26 -0
  189. package/src/Utils/pre-key-manager.js +96 -0
  190. package/src/Utils/process-message.d.ts +61 -0
  191. package/src/Utils/process-message.js +689 -0
  192. package/src/Utils/reporting-utils.d.ts +13 -0
  193. package/src/Utils/reporting-utils.js +257 -0
  194. package/src/Utils/scheduled-message.d.ts +51 -0
  195. package/src/Utils/scheduled-message.js +113 -0
  196. package/src/Utils/sender-key-memory.d.ts +20 -0
  197. package/src/Utils/sender-key-memory.js +52 -0
  198. package/src/Utils/signal.d.ts +83 -0
  199. package/src/Utils/signal.js +194 -0
  200. package/src/Utils/stanza-ack.d.ts +17 -0
  201. package/src/Utils/stanza-ack.js +31 -0
  202. package/src/Utils/status-stickers.d.ts +127 -0
  203. package/src/Utils/status-stickers.js +261 -0
  204. package/src/Utils/sync-action-utils.d.ts +3 -0
  205. package/src/Utils/sync-action-utils.js +45 -0
  206. package/src/Utils/tc-token-utils.d.ts +30 -0
  207. package/src/Utils/tc-token-utils.js +156 -0
  208. package/src/Utils/ttl-cache.d.ts +29 -0
  209. package/src/Utils/ttl-cache.js +121 -0
  210. package/src/Utils/use-mongo-auth-state.d.ts +22 -0
  211. package/src/Utils/use-mongo-auth-state.js +68 -0
  212. package/src/Utils/use-multi-file-auth-state.d.ts +12 -0
  213. package/src/Utils/use-multi-file-auth-state.js +107 -0
  214. package/src/Utils/use-mysql-auth-state.d.ts +20 -0
  215. package/src/Utils/use-mysql-auth-state.js +80 -0
  216. package/src/Utils/use-postgres-auth-state.d.ts +20 -0
  217. package/src/Utils/use-postgres-auth-state.js +80 -0
  218. package/src/Utils/use-redis-auth-state.d.ts +20 -0
  219. package/src/Utils/use-redis-auth-state.js +90 -0
  220. package/src/Utils/use-single-file-auth-state.d.ts +11 -0
  221. package/src/Utils/use-single-file-auth-state.js +109 -0
  222. package/src/Utils/use-sqlite-auth-state.d.ts +13 -0
  223. package/src/Utils/use-sqlite-auth-state.js +121 -0
  224. package/src/Utils/useNekoDBAuth.d.ts +19 -0
  225. package/src/Utils/useNekoDBAuth.js +111 -0
  226. package/src/Utils/username.d.ts +12 -0
  227. package/src/Utils/username.js +59 -0
  228. package/src/Utils/validate-connection.d.ts +44 -0
  229. package/src/Utils/validate-connection.js +208 -0
  230. package/src/Utils/voice-recognition.d.ts +53 -0
  231. package/src/Utils/voice-recognition.js +219 -0
  232. package/src/Voip/audio-feeder.d.ts +25 -0
  233. package/src/Voip/audio-feeder.js +269 -0
  234. package/src/Voip/index.d.ts +89 -0
  235. package/src/Voip/index.js +937 -0
  236. package/src/Voip/relay-transport.d.ts +6 -0
  237. package/src/Voip/relay-transport.js +825 -0
  238. package/src/Voip/signaling.d.ts +12 -0
  239. package/src/Voip/signaling.js +1100 -0
  240. package/src/Voip/types.d.ts +3 -0
  241. package/src/Voip/types.js +13 -0
  242. package/src/Voip/video-feeder.d.ts +25 -0
  243. package/src/Voip/video-feeder.js +269 -0
  244. package/src/Voip/wasm-engine.d.ts +27 -0
  245. package/src/Voip/wasm-engine.js +1308 -0
  246. package/src/Voip/worker-bootstrap.js +1024 -0
  247. package/src/WABinary/constants.d.ts +23 -0
  248. package/src/WABinary/constants.js +1301 -0
  249. package/src/WABinary/decode.d.ts +10 -0
  250. package/src/WABinary/decode.js +262 -0
  251. package/src/WABinary/encode.d.ts +3 -0
  252. package/src/WABinary/encode.js +220 -0
  253. package/src/WABinary/generic-utils.d.ts +77 -0
  254. package/src/WABinary/generic-utils.js +214 -0
  255. package/src/WABinary/index.d.ts +6 -0
  256. package/src/WABinary/index.js +6 -0
  257. package/src/WABinary/jid-utils.d.ts +31 -0
  258. package/src/WABinary/jid-utils.js +98 -0
  259. package/src/WABinary/types.d.ts +2 -0
  260. package/src/WABinary/types.js +1 -0
  261. package/src/WAM/BinaryInfo.d.ts +8 -0
  262. package/src/WAM/BinaryInfo.js +10 -0
  263. package/src/WAM/constants.d.ts +34927 -0
  264. package/src/WAM/constants.js +22853 -0
  265. package/src/WAM/encode.d.ts +2 -0
  266. package/src/WAM/encode.js +149 -0
  267. package/src/WAM/index.d.ts +4 -0
  268. package/src/WAM/index.js +4 -0
  269. package/src/WAUSync/Protocols/USyncContactProtocol.d.ts +37 -0
  270. package/src/WAUSync/Protocols/USyncContactProtocol.js +51 -0
  271. package/src/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  272. package/src/WAUSync/Protocols/USyncDeviceProtocol.js +52 -0
  273. package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  274. package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
  275. package/src/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  276. package/src/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
  277. package/src/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
  278. package/src/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
  279. package/src/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +39 -0
  280. package/src/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -0
  281. package/src/WAUSync/Protocols/UsyncLIDProtocol.d.ts +15 -0
  282. package/src/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
  283. package/src/WAUSync/Protocols/index.d.ts +6 -0
  284. package/src/WAUSync/Protocols/index.js +6 -0
  285. package/src/WAUSync/USyncQuery.d.ts +21 -0
  286. package/src/WAUSync/USyncQuery.js +94 -0
  287. package/src/WAUSync/USyncUser.d.ts +17 -0
  288. package/src/WAUSync/USyncUser.js +31 -0
  289. package/src/WAUSync/index.d.ts +4 -0
  290. package/src/WAUSync/index.js +4 -0
  291. package/src/assets/wasm/README.md +76 -0
  292. package/src/assets/wasm/loader.js +5 -0
  293. package/src/assets/wasm/whatsapp.wasm +0 -0
  294. package/src/assets/wasm/worker-modules.js +273 -0
  295. package/src/index.d.ts +49 -0
  296. package/src/index.js +54 -0
@@ -0,0 +1,44 @@
1
+ /* Elaina Baileys maintained distribution. Upstream notices and license are preserved in LICENSE and NOTICE.md. */
2
+ export function generateLoginNode(userJid: any, config: any): proto.ClientPayload;
3
+ export function generateRegistrationNode({ registrationId, signedPreKey, signedIdentityKey }: {
4
+ registrationId: any;
5
+ signedPreKey: any;
6
+ signedIdentityKey: any;
7
+ }, config: any): proto.ClientPayload;
8
+ export function configureSuccessfulPairing(stanza: any, { advSecretKey, signedIdentityKey, signalIdentities }: {
9
+ advSecretKey: any;
10
+ signedIdentityKey: any;
11
+ signalIdentities: any;
12
+ }): {
13
+ creds: {
14
+ account: proto.ADVSignedDeviceIdentity;
15
+ me: {
16
+ id: any;
17
+ name: any;
18
+ lid: any;
19
+ };
20
+ signalIdentities: any[];
21
+ platform: any;
22
+ };
23
+ reply: {
24
+ tag: string;
25
+ attrs: {
26
+ to: string;
27
+ type: string;
28
+ id: any;
29
+ };
30
+ content: {
31
+ tag: string;
32
+ attrs: {};
33
+ content: {
34
+ tag: string;
35
+ attrs: {
36
+ 'key-index': string;
37
+ };
38
+ content: any;
39
+ }[];
40
+ }[];
41
+ };
42
+ };
43
+ export function encodeSignedDeviceIdentity(account: any, includeSignatureKey: any): any;
44
+ import { proto } from '../../WAProto/index.js';
@@ -0,0 +1,208 @@
1
+ /* Elaina Baileys maintained distribution. Upstream notices and license are preserved in LICENSE and NOTICE.md. */
2
+ import { Boom } from '@hapi/boom';
3
+ import { createHash } from 'crypto';
4
+ import { proto } from '../../WAProto/index.js';
5
+ import { KEY_BUNDLE_TYPE, WA_ADV_ACCOUNT_SIG_PREFIX, WA_ADV_DEVICE_SIG_PREFIX, WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX } from '../Defaults/index.js';
6
+ import { getBinaryNodeChild, jidDecode, S_WHATSAPP_NET } from '../WABinary/index.js';
7
+ import { Curve, hmacSign } from './crypto.js';
8
+ import { encodeBigEndian } from './generics.js';
9
+ import { createSignalIdentity } from './signal.js';
10
+ const getUserAgent = (config) => {
11
+ return {
12
+ appVersion: {
13
+ primary: config.version[0],
14
+ secondary: config.version[1],
15
+ tertiary: config.version[2]
16
+ },
17
+ platform: config.browser[1].toLocaleLowerCase().includes('android')
18
+ ? proto.ClientPayload.UserAgent.Platform.ANDROID
19
+ : proto.ClientPayload.UserAgent.Platform.WEB,
20
+ releaseChannel: proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
21
+ osVersion: '0.1',
22
+ device: 'Desktop',
23
+ osBuildNumber: '0.1',
24
+ localeLanguageIso6391: 'en',
25
+ mnc: '000',
26
+ mcc: '000',
27
+ localeCountryIso31661Alpha2: config.countryCode
28
+ };
29
+ };
30
+ const PLATFORM_MAP = {
31
+ 'Mac OS': proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
32
+ Windows: proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
33
+ };
34
+ const getWebInfo = (config) => {
35
+ let webSubPlatform = proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER;
36
+ if (config.syncFullHistory &&
37
+ PLATFORM_MAP[config.browser[0]] &&
38
+ config.browser[1] === 'Desktop') {
39
+ webSubPlatform = PLATFORM_MAP[config.browser[0]];
40
+ }
41
+ return { webSubPlatform };
42
+ };
43
+ const getClientPayload = (config) => {
44
+ const payload = {
45
+ connectType: proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
46
+ connectReason: proto.ClientPayload.ConnectReason.USER_ACTIVATED,
47
+ userAgent: getUserAgent(config)
48
+ };
49
+ if (!config.browser[1].toLocaleLowerCase().includes('android')) {
50
+ payload.webInfo = getWebInfo(config);
51
+ }
52
+ if (config.pushName) {
53
+ payload.pushName = config.pushName;
54
+ }
55
+ return payload;
56
+ };
57
+ export const generateLoginNode = (userJid, config) => {
58
+ const { user, device } = jidDecode(userJid);
59
+ const payload = {
60
+ ...getClientPayload(config),
61
+ passive: true,
62
+ pull: true,
63
+ username: +user,
64
+ device: device,
65
+
66
+ lidDbMigrated: false
67
+ };
68
+ return proto.ClientPayload.fromObject(payload);
69
+ };
70
+ const getPlatformType = (platform) => {
71
+ const platformType = platform.toUpperCase();
72
+ if (platformType === 'ANDROID') {
73
+ return proto.DeviceProps.PlatformType.ANDROID_PHONE;
74
+ }
75
+ return (proto.DeviceProps.PlatformType[platformType] ||
76
+ proto.DeviceProps.PlatformType.CHROME);
77
+ };
78
+ export const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
79
+
80
+ const appVersionBuf = createHash('md5')
81
+ .update(config.version.join('.'))
82
+ .digest();
83
+ const companion = {
84
+ os: config.browser[0],
85
+ platformType: getPlatformType(config.browser[1]),
86
+ requireFullSync: config.syncFullHistory,
87
+ historySyncConfig: {
88
+ storageQuotaMb: 10240,
89
+ inlineInitialPayloadInE2EeMsg: true,
90
+ recentSyncDaysLimit: undefined,
91
+ supportCallLogHistory: false,
92
+ supportBotUserAgentChatHistory: true,
93
+ supportCagReactionsAndPolls: true,
94
+ supportBizHostedMsg: true,
95
+ supportRecentSyncChunkMessageCountTuning: true,
96
+ supportHostedGroupMsg: true,
97
+ supportFbidBotChatHistory: true,
98
+ supportAddOnHistorySyncMigration: undefined,
99
+ supportMessageAssociation: true,
100
+ supportGroupHistory: false,
101
+ onDemandReady: undefined,
102
+ supportGuestChat: undefined
103
+ },
104
+ version: {
105
+ primary: 10,
106
+ secondary: 15,
107
+ tertiary: 7
108
+ }
109
+ };
110
+ const companionProto = proto.DeviceProps.encode(companion).finish();
111
+ const registerPayload = {
112
+ ...getClientPayload(config),
113
+ passive: false,
114
+ pull: false,
115
+ devicePairingData: {
116
+ buildHash: appVersionBuf,
117
+ deviceProps: companionProto,
118
+ eRegid: encodeBigEndian(registrationId),
119
+ eKeytype: KEY_BUNDLE_TYPE,
120
+ eIdent: signedIdentityKey.public,
121
+ eSkeyId: encodeBigEndian(signedPreKey.keyId, 3),
122
+ eSkeyVal: signedPreKey.keyPair.public,
123
+ eSkeySig: signedPreKey.signature
124
+ }
125
+ };
126
+ return proto.ClientPayload.fromObject(registerPayload);
127
+ };
128
+ export const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
129
+ const msgId = stanza.attrs.id;
130
+ const pairSuccessNode = getBinaryNodeChild(stanza, 'pair-success');
131
+ const deviceIdentityNode = getBinaryNodeChild(pairSuccessNode, 'device-identity');
132
+ const platformNode = getBinaryNodeChild(pairSuccessNode, 'platform');
133
+ const deviceNode = getBinaryNodeChild(pairSuccessNode, 'device');
134
+ const businessNode = getBinaryNodeChild(pairSuccessNode, 'biz');
135
+ if (!deviceIdentityNode || !deviceNode) {
136
+ throw new Boom('Missing device-identity or device in pair success node', { data: stanza });
137
+ }
138
+ const bizName = businessNode?.attrs.name;
139
+ const jid = deviceNode.attrs.jid;
140
+ const lid = deviceNode.attrs.lid;
141
+ const { details, hmac, accountType } = proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
142
+ let hmacPrefix = Buffer.from([]);
143
+ if (accountType !== undefined && accountType === proto.ADVEncryptionType.HOSTED) {
144
+ hmacPrefix = WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX;
145
+ }
146
+ const advSign = hmacSign(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'));
147
+ if (Buffer.compare(hmac, advSign) !== 0) {
148
+ throw new Boom('Invalid account signature');
149
+ }
150
+ const account = proto.ADVSignedDeviceIdentity.decode(details);
151
+ const { accountSignatureKey, accountSignature, details: deviceDetails } = account;
152
+ const deviceIdentity = proto.ADVDeviceIdentity.decode(deviceDetails);
153
+ const accountSignaturePrefix = deviceIdentity.deviceType === proto.ADVEncryptionType.HOSTED
154
+ ? WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX
155
+ : WA_ADV_ACCOUNT_SIG_PREFIX;
156
+ const accountMsg = Buffer.concat([accountSignaturePrefix, deviceDetails, signedIdentityKey.public]);
157
+ if (!Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
158
+ throw new Boom('Failed to verify account signature');
159
+ }
160
+ const deviceMsg = Buffer.concat([
161
+ WA_ADV_DEVICE_SIG_PREFIX,
162
+ deviceDetails,
163
+ signedIdentityKey.public,
164
+ accountSignatureKey
165
+ ]);
166
+ account.deviceSignature = Curve.sign(signedIdentityKey.private, deviceMsg);
167
+ const identity = createSignalIdentity(lid, accountSignatureKey);
168
+ const accountEnc = encodeSignedDeviceIdentity(account, false);
169
+ const reply = {
170
+ tag: 'iq',
171
+ attrs: {
172
+ to: S_WHATSAPP_NET,
173
+ type: 'result',
174
+ id: msgId
175
+ },
176
+ content: [
177
+ {
178
+ tag: 'pair-device-sign',
179
+ attrs: {},
180
+ content: [
181
+ {
182
+ tag: 'device-identity',
183
+ attrs: { 'key-index': deviceIdentity.keyIndex.toString() },
184
+ content: accountEnc
185
+ }
186
+ ]
187
+ }
188
+ ]
189
+ };
190
+ const authUpdate = {
191
+ account,
192
+ me: { id: jid, name: bizName, lid },
193
+ signalIdentities: [...(signalIdentities || []), identity],
194
+ platform: platformNode?.attrs.name
195
+ };
196
+ return {
197
+ creds: authUpdate,
198
+ reply
199
+ };
200
+ };
201
+ export const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
202
+ account = { ...account };
203
+
204
+ if (!includeSignatureKey || !account.accountSignatureKey?.length) {
205
+ account.accountSignatureKey = null;
206
+ }
207
+ return proto.ADVSignedDeviceIdentity.encode(account).finish();
208
+ };
@@ -0,0 +1,53 @@
1
+ export type VoiceRecognitionContext = {
2
+ message: any;
3
+ audioMessage: any;
4
+ chatJid: string;
5
+ senderJid: string;
6
+ isGroup: boolean;
7
+ };
8
+ export type VoiceTranscriptionInput = VoiceRecognitionContext & {
9
+ buffer: Buffer;
10
+ mimetype: string;
11
+ };
12
+ export type VoiceTranscriptionResult = string | {
13
+ text?: string;
14
+ transcript?: string;
15
+ language?: string;
16
+ confidence?: number;
17
+ [key: string]: any;
18
+ };
19
+ export type VoiceRecognitionOptions = {
20
+ enabled?: boolean;
21
+ transcribe: (input: VoiceTranscriptionInput) => VoiceTranscriptionResult | Promise<VoiceTranscriptionResult>;
22
+ wakePhrases?: string | string[];
23
+ getWakePhrases?: (context: VoiceRecognitionContext) => string | string[] | undefined | Promise<string | string[] | undefined>;
24
+ shouldProcess?: (context: VoiceRecognitionContext) => boolean | Promise<boolean>;
25
+ allowQuotedActivation?: boolean;
26
+ pttOnly?: boolean;
27
+ maxDuration?: number;
28
+ maxBytes?: number;
29
+ downloadOptions?: any;
30
+ };
31
+ export type VoiceRecognitionEvent = VoiceRecognitionContext & {
32
+ transcript: string;
33
+ commandText: string;
34
+ activation: 'quoted' | 'wake-phrase' | null;
35
+ wakePhrase: string | null;
36
+ language?: string;
37
+ confidence?: number;
38
+ [key: string]: any;
39
+ };
40
+ export function normalizeVoiceText(value: any): string;
41
+ export function matchVoiceWakePhrase(transcript: any, phrases?: string | string[]): {
42
+ phrase: string;
43
+ normalizedPhrase: string;
44
+ normalizedTranscript: string;
45
+ } | null;
46
+ export function removeVoiceWakePhrase(transcript: any, wakePhrase: any): string;
47
+ export function bindVoiceRecognition(sock: any, config?: {
48
+ voiceRecognition?: VoiceRecognitionOptions;
49
+ getMessage?: (key: any) => Promise<any>;
50
+ logger?: any;
51
+ }, dependencies?: {
52
+ downloadContentFromMessage?: (...args: any[]) => Promise<any>;
53
+ }): () => void;
@@ -0,0 +1,219 @@
1
+ import { downloadContentFromMessage } from './messages-media.js';
2
+ import { normalizeMessageContent } from './messages.js';
3
+ import { areJidsSameUser, isJidGroup, jidNormalizedUser } from '../WABinary/index.js';
4
+
5
+ const DEFAULT_MAX_DURATION = 60;
6
+ const DEFAULT_MAX_BYTES = 16 * 1024 * 1024;
7
+
8
+ const streamToBuffer = async (stream, maxBytes) => {
9
+ const chunks = [];
10
+ let total = 0;
11
+ for await (const chunk of stream) {
12
+ const buffer = Buffer.from(chunk);
13
+ total += buffer.length;
14
+ if (maxBytes && total > maxBytes) {
15
+ throw new Error('voice message exceeds maxBytes');
16
+ }
17
+ chunks.push(buffer);
18
+ }
19
+ return Buffer.concat(chunks);
20
+ };
21
+
22
+ export const normalizeVoiceText = value => String(value ?? '')
23
+ .normalize('NFKD')
24
+ .replace(/\p{M}/gu, '')
25
+ .toLowerCase()
26
+ .replace(/[^\p{L}\p{N}]+/gu, ' ')
27
+ .replace(/\s+/g, ' ')
28
+ .trim();
29
+
30
+ export const matchVoiceWakePhrase = (transcript, phrases = []) => {
31
+ const normalizedTranscript = normalizeVoiceText(transcript);
32
+ if (!normalizedTranscript) {
33
+ return null;
34
+ }
35
+ const candidates = [...new Map((Array.isArray(phrases) ? phrases : [phrases])
36
+ .map(phrase => ({ raw: String(phrase ?? '').trim(), normalized: normalizeVoiceText(phrase) }))
37
+ .filter(phrase => phrase.normalized)
38
+ .map(phrase => [phrase.normalized, phrase])).values()]
39
+ .sort((a, b) => b.normalized.length - a.normalized.length);
40
+ for (const phrase of candidates) {
41
+ const index = ` ${normalizedTranscript} `.indexOf(` ${phrase.normalized} `);
42
+ if (index >= 0) {
43
+ return {
44
+ phrase: phrase.raw,
45
+ normalizedPhrase: phrase.normalized,
46
+ normalizedTranscript
47
+ };
48
+ }
49
+ }
50
+ return null;
51
+ };
52
+
53
+ export const removeVoiceWakePhrase = (transcript, wakePhrase) => {
54
+ const normalizedTranscript = normalizeVoiceText(transcript);
55
+ const normalizedPhrase = normalizeVoiceText(wakePhrase);
56
+ if (!normalizedPhrase) {
57
+ return normalizedTranscript;
58
+ }
59
+ const words = normalizedTranscript.split(' ');
60
+ const phraseWords = normalizedPhrase.split(' ');
61
+ for (let index = 0; index <= words.length - phraseWords.length; index += 1) {
62
+ if (phraseWords.every((word, offset) => words[index + offset] === word)) {
63
+ words.splice(index, phraseWords.length);
64
+ break;
65
+ }
66
+ }
67
+ return words.join(' ').trim();
68
+ };
69
+
70
+ const getVoiceSenderJid = message => jidNormalizedUser(message?.key?.participantAlt ||
71
+ message?.key?.participant ||
72
+ message?.key?.remoteJidAlt ||
73
+ message?.key?.remoteJid);
74
+
75
+ const isQuotedToSelf = async ({ message, audioMessage, meId, meLid, getMessage }) => {
76
+ const contextInfo = audioMessage?.contextInfo;
77
+ if (!contextInfo?.quotedMessage && !contextInfo?.stanzaId) {
78
+ return false;
79
+ }
80
+ const quotedAuthor = contextInfo.participantAlt || contextInfo.participant;
81
+ if (quotedAuthor && (areJidsSameUser(quotedAuthor, meId) || areJidsSameUser(quotedAuthor, meLid))) {
82
+ return true;
83
+ }
84
+ if (!contextInfo.stanzaId || typeof getMessage !== 'function') {
85
+ return false;
86
+ }
87
+ const target = await getMessage({
88
+ remoteJid: message.key.remoteJid,
89
+ remoteJidAlt: message.key.remoteJidAlt,
90
+ participant: quotedAuthor,
91
+ id: contextInfo.stanzaId
92
+ });
93
+ return target?.key?.fromMe === true;
94
+ };
95
+
96
+ const normalizeTranscriptionResult = value => {
97
+ if (typeof value === 'string') {
98
+ return { text: value };
99
+ }
100
+ if (value && typeof value === 'object') {
101
+ return {
102
+ ...value,
103
+ text: String(value.text ?? value.transcript ?? '')
104
+ };
105
+ }
106
+ return { text: '' };
107
+ };
108
+
109
+ const getWakePhrases = async (voiceRecognition, context) => {
110
+ const staticPhrases = Array.isArray(voiceRecognition.wakePhrases)
111
+ ? voiceRecognition.wakePhrases
112
+ : voiceRecognition.wakePhrases
113
+ ? [voiceRecognition.wakePhrases]
114
+ : [];
115
+ const dynamicPhrases = typeof voiceRecognition.getWakePhrases === 'function'
116
+ ? await voiceRecognition.getWakePhrases(context)
117
+ : [];
118
+ return [...new Set([
119
+ ...staticPhrases,
120
+ ...(Array.isArray(dynamicPhrases) ? dynamicPhrases : dynamicPhrases ? [dynamicPhrases] : [])
121
+ ].map(value => String(value ?? '').trim()).filter(Boolean))];
122
+ };
123
+
124
+ export const bindVoiceRecognition = (sock, config = {}, dependencies = {}) => {
125
+ const voiceRecognition = config.voiceRecognition;
126
+ if (!voiceRecognition?.enabled || typeof voiceRecognition.transcribe !== 'function') {
127
+ return () => undefined;
128
+ }
129
+ const downloadContent = dependencies.downloadContentFromMessage || downloadContentFromMessage;
130
+ const getMessage = config.getMessage;
131
+ const logger = config.logger;
132
+ const handler = async ({ messages, type }) => {
133
+ if (type !== 'notify') {
134
+ return;
135
+ }
136
+ for (const message of messages || []) {
137
+ try {
138
+ if (
139
+ !message?.message ||
140
+ (message.key?.fromMe && !voiceRecognition.allowFromMe)
141
+ ) {
142
+ continue
143
+ }
144
+ const content = normalizeMessageContent(message.message);
145
+ const audioMessage = content?.audioMessage;
146
+ if (!audioMessage) {
147
+ continue;
148
+ }
149
+ if ((voiceRecognition.pttOnly ?? true) && !audioMessage.ptt) {
150
+ continue;
151
+ }
152
+ const maxDuration = Number.isFinite(voiceRecognition.maxDuration)
153
+ ? Math.max(0, Number(voiceRecognition.maxDuration))
154
+ : DEFAULT_MAX_DURATION;
155
+ if (maxDuration && Number(audioMessage.seconds || 0) > maxDuration) {
156
+ continue;
157
+ }
158
+ const chatJid = jidNormalizedUser(message.key.remoteJid);
159
+ const senderJid = getVoiceSenderJid(message);
160
+ const context = {
161
+ message,
162
+ audioMessage,
163
+ chatJid,
164
+ senderJid,
165
+ isGroup: isJidGroup(chatJid)
166
+ };
167
+ if (typeof voiceRecognition.shouldProcess === 'function' && !(await voiceRecognition.shouldProcess(context))) {
168
+ continue;
169
+ }
170
+ const maxBytes = Number.isFinite(voiceRecognition.maxBytes)
171
+ ? Math.max(0, Number(voiceRecognition.maxBytes))
172
+ : DEFAULT_MAX_BYTES;
173
+ const declaredBytes = Number(audioMessage.fileLength?.toString?.() || audioMessage.fileLength || 0);
174
+ if (maxBytes && declaredBytes > maxBytes) {
175
+ continue;
176
+ }
177
+ const stream = await downloadContent(audioMessage, 'audio', voiceRecognition.downloadOptions || {});
178
+ const buffer = await streamToBuffer(stream, maxBytes);
179
+ const transcription = normalizeTranscriptionResult(await voiceRecognition.transcribe({
180
+ ...context,
181
+ buffer,
182
+ mimetype: audioMessage.mimetype || 'audio/ogg; codecs=opus'
183
+ }));
184
+ const transcript = transcription.text.trim();
185
+ if (!transcript) {
186
+ continue;
187
+ }
188
+ const meId = sock.authState?.creds?.me?.id;
189
+ const meLid = sock.authState?.creds?.me?.lid;
190
+ const quoted = (voiceRecognition.allowQuotedActivation ?? true)
191
+ ? await isQuotedToSelf({ message, audioMessage, meId, meLid, getMessage })
192
+ : false;
193
+ const phrases = quoted ? [] : await getWakePhrases(voiceRecognition, context);
194
+ const wake = quoted ? null : matchVoiceWakePhrase(transcript, phrases);
195
+ const activation = quoted ? 'quoted' : wake ? 'wake-phrase' : null;
196
+ const commandText = wake
197
+ ? removeVoiceWakePhrase(transcript, wake.normalizedPhrase)
198
+ : normalizeVoiceText(transcript);
199
+ const event = {
200
+ ...context,
201
+ ...transcription,
202
+ transcript,
203
+ commandText,
204
+ activation,
205
+ wakePhrase: wake?.phrase || null
206
+ };
207
+ sock.ev.emit('voice.transcription', event);
208
+ if (activation) {
209
+ sock.ev.emit('voice.command', event);
210
+ }
211
+ }
212
+ catch (error) {
213
+ logger?.warn({ err: error, key: message?.key }, 'voice recognition failed');
214
+ }
215
+ }
216
+ };
217
+ sock.ev.on('messages.upsert', handler);
218
+ return () => sock.ev.off('messages.upsert', handler);
219
+ };
@@ -0,0 +1,25 @@
1
+ /* Elaina Baileys maintained distribution. Upstream notices and license are preserved in LICENSE and NOTICE.md. */
2
+ export declare class AudioFeeder {
3
+ constructor(sampleRate: number, channels: number, framesPerChunk: number, onChunk: (chunk: Float32Array) => void, source?: string, hooks?: {
4
+ onTrackStart?: (track: string) => void;
5
+ onTrackEnd?: (track: string) => void;
6
+ onIdle?: () => void;
7
+ ffmpegPath?: string;
8
+ });
9
+ readonly queuedChunks: number;
10
+ droppedChunks: number;
11
+ underflowChunks: number;
12
+ rebuffers: number;
13
+ bytesProduced: number;
14
+ chunksEmitted: number;
15
+ readonly playlistLength: number;
16
+ readonly currentTrack: string | null;
17
+ readonly idle: boolean;
18
+ tracksPlayed: number;
19
+ enqueue(source: string | string[]): number;
20
+ clearPlaylist(): void;
21
+ skip(): boolean;
22
+ start(playlist?: string[]): void;
23
+ stop(): void;
24
+ }
25
+ export default AudioFeeder;