@pontalabs/baileys 1.0.10 → 1.1.0

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 (119) hide show
  1. package/README.md +96 -85
  2. package/lib/Defaults/connection.js +39 -0
  3. package/lib/Defaults/constants.js +50 -0
  4. package/lib/Defaults/history.js +13 -0
  5. package/lib/Defaults/index.js +36 -151
  6. package/lib/Defaults/media.js +43 -0
  7. package/lib/Defaults/phonenumber-mcc.json +221 -221
  8. package/lib/Defaults/prefix.js +12 -0
  9. package/lib/Defaults/vialeys-version.json +7 -0
  10. package/lib/Signal/Group/ciphertext-message.js +10 -15
  11. package/lib/Signal/Group/group-session-builder.js +34 -60
  12. package/lib/Signal/Group/group_cipher.js +69 -76
  13. package/lib/Signal/Group/index.js +41 -60
  14. package/lib/Signal/Group/keyhelper.js +12 -57
  15. package/lib/Signal/Group/sender-chain-key.js +20 -33
  16. package/lib/Signal/Group/sender-key-distribution-message.js +43 -48
  17. package/lib/Signal/Group/sender-key-message.js +58 -53
  18. package/lib/Signal/Group/sender-key-name.js +21 -31
  19. package/lib/Signal/Group/sender-key-record.js +21 -34
  20. package/lib/Signal/Group/sender-key-state.js +59 -106
  21. package/lib/Signal/Group/sender-message-key.js +16 -21
  22. package/lib/Signal/libsignal.js +282 -203
  23. package/lib/Signal/lid-mapping.js +164 -184
  24. package/lib/Socket/Client/index.js +31 -22
  25. package/lib/Socket/Client/types.js +9 -15
  26. package/lib/Socket/Client/websocket.js +42 -37
  27. package/lib/Socket/business.js +212 -336
  28. package/lib/Socket/chats.js +696 -940
  29. package/lib/Socket/community.js +454 -369
  30. package/lib/Socket/groups.js +278 -280
  31. package/lib/Socket/index.js +9 -21
  32. package/lib/Socket/messages-recv.js +1027 -1570
  33. package/lib/Socket/messages-send.js +1180 -1136
  34. package/lib/Socket/mex.js +59 -0
  35. package/lib/Socket/newsletter.js +193 -251
  36. package/lib/Socket/socket.js +758 -898
  37. package/lib/Store/index.js +35 -24
  38. package/lib/Store/make-cache-manager-store.js +53 -66
  39. package/lib/Store/make-in-memory-store.js +319 -325
  40. package/lib/Store/make-ordered-dictionary.js +49 -57
  41. package/lib/Store/object-repository.js +10 -15
  42. package/lib/Types/Auth.js +2 -3
  43. package/lib/Types/Bussines.js +2 -3
  44. package/lib/Types/Call.js +2 -3
  45. package/lib/Types/Chat.js +10 -9
  46. package/lib/Types/Contact.js +2 -3
  47. package/lib/Types/Events.js +2 -3
  48. package/lib/Types/GroupMetadata.js +2 -3
  49. package/lib/Types/Label.js +6 -12
  50. package/lib/Types/LabelAssociation.js +4 -13
  51. package/lib/Types/Message.js +10 -18
  52. package/lib/Types/MexUpdates.js +15 -18
  53. package/lib/Types/Newsletter.js +26 -34
  54. package/lib/Types/Product.js +2 -3
  55. package/lib/Types/Signal.js +2 -3
  56. package/lib/Types/Socket.js +2 -3
  57. package/lib/Types/State.js +8 -13
  58. package/lib/Types/USync.js +2 -3
  59. package/lib/Types/index.js +49 -40
  60. package/lib/Utils/auth-utils.js +190 -495
  61. package/lib/Utils/browser-utils.js +29 -0
  62. package/lib/Utils/business.js +177 -199
  63. package/lib/Utils/chat-utils.js +711 -624
  64. package/lib/Utils/crypto.js +116 -161
  65. package/lib/Utils/decode-wa-message.js +225 -321
  66. package/lib/Utils/event-buffer.js +363 -405
  67. package/lib/Utils/generics.js +318 -472
  68. package/lib/Utils/history.js +72 -76
  69. package/lib/Utils/index.js +49 -41
  70. package/lib/Utils/link-preview.js +59 -103
  71. package/lib/Utils/logger.js +4 -7
  72. package/lib/Utils/lt-hash.js +29 -42
  73. package/lib/Utils/make-mutex.js +26 -42
  74. package/lib/Utils/message-retry-manager.js +134 -160
  75. package/lib/Utils/messages-media.js +665 -731
  76. package/lib/Utils/messages.js +518 -1
  77. package/lib/Utils/noise-handler.js +127 -125
  78. package/lib/Utils/pre-key-manager.js +86 -0
  79. package/lib/Utils/process-message.js +739 -351
  80. package/lib/Utils/signal.js +146 -129
  81. package/lib/Utils/use-multi-file-auth-state.js +68 -135
  82. package/lib/Utils/validate-connection.js +183 -142
  83. package/lib/Utils/vialeys-event-stream.js +41 -0
  84. package/lib/WABinary/constants.js +1281 -1289
  85. package/lib/WABinary/decode.js +145 -200
  86. package/lib/WABinary/encode.js +149 -202
  87. package/lib/WABinary/generic-utils.js +79 -97
  88. package/lib/WABinary/index.js +36 -25
  89. package/lib/WABinary/jid-utils.js +91 -123
  90. package/lib/WABinary/types.js +2 -3
  91. package/lib/WAM/BinaryInfo.js +8 -13
  92. package/lib/WAM/constants.js +16584 -11464
  93. package/lib/WAM/encode.js +117 -133
  94. package/lib/WAM/index.js +34 -23
  95. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +62 -69
  96. package/lib/WAUSync/Protocols/USyncContactProtocol.js +11 -25
  97. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +32 -44
  98. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +13 -23
  99. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +24 -38
  100. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +17 -31
  101. package/lib/WAUSync/Protocols/index.js +37 -26
  102. package/lib/WAUSync/USyncQuery.js +66 -66
  103. package/lib/WAUSync/USyncUser.js +13 -18
  104. package/lib/WAUSync/index.js +34 -23
  105. package/lib/index.js +95 -28
  106. package/package.json +4 -3
  107. package/lib/Defaults/baileys-version.json +0 -3
  108. package/lib/Signal/Group/queue-job.d.ts +0 -1
  109. package/lib/Signal/Group/queue-job.js +0 -57
  110. package/lib/Socket/usync.d.ts +0 -37
  111. package/lib/Socket/usync.js +0 -83
  112. package/lib/Utils/baileys-event-stream.d.ts +0 -18
  113. package/lib/Utils/baileys-event-stream.js +0 -70
  114. package/lib/Utils/signal-housekeeping.d.ts +0 -19
  115. package/lib/Utils/signal-housekeeping.js +0 -73
  116. package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
  117. package/lib/Utils/use-mongo-file-auth-state.js +0 -84
  118. package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
  119. package/lib/Utils/use-single-file-auth-state.js +0 -80
package/lib/WAM/encode.js CHANGED
@@ -1,164 +1,148 @@
1
- "use strict"
2
-
3
- Object.defineProperty(exports, "__esModule", { value: true })
4
-
5
- const constants_1 = require("./constants")
6
- const getHeaderBitLength = (key) => (key < 256 ? 2 : 3)
7
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const {
4
+ FLAG_BYTE: FLAG_BYTE,
5
+ FLAG_EVENT: FLAG_EVENT,
6
+ FLAG_EXTENDED: FLAG_EXTENDED,
7
+ FLAG_FIELD: FLAG_FIELD,
8
+ FLAG_GLOBAL: FLAG_GLOBAL,
9
+ WEB_EVENTS: WEB_EVENTS,
10
+ WEB_GLOBALS: WEB_GLOBALS,
11
+ } = require("./constants");
12
+ const getHeaderBitLength = (key) => (key < 256 ? 2 : 3);
8
13
  const encodeWAM = (binaryInfo) => {
9
- binaryInfo.buffer = []
10
- encodeWAMHeader(binaryInfo)
11
- encodeEvents(binaryInfo)
12
- const totalSize = binaryInfo.buffer
13
- .map((a) => a.length)
14
- .reduce((a, b) => a + b)
15
- const buffer = Buffer.alloc(totalSize)
16
- let offset = 0
14
+ binaryInfo.buffer = [];
15
+ encodeWAMHeader(binaryInfo);
16
+ encodeEvents(binaryInfo);
17
+ const totalSize = binaryInfo.buffer.map((a) => a.length).reduce((a, b) => a + b);
18
+ const buffer = Buffer.alloc(totalSize);
19
+ let offset = 0;
17
20
  for (const buffer_ of binaryInfo.buffer) {
18
- buffer_.copy(buffer, offset)
19
- offset += buffer_.length
21
+ buffer_.copy(buffer, offset);
22
+ offset += buffer_.length;
20
23
  }
21
- return buffer
22
- }
23
-
24
+ return buffer;
25
+ };
24
26
  function encodeWAMHeader(binaryInfo) {
25
- const headerBuffer = Buffer.alloc(8) // starting buffer
26
- headerBuffer.write('WAM', 0, 'utf8')
27
- headerBuffer.writeUInt8(binaryInfo.protocolVersion, 3)
28
- headerBuffer.writeUInt8(1, 4) //random flag
29
- headerBuffer.writeUInt16BE(binaryInfo.sequence, 5)
30
- headerBuffer.writeUInt8(0, 7) // regular channel
31
- binaryInfo.buffer.push(headerBuffer)
27
+ const headerBuffer = Buffer.alloc(8);
28
+ headerBuffer.write("WAM", 0, "utf8");
29
+ headerBuffer.writeUInt8(binaryInfo.protocolVersion, 3);
30
+ headerBuffer.writeUInt8(1, 4);
31
+ headerBuffer.writeUInt16BE(binaryInfo.sequence, 5);
32
+ headerBuffer.writeUInt8(0, 7);
33
+ binaryInfo.buffer.push(headerBuffer);
32
34
  }
33
-
34
35
  function encodeGlobalAttributes(binaryInfo, globals) {
35
36
  for (const [key, _value] of Object.entries(globals)) {
36
- const id = constants_1.WEB_GLOBALS.find(a => a?.name === key)?.id
37
- let value = _value
38
- if (typeof value === 'boolean') {
39
- value = value ? 1 : 0
37
+ const id = WEB_GLOBALS.find((a) => a?.name === key).id;
38
+ let value = _value;
39
+ if (typeof value === "boolean") {
40
+ value = value ? 1 : 0;
40
41
  }
41
- binaryInfo.buffer.push(serializeData(id, value, constants_1.FLAG_GLOBAL))
42
+ binaryInfo.buffer.push(serializeData(id, value, FLAG_GLOBAL));
42
43
  }
43
44
  }
44
-
45
45
  function encodeEvents(binaryInfo) {
46
- for (const [name, { props, globals },] of binaryInfo.events.map((a) => Object.entries(a)[0])) {
47
- encodeGlobalAttributes(binaryInfo, globals)
48
- const event = constants_1.WEB_EVENTS.find((a) => a.name === name)
49
- const props_ = Object.entries(props)
50
- let extended = false
46
+ for (const [name, { props: props, globals: globals }] of binaryInfo.events.map(
47
+ (a) => Object.entries(a)[0]
48
+ )) {
49
+ encodeGlobalAttributes(binaryInfo, globals);
50
+ const event = WEB_EVENTS.find((a) => a.name === name);
51
+ const props_ = Object.entries(props);
52
+ let extended = false;
51
53
  for (const [, value] of props_) {
52
- extended || (extended = value !== null)
54
+ extended || (extended = value !== null);
53
55
  }
54
- const eventFlag = extended ? constants_1.FLAG_EVENT : constants_1.FLAG_EVENT | constants_1.FLAG_EXTENDED
55
- binaryInfo.buffer.push(serializeData(event.id, -event.weight, eventFlag))
56
+ const eventFlag = extended ? FLAG_EVENT : FLAG_EVENT | FLAG_EXTENDED;
57
+ binaryInfo.buffer.push(serializeData(event.id, -event.weight, eventFlag));
56
58
  for (let i = 0; i < props_.length; i++) {
57
- const [key, _value] = props_[i]
58
- const id = (event.props)[key][0]
59
- extended = i < (props_.length - 1)
60
- let value = _value
61
- if (typeof value === 'boolean') {
62
- value = value ? 1 : 0
59
+ const [key, _value] = props_[i];
60
+ const id = event.props[key]?.[0];
61
+ extended = i < props_.length - 1;
62
+ let value = _value;
63
+ if (typeof value === "boolean") {
64
+ value = value ? 1 : 0;
63
65
  }
64
- const fieldFlag = extended ? constants_1.FLAG_EVENT : constants_1.FLAG_FIELD | constants_1.FLAG_EXTENDED
65
- binaryInfo.buffer.push(serializeData(id, value, fieldFlag))
66
+ const fieldFlag = extended ? FLAG_EVENT : FLAG_FIELD | FLAG_EXTENDED;
67
+ binaryInfo.buffer.push(serializeData(id, value, fieldFlag));
66
68
  }
67
69
  }
68
70
  }
69
-
70
71
  function serializeData(key, value, flag) {
71
- const bufferLength = getHeaderBitLength(key)
72
- let buffer
73
- let offset = 0
72
+ const bufferLength = getHeaderBitLength(key);
73
+ let buffer;
74
+ let offset = 0;
74
75
  if (value === null) {
75
- if (flag === constants_1.FLAG_GLOBAL) {
76
- buffer = Buffer.alloc(bufferLength)
77
- offset = serializeHeader(buffer, offset, key, flag)
78
- return buffer
76
+ if (flag === FLAG_GLOBAL) {
77
+ buffer = Buffer.alloc(bufferLength);
78
+ offset = serializeHeader(buffer, offset, key, flag);
79
+ return buffer;
79
80
  }
80
- }
81
- else if (typeof value === 'number' && Number.isInteger(value)) {
82
- // is number
81
+ } else if (typeof value === "number" && Number.isInteger(value)) {
83
82
  if (value === 0 || value === 1) {
84
- buffer = Buffer.alloc(bufferLength)
85
- offset = serializeHeader(buffer, offset, key, flag | ((value + 1) << 4))
86
- return buffer
87
- }
88
- else if (-128 <= value && value < 128) {
89
- buffer = Buffer.alloc(bufferLength + 1)
90
- offset = serializeHeader(buffer, offset, key, flag | (3 << 4))
91
- buffer.writeInt8(value, offset)
92
- return buffer
93
- }
94
- else if (-32768 <= value && value < 32768) {
95
- buffer = Buffer.alloc(bufferLength + 2)
96
- offset = serializeHeader(buffer, offset, key, flag | (4 << 4))
97
- buffer.writeInt16LE(value, offset)
98
- return buffer
99
- }
100
- else if (-2147483648 <= value && value < 2147483648) {
101
- buffer = Buffer.alloc(bufferLength + 4)
102
- offset = serializeHeader(buffer, offset, key, flag | (5 << 4))
103
- buffer.writeInt32LE(value, offset)
104
- return buffer
105
- }
106
- else {
107
- buffer = Buffer.alloc(bufferLength + 8)
108
- offset = serializeHeader(buffer, offset, key, flag | (7 << 4))
109
- buffer.writeDoubleLE(value, offset)
110
- return buffer
83
+ buffer = Buffer.alloc(bufferLength);
84
+ offset = serializeHeader(buffer, offset, key, flag | ((value + 1) << 4));
85
+ return buffer;
86
+ } else if (-128 <= value && value < 128) {
87
+ buffer = Buffer.alloc(bufferLength + 1);
88
+ offset = serializeHeader(buffer, offset, key, flag | (3 << 4));
89
+ buffer.writeInt8(value, offset);
90
+ return buffer;
91
+ } else if (-32768 <= value && value < 32768) {
92
+ buffer = Buffer.alloc(bufferLength + 2);
93
+ offset = serializeHeader(buffer, offset, key, flag | (4 << 4));
94
+ buffer.writeInt16LE(value, offset);
95
+ return buffer;
96
+ } else if (-2147483648 <= value && value < 2147483648) {
97
+ buffer = Buffer.alloc(bufferLength + 4);
98
+ offset = serializeHeader(buffer, offset, key, flag | (5 << 4));
99
+ buffer.writeInt32LE(value, offset);
100
+ return buffer;
101
+ } else {
102
+ buffer = Buffer.alloc(bufferLength + 8);
103
+ offset = serializeHeader(buffer, offset, key, flag | (7 << 4));
104
+ buffer.writeDoubleLE(value, offset);
105
+ return buffer;
111
106
  }
112
- }
113
- else if (typeof value === 'number') {
114
- // is float
115
- buffer = Buffer.alloc(bufferLength + 8)
116
- offset = serializeHeader(buffer, offset, key, flag | (7 << 4))
117
- buffer.writeDoubleLE(value, offset)
118
- return buffer
119
- }
120
- else if (typeof value === 'string') {
121
- // is string
122
- const utf8Bytes = Buffer.byteLength(value, 'utf8')
107
+ } else if (typeof value === "number") {
108
+ buffer = Buffer.alloc(bufferLength + 8);
109
+ offset = serializeHeader(buffer, offset, key, flag | (7 << 4));
110
+ buffer.writeDoubleLE(value, offset);
111
+ return buffer;
112
+ } else if (typeof value === "string") {
113
+ const utf8Bytes = Buffer.byteLength(value, "utf8");
123
114
  if (utf8Bytes < 256) {
124
- buffer = Buffer.alloc(bufferLength + 1 + utf8Bytes)
125
- offset = serializeHeader(buffer, offset, key, flag | (8 << 4))
126
- buffer.writeUint8(utf8Bytes, offset++)
127
- }
128
- else if (utf8Bytes < 65536) {
129
- buffer = Buffer.alloc(bufferLength + 2 + utf8Bytes)
130
- offset = serializeHeader(buffer, offset, key, flag | (9 << 4))
131
- buffer.writeUInt16LE(utf8Bytes, offset)
132
- offset += 2
115
+ buffer = Buffer.alloc(bufferLength + 1 + utf8Bytes);
116
+ offset = serializeHeader(buffer, offset, key, flag | (8 << 4));
117
+ buffer.writeUint8(utf8Bytes, offset++);
118
+ } else if (utf8Bytes < 65536) {
119
+ buffer = Buffer.alloc(bufferLength + 2 + utf8Bytes);
120
+ offset = serializeHeader(buffer, offset, key, flag | (9 << 4));
121
+ buffer.writeUInt16LE(utf8Bytes, offset);
122
+ offset += 2;
123
+ } else {
124
+ buffer = Buffer.alloc(bufferLength + 4 + utf8Bytes);
125
+ offset = serializeHeader(buffer, offset, key, flag | (10 << 4));
126
+ buffer.writeUInt32LE(utf8Bytes, offset);
127
+ offset += 4;
133
128
  }
134
- else {
135
- buffer = Buffer.alloc(bufferLength + 4 + utf8Bytes)
136
- offset = serializeHeader(buffer, offset, key, flag | (10 << 4))
137
- buffer.writeUInt32LE(utf8Bytes, offset)
138
- offset += 4
139
- }
140
- buffer.write(value, offset, 'utf8')
141
- return buffer
129
+ buffer.write(value, offset, "utf8");
130
+ return buffer;
142
131
  }
143
- throw 'missing'
132
+ throw "missing";
144
133
  }
145
-
146
134
  function serializeHeader(buffer, offset, key, flag) {
147
135
  if (key < 256) {
148
- buffer.writeUInt8(flag, offset)
149
- offset += 1
150
- buffer.writeUInt8(key, offset)
151
- offset += 1
152
- }
153
- else {
154
- buffer.writeUInt8(flag | constants_1.FLAG_BYTE, offset)
155
- offset += 1
156
- buffer.writeUInt16LE(key, offset)
157
- offset += 2
136
+ buffer.writeUInt8(flag, offset);
137
+ offset += 1;
138
+ buffer.writeUInt8(key, offset);
139
+ offset += 1;
140
+ } else {
141
+ buffer.writeUInt8(flag | FLAG_BYTE, offset);
142
+ offset += 1;
143
+ buffer.writeUInt16LE(key, offset);
144
+ offset += 2;
158
145
  }
159
- return offset
146
+ return offset;
160
147
  }
161
-
162
- module.exports = {
163
- encodeWAM
164
- }
148
+ module.exports = { encodeWAM: encodeWAM };
package/lib/WAM/index.js CHANGED
@@ -1,23 +1,34 @@
1
- "use strict"
2
-
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k
5
- var desc = Object.getOwnPropertyDescriptor(m, k)
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k] } }
8
- }
9
- Object.defineProperty(o, k2, desc)
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k
12
- o[k2] = m[k]
13
- }))
14
-
15
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p)
17
- }
18
-
19
- Object.defineProperty(exports, "__esModule", { value: true })
20
-
21
- __exportStar(require("./constants"), exports)
22
- __exportStar(require("./encode"), exports)
23
- __exportStar(require("./BinaryInfo"), exports)
1
+ "use strict";
2
+ const __createBinding =
3
+ (this && this.__createBinding) ||
4
+ (Object.create
5
+ ? function (o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ let desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = {
10
+ enumerable: true,
11
+ get: function () {
12
+ return m[k];
13
+ },
14
+ };
15
+ }
16
+ Object.defineProperty(o, k2, desc);
17
+ }
18
+ : function (o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ o[k2] = m[k];
21
+ });
22
+ const __exportStar =
23
+ (this && this.__exportStar) ||
24
+ function (m, exports) {
25
+ for (var p in m) {
26
+ if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) {
27
+ __createBinding(exports, m, p);
28
+ }
29
+ }
30
+ };
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ __exportStar(require("./constants"), exports);
33
+ __exportStar(require("./encode"), exports);
34
+ __exportStar(require("./BinaryInfo"), exports);
@@ -1,69 +1,62 @@
1
- "use strict"
2
-
3
- Object.defineProperty(exports, "__esModule", { value: true })
4
-
5
- const WABinary_1 = require("../../WABinary")
6
-
7
- class USyncBotProfileProtocol {
8
- constructor() {
9
- this.name = 'bot'
10
- }
11
- getQueryElement() {
12
- return {
13
- tag: 'bot',
14
- attrs: {},
15
- content: [{ tag: 'profile', attrs: { v: '1' } }]
16
- }
17
- }
18
- getUserElement(user) {
19
- return {
20
- tag: 'bot',
21
- attrs: {},
22
- content: [{ tag: 'profile', attrs: { 'persona_id': user.personaId } }]
23
- }
24
- }
25
- parser(node) {
26
- const botNode = WABinary_1.getBinaryNodeChild(node, 'bot')
27
- const profile = WABinary_1.getBinaryNodeChild(botNode, 'profile')
28
-
29
- const commandsNode = WABinary_1.getBinaryNodeChild(profile, 'commands')
30
- const promptsNode = WABinary_1.getBinaryNodeChild(profile, 'prompts')
31
-
32
- const commands = []
33
- const prompts = []
34
-
35
- if (commandsNode) {
36
- for (const command of WABinary_1.getBinaryNodeChildren(commandsNode, 'command')) {
37
- commands.push({
38
- name: WABinary_1.getBinaryNodeChildString(command, 'name') || '',
39
- description: WABinary_1.getBinaryNodeChildString(command, 'description') || ''
40
- })
41
- }
42
- }
43
-
44
- if (promptsNode) {
45
- for (const prompt of WABinary_1.getBinaryNodeChildren(promptsNode, 'prompt')) {
46
- prompts.push(
47
- `${WABinary_1.getBinaryNodeChildString(prompt, 'emoji') || ''} ${WABinary_1.getBinaryNodeChildString(prompt, 'text') || ''}`
48
- )
49
- }
50
- }
51
-
52
- return {
53
- isDefault: !!WABinary_1.getBinaryNodeChild(profile, 'default'),
54
- jid: node.attrs.jid,
55
- name: WABinary_1.getBinaryNodeChildString(profile, 'name') || '',
56
- attributes: WABinary_1.getBinaryNodeChildString(profile, 'attributes') || '',
57
- description: WABinary_1.getBinaryNodeChildString(profile, 'description') || '',
58
- category: WABinary_1.getBinaryNodeChildString(profile, 'category') || '',
59
- personaId: profile.attrs['persona_id'] || '',
60
- commandsDescription: WABinary_1.getBinaryNodeChildString(commandsNode, 'description') || '',
61
- commands,
62
- prompts
63
- }
64
- }
65
- }
66
-
67
- module.exports = {
68
- USyncBotProfileProtocol
69
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const {
4
+ getBinaryNodeChild: getBinaryNodeChild,
5
+ getBinaryNodeChildren: getBinaryNodeChildren,
6
+ getBinaryNodeChildString: getBinaryNodeChildString,
7
+ } = require("../../WABinary");
8
+ class USyncBotProfileProtocol {
9
+ constructor() {
10
+ this.name = "bot";
11
+ }
12
+ getQueryElement() {
13
+ return {
14
+ tag: "bot",
15
+ attrs: {},
16
+ content: [{ tag: "profile", attrs: { v: "1" } }],
17
+ };
18
+ }
19
+ getUserElement(user) {
20
+ return {
21
+ tag: "bot",
22
+ attrs: {},
23
+ content: [{ tag: "profile", attrs: { persona_id: user.personaId } }],
24
+ };
25
+ }
26
+ parser(node) {
27
+ const botNode = getBinaryNodeChild(node, "bot");
28
+ const profile = getBinaryNodeChild(botNode, "profile");
29
+ const commandsNode = getBinaryNodeChild(profile, "commands");
30
+ const promptsNode = getBinaryNodeChild(profile, "prompts");
31
+ const commands = [];
32
+ const prompts = [];
33
+ if (commandsNode) {
34
+ for (const command of getBinaryNodeChildren(commandsNode, "command")) {
35
+ commands.push({
36
+ name: getBinaryNodeChildString(command, "name") || "",
37
+ description: getBinaryNodeChildString(command, "description") || "",
38
+ });
39
+ }
40
+ }
41
+ if (promptsNode) {
42
+ for (const prompt of getBinaryNodeChildren(promptsNode, "prompt")) {
43
+ prompts.push(
44
+ `${getBinaryNodeChildString(prompt, "emoji") || ""} ${getBinaryNodeChildString(prompt, "text") || ""}`
45
+ );
46
+ }
47
+ }
48
+ return {
49
+ isDefault: !!getBinaryNodeChild(profile, "default"),
50
+ jid: node.attrs.jid,
51
+ name: getBinaryNodeChildString(profile, "name") || "",
52
+ attributes: getBinaryNodeChildString(profile, "attributes") || "",
53
+ description: getBinaryNodeChildString(profile, "description") || "",
54
+ category: getBinaryNodeChildString(profile, "category") || "",
55
+ personaId: profile.attrs["persona_id"] || "",
56
+ commandsDescription: getBinaryNodeChildString(commandsNode, "description") || "",
57
+ commands: commands,
58
+ prompts: prompts,
59
+ };
60
+ }
61
+ }
62
+ module.exports = { USyncBotProfileProtocol: USyncBotProfileProtocol };
@@ -1,36 +1,22 @@
1
- "use strict"
2
-
3
- Object.defineProperty(exports, "__esModule", { value: true })
4
-
5
- const WABinary_1 = require("../../WABinary")
6
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const { assertNodeErrorFree: assertNodeErrorFree } = require("../../WABinary");
7
4
  class USyncContactProtocol {
8
5
  constructor() {
9
- this.name = 'contact'
6
+ this.name = "contact";
10
7
  }
11
8
  getQueryElement() {
12
- return {
13
- tag: 'contact',
14
- attrs: {},
15
- }
9
+ return { tag: "contact", attrs: {} };
16
10
  }
17
11
  getUserElement(user) {
18
- //TODO: Implement type / username fields (not yet supported)
19
- return {
20
- tag: 'contact',
21
- attrs: {},
22
- content: user.phone,
23
- }
12
+ return { tag: "contact", attrs: {}, content: user.phone };
24
13
  }
25
14
  parser(node) {
26
- if (node.tag === 'contact') {
27
- WABinary_1.assertNodeErrorFree(node)
28
- return node?.attrs?.type === 'in'
15
+ if (node.tag === "contact") {
16
+ assertNodeErrorFree(node);
17
+ return node?.attrs?.type === "in";
29
18
  }
30
- return false
19
+ return false;
31
20
  }
32
21
  }
33
-
34
- module.exports = {
35
- USyncContactProtocol
36
- }
22
+ module.exports = { USyncContactProtocol: USyncContactProtocol };
@@ -1,62 +1,50 @@
1
- "use strict"
2
-
3
- Object.defineProperty(exports, "__esModule", { value: true })
4
-
5
- const WABinary_1 = require("../../WABinary")
6
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const {
4
+ getBinaryNodeChild: getBinaryNodeChild,
5
+ assertNodeErrorFree: assertNodeErrorFree,
6
+ } = require("../../WABinary");
7
7
  class USyncDeviceProtocol {
8
8
  constructor() {
9
- this.name = 'devices'
9
+ this.name = "devices";
10
10
  }
11
11
  getQueryElement() {
12
- return {
13
- tag: 'devices',
14
- attrs: {
15
- version: '2',
16
- },
17
- }
12
+ return { tag: "devices", attrs: { version: "2" } };
18
13
  }
19
- getUserElement( /* user: USyncUser */) {
20
- //TODO: Implement device phashing, ts and expectedTs
21
- //TODO: if all are not present, return null <- current behavior
22
- //TODO: otherwise return a node w tag 'devices' w those as attrs
23
- return null
14
+ getUserElement() {
15
+ return null;
24
16
  }
25
17
  parser(node) {
26
- const deviceList = []
27
- let keyIndex = undefined
28
- if (node.tag === 'devices') {
29
- WABinary_1.assertNodeErrorFree(node)
30
- const deviceListNode = WABinary_1.getBinaryNodeChild(node, 'device-list')
31
- const keyIndexNode = WABinary_1.getBinaryNodeChild(node, 'key-index-list')
18
+ const deviceList = [];
19
+ let keyIndex = undefined;
20
+ if (node.tag === "devices") {
21
+ assertNodeErrorFree(node);
22
+ const deviceListNode = getBinaryNodeChild(node, "device-list");
23
+ const keyIndexNode = getBinaryNodeChild(node, "key-index-list");
32
24
  if (Array.isArray(deviceListNode?.content)) {
33
- for (const { tag, attrs } of deviceListNode.content) {
34
- const id = +attrs.id
35
- const keyIndex = +attrs['key-index']
36
- if (tag === 'device') {
25
+ for (const { tag: tag, attrs: attrs } of deviceListNode.content) {
26
+ const id = +attrs.id;
27
+ const keyIndex = +attrs["key-index"];
28
+ if (tag === "device") {
37
29
  deviceList.push({
38
- id,
39
- keyIndex,
40
- isHosted: !!(attrs['is_hosted'] && attrs['is_hosted'] === 'true')
41
- })
30
+ id: id,
31
+ keyIndex: keyIndex,
32
+ isHosted: !!(attrs["is_hosted"] && attrs["is_hosted"] === "true"),
33
+ });
42
34
  }
43
35
  }
44
36
  }
45
- if (keyIndexNode?.tag === 'key-index-list') {
37
+ if (keyIndexNode?.tag === "key-index-list") {
46
38
  keyIndex = {
47
- timestamp: +keyIndexNode.attrs['ts'],
39
+ timestamp: +keyIndexNode.attrs["ts"],
48
40
  signedKeyIndex: keyIndexNode?.content,
49
- expectedTimestamp: keyIndexNode.attrs['expected_ts'] ? +keyIndexNode.attrs['expected_ts'] : undefined
50
- }
41
+ expectedTimestamp: keyIndexNode.attrs["expected_ts"]
42
+ ? +keyIndexNode.attrs["expected_ts"]
43
+ : undefined,
44
+ };
51
45
  }
52
46
  }
53
- return {
54
- deviceList,
55
- keyIndex
56
- }
47
+ return { deviceList: deviceList, keyIndex: keyIndex };
57
48
  }
58
49
  }
59
-
60
- module.exports = {
61
- USyncDeviceProtocol
62
- }
50
+ module.exports = { USyncDeviceProtocol: USyncDeviceProtocol };