@kaels/casileys 0.4.5 → 0.4.7
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.
- package/README.md +332 -1
- package/lib/MessageBuilder/AIRich.js +3235 -0
- package/lib/Socket/index.js +8 -1
- package/lib/Socket/messages-recv.js +21 -0
- package/lib/Utils/rich-message-utils.js +57 -2
- package/package.json +1 -1
package/lib/Socket/index.js
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { DEFAULT_CONNECTION_CONFIG } from '../Defaults/index.js';
|
|
2
2
|
import { makeCommunitiesSocket } from './communities.js';
|
|
3
|
+
import { AIRich } from '../MessageBuilder/AIRich.js';
|
|
3
4
|
// export the last socket layer
|
|
4
5
|
const makeWASocket = (config) => {
|
|
5
6
|
const newConfig = {
|
|
6
7
|
...DEFAULT_CONNECTION_CONFIG,
|
|
7
8
|
...config
|
|
8
9
|
};
|
|
9
|
-
|
|
10
|
+
const sock = makeCommunitiesSocket(newConfig);
|
|
11
|
+
|
|
12
|
+
sock.createAIRich = (options = {}) => {
|
|
13
|
+
return new AIRich(sock, options);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
return sock;
|
|
10
17
|
};
|
|
11
18
|
export default makeWASocket;
|
|
12
19
|
//# sourceMappingURL=index.js.map
|
|
@@ -6,6 +6,7 @@ import { proto } from '../../WAProto/index.js';
|
|
|
6
6
|
import { DEFAULT_CACHE_TTLS, KEY_BUNDLE_TYPE, MIN_PREKEY_COUNT, PLACEHOLDER_MAX_AGE_SECONDS, STATUS_EXPIRY_SECONDS } from '../Defaults/index.js';
|
|
7
7
|
import { ReachoutTimelockEnforcementType, WAMessageStatus, WAMessageStubType } from '../Types/index.js';
|
|
8
8
|
import { ACCOUNT_RESTRICTED_TEXT, aesDecryptCTR, aesEncryptGCM, cleanMessage, Curve, decodeMediaRetryNode, decodeMessageNode, decryptMessageNode, delay, derivePairingCodeKey, encodeBigEndian, encodeSignedDeviceIdentity, extractAddressingContext, extractE2ESessionFromRetryReceipt, getCallStatusFromNode, getHistoryMsg, getNextPreKeys, getStatusFromReceiptType, handleIdentityChange, hkdf, MISSING_KEYS_ERROR_TEXT, NACK_REASONS, NO_MESSAGE_FOUND_ERROR_TEXT, SERVER_ERROR_CODES, toNumber, unixTimestampSeconds, xmppPreKey, xmppSignedPreKey } from '../Utils/index.js';
|
|
9
|
+
import { getContentType, normalizeMessageContent } from '../Utils/messages.js';
|
|
9
10
|
import { makeMutex } from '../Utils/make-mutex.js';
|
|
10
11
|
import { makeOfflineNodeProcessor } from '../Utils/offline-node-processor.js';
|
|
11
12
|
import { buildAckStanza } from '../Utils/stanza-ack.js';
|
|
@@ -1263,6 +1264,25 @@ export const makeMessagesRecvSocket = (config) => {
|
|
|
1263
1264
|
await sendMessageAck(node).catch(ackErr => logger.error({ ackErr }, 'failed to ack notification'));
|
|
1264
1265
|
}
|
|
1265
1266
|
};
|
|
1267
|
+
const resolveMentionedPn = async (message) => {
|
|
1268
|
+
const content = normalizeMessageContent(message);
|
|
1269
|
+
const contentType = getContentType(content);
|
|
1270
|
+
const contextInfo = content?.[contentType]?.contextInfo;
|
|
1271
|
+
|
|
1272
|
+
if (!contextInfo?.mentionedJid?.length) return;
|
|
1273
|
+
|
|
1274
|
+
const lids = contextInfo.mentionedJid.filter(isLidUser);
|
|
1275
|
+
if (!lids.length) return;
|
|
1276
|
+
|
|
1277
|
+
const mappings =
|
|
1278
|
+
await signalRepository.lidMapping.getPNsForLIDs(lids);
|
|
1279
|
+
|
|
1280
|
+
contextInfo.mentionedPn = lids
|
|
1281
|
+
.map(lid => mappings.find(mapping => mapping.lid === lid)?.pn)
|
|
1282
|
+
.filter(Boolean)
|
|
1283
|
+
.map(pn => pn.replace(':0@', '@'));
|
|
1284
|
+
};
|
|
1285
|
+
|
|
1266
1286
|
const handleMessage = async (node) => {
|
|
1267
1287
|
const encNode = getBinaryNodeChild(node, 'enc');
|
|
1268
1288
|
// TODO: temporary fix for crashes and issues resulting of failed msmsg decryption
|
|
@@ -1429,6 +1449,7 @@ export const makeMessagesRecvSocket = (config) => {
|
|
|
1429
1449
|
}
|
|
1430
1450
|
}
|
|
1431
1451
|
cleanMessage(msg, authState.creds.me.id, authState.creds.me.lid);
|
|
1452
|
+
await resolveMentionedPn(msg.message);
|
|
1432
1453
|
await upsertMessage(msg, node.attrs.offline ? 'append' : 'notify');
|
|
1433
1454
|
});
|
|
1434
1455
|
}
|
|
@@ -61,10 +61,44 @@ export const toUnified = (submessages, uuid) => ({
|
|
|
61
61
|
__typename: 'GenAISingleLayoutViewModel'
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
|
+
case RichSubMessageType.GRID_IMAGE: {
|
|
65
|
+
const imageMetadata = submessage.gridImageMetadata;
|
|
66
|
+
const image = imageMetadata?.imageUrls?.[0] || imageMetadata?.gridImageUrl;
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
view_model: {
|
|
70
|
+
primitive: {
|
|
71
|
+
media: {
|
|
72
|
+
url: image?.imagePreviewUrl || image?.imageHighResUrl || '',
|
|
73
|
+
mime_type: 'image/png'
|
|
74
|
+
},
|
|
75
|
+
imagine_type: 'IMAGE',
|
|
76
|
+
status: { status: 'READY' },
|
|
77
|
+
__typename: 'GenAIImaginePrimitive'
|
|
78
|
+
},
|
|
79
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
64
83
|
case RichSubMessageType.CONTENT_ITEMS:
|
|
65
84
|
return {};
|
|
66
|
-
case RichSubMessageType.INLINE_IMAGE:
|
|
67
|
-
|
|
85
|
+
case RichSubMessageType.INLINE_IMAGE: {
|
|
86
|
+
const imageMetadata = submessage.imageMetadata;
|
|
87
|
+
return {
|
|
88
|
+
view_model: {
|
|
89
|
+
primitive: {
|
|
90
|
+
media: {
|
|
91
|
+
url: imageMetadata?.imageUrl || imageMetadata?.imagePreviewUrl || '',
|
|
92
|
+
mime_type: 'image/png'
|
|
93
|
+
},
|
|
94
|
+
imagine_type: 'IMAGE',
|
|
95
|
+
status: { status: 'READY' },
|
|
96
|
+
__typename: 'GenAIImaginePrimitive'
|
|
97
|
+
},
|
|
98
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
68
102
|
case RichSubMessageType.LATEX:
|
|
69
103
|
return {};
|
|
70
104
|
case RichSubMessageType.TABLE:
|
|
@@ -128,6 +162,25 @@ export const prepareRichResponseMessage = (content) => {
|
|
|
128
162
|
}
|
|
129
163
|
};
|
|
130
164
|
}
|
|
165
|
+
else if (submessage.image) {
|
|
166
|
+
const images = Array.isArray(submessage.image)
|
|
167
|
+
? submessage.image
|
|
168
|
+
: [submessage.image];
|
|
169
|
+
|
|
170
|
+
const imageUrls = images.map((url) => ({
|
|
171
|
+
imagePreviewUrl: url,
|
|
172
|
+
imageHighResUrl: url,
|
|
173
|
+
sourceUrl: url
|
|
174
|
+
}));
|
|
175
|
+
|
|
176
|
+
return {
|
|
177
|
+
messageType: RichSubMessageType.GRID_IMAGE,
|
|
178
|
+
gridImageMetadata: {
|
|
179
|
+
gridImageUrl: imageUrls[0],
|
|
180
|
+
imageUrls
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
}
|
|
131
184
|
else if (submessage.inlineImage) {
|
|
132
185
|
return {
|
|
133
186
|
messageType: RichSubMessageType.INLINE_IMAGE,
|
|
@@ -307,7 +360,9 @@ export const prepareRichResponseMessage = (content) => {
|
|
|
307
360
|
}
|
|
308
361
|
}
|
|
309
362
|
const uuid = randomUUID();
|
|
363
|
+
console.log('[RICH DEBUG]', JSON.stringify(submessages, null, 2));
|
|
310
364
|
const unified = toUnified(submessages, uuid);
|
|
365
|
+
console.log('[UNIFIED DEBUG]', JSON.stringify(unified, null, 2));
|
|
311
366
|
const richResponseMessage = proto.AIRichResponseMessage.create({
|
|
312
367
|
submessages,
|
|
313
368
|
messageType: proto.AIRichResponseMessageType.AI_RICH_RESPONSE_TYPE_STANDARD,
|