@oxidezap/baileyrs 0.2.3 → 0.2.4
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.
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import type { MessageRetransmissionInput } from '@oxidezap/whatsapp-rust-bridge';
|
|
2
2
|
import type { BinaryNode, MessageRelayOptions } from '../Types/index.js';
|
|
3
|
-
|
|
3
|
+
export declare const EMPTY_RELAY_NODES: BinaryNode[];
|
|
4
|
+
export type OwnRelayIdentity = {
|
|
4
5
|
id?: string;
|
|
5
6
|
lid?: string;
|
|
6
7
|
} | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* The one place that decides between the caller's id and a generated one.
|
|
10
|
+
* Every send path resolves through here, so `messageId` means the same thing
|
|
11
|
+
* on `sendMessage` and on `relayMessage`.
|
|
12
|
+
*/
|
|
13
|
+
export declare const resolveMessageId: (own: OwnRelayIdentity, messageId?: string) => string;
|
|
7
14
|
export type MessageRelayPlan = {
|
|
8
15
|
kind: 'message';
|
|
9
16
|
messageId: string;
|
|
@@ -22,5 +29,4 @@ export type MessageRelayPlan = {
|
|
|
22
29
|
input: MessageRetransmissionInput;
|
|
23
30
|
};
|
|
24
31
|
export declare const planMessageRelay: (jid: string, options: MessageRelayOptions, own: OwnRelayIdentity) => MessageRelayPlan;
|
|
25
|
-
export {};
|
|
26
32
|
//# sourceMappingURL=message-relay.d.ts.map
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { Boom } from '../Utils/boom.js';
|
|
2
2
|
import { generateMessageIDV2 } from '../Utils/generics.js';
|
|
3
3
|
import { areJidsSameUser, isJidBroadcast, isJidGroup, isJidNewsletter } from '../WABinary/index.js';
|
|
4
|
-
const EMPTY_RELAY_NODES = [];
|
|
4
|
+
export const EMPTY_RELAY_NODES = [];
|
|
5
|
+
/**
|
|
6
|
+
* The one place that decides between the caller's id and a generated one.
|
|
7
|
+
* Every send path resolves through here, so `messageId` means the same thing
|
|
8
|
+
* on `sendMessage` and on `relayMessage`.
|
|
9
|
+
*/
|
|
10
|
+
export const resolveMessageId = (own, messageId) => messageId || generateMessageIDV2(own?.id);
|
|
5
11
|
const assertSupportedAttributes = (attributes) => {
|
|
6
12
|
if (!attributes)
|
|
7
13
|
return;
|
|
@@ -24,7 +30,7 @@ export const planMessageRelay = (jid, options, own) => {
|
|
|
24
30
|
statusCode: 400
|
|
25
31
|
});
|
|
26
32
|
}
|
|
27
|
-
const id =
|
|
33
|
+
const id = resolveMessageId(own, messageId);
|
|
28
34
|
const refreshGroupMetadata = useCachedGroupMetadata === false;
|
|
29
35
|
if (participant) {
|
|
30
36
|
const requesterIsOwnDevice = isDirectConversation(jid) && isOwnDevice(participant.jid, own);
|
package/lib/Socket/messages.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { sendReportingUpstreamFailure } from '../Compatibility/all-encryptions-failed.js';
|
|
2
2
|
import { sendDroppingDerivedNodes } from '../Compatibility/derived-stanza-nodes.js';
|
|
3
3
|
import { encodeProtoCompat } from '../Compatibility/encode-proto.js';
|
|
4
|
-
import { planMessageRelay } from '../Compatibility/message-relay.js';
|
|
4
|
+
import { EMPTY_RELAY_NODES, planMessageRelay, resolveMessageId } from '../Compatibility/message-relay.js';
|
|
5
5
|
import { receiptMessageKeys } from '../Compatibility/message-keys.js';
|
|
6
6
|
import { MESSAGE_RECEIPT_TYPES, WAProto } from '../Types/index.js';
|
|
7
7
|
import { assertArgumentDomain } from '../Utils/argument-domain.js';
|
|
@@ -52,6 +52,12 @@ export const makeMessageMethods = (ctx) => ({
|
|
|
52
52
|
if (contentType === 'protocolMessage') {
|
|
53
53
|
const protoMsg = msg.protocolMessage;
|
|
54
54
|
if (protoMsg?.type === WAProto.Message.ProtocolMessage.Type.REVOKE && protoMsg?.key?.id) {
|
|
55
|
+
if (options?.messageId) {
|
|
56
|
+
// The core has no revoke variant that takes a stanza id, so
|
|
57
|
+
// the option cannot be honoured here. Saying so beats the
|
|
58
|
+
// silent drop this option used to get on every path.
|
|
59
|
+
ctx.logger.warn({ jid, messageId: options.messageId }, 'messageId option cannot be honoured for a revoke: the core assigns the stanza id itself');
|
|
60
|
+
}
|
|
55
61
|
// Group revokes need the original sender's participant JID —
|
|
56
62
|
// without it the server rejects the revoke. The bridge
|
|
57
63
|
// signature is `revokeMessage(jid, message_id, participant?)`.
|
|
@@ -65,15 +71,26 @@ export const makeMessageMethods = (ctx) => ({
|
|
|
65
71
|
protoMsg?.key?.id &&
|
|
66
72
|
protoMsg?.editedMessage) {
|
|
67
73
|
const editBytes = WAProto.Message.encode(protoMsg.editedMessage).finish();
|
|
68
|
-
|
|
74
|
+
// Edit-path counterpart of `options.messageId` on a plain send, and
|
|
75
|
+
// deliberately not `resolveMessageId`: the engine treats any supplied
|
|
76
|
+
// stanza id as borrowed and binds no id-keyed state to it, so an edit
|
|
77
|
+
// nobody asked to pin would silently lose its retry-cache entry and
|
|
78
|
+
// outbound secret. Absent stays absent. `||` and not `??` because an
|
|
79
|
+
// empty id means unspecified everywhere else in this API.
|
|
80
|
+
const editStanzaId = options?.messageId || undefined;
|
|
81
|
+
const newMsgId = await client.editMessageBytes(jid, protoMsg.key.id, editBytes, editStanzaId);
|
|
69
82
|
fullMsg.key.id = newMsgId || fullMsg.key.id;
|
|
70
83
|
return fullMsg;
|
|
71
84
|
}
|
|
72
85
|
}
|
|
73
86
|
const msgBytes = encodeProtoCompat('Message', msg);
|
|
87
|
+
// The with-options sends are the same core send as the plain ones, with
|
|
88
|
+
// the stanza id supplied by the caller instead of drawn by the engine.
|
|
89
|
+
// The id resolves through the same place `relayMessage` resolves it.
|
|
90
|
+
const messageId = resolveMessageId(ctx.getUser(), options?.messageId);
|
|
74
91
|
const msgId = await sendReportingUpstreamFailure(() => jid === 'status@broadcast' && options?.statusJidList?.length
|
|
75
|
-
? client.
|
|
76
|
-
: client.
|
|
92
|
+
? client.sendStatusMessageBytesWithOptions(msgBytes, options.statusJidList, messageId, EMPTY_RELAY_NODES, false)
|
|
93
|
+
: client.relayMessageBytesWithOptions(jid, msgBytes, messageId, EMPTY_RELAY_NODES, false, false));
|
|
77
94
|
fullMsg.key.id = msgId || fullMsg.key.id;
|
|
78
95
|
// Local echo of the message we just sent. Suppressed when
|
|
79
96
|
// `emitOwnEvents=false` so callers that explicitly opted out of seeing
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oxidezap/baileyrs",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.4",
|
|
5
5
|
"description": "A Rust-powered WhatsApp Web library for JavaScript, with a Baileys-compatible API",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"whatsapp",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
},
|
|
83
83
|
"dependencies": {
|
|
84
84
|
"@hapi/boom": "^9.1.4",
|
|
85
|
-
"@oxidezap/whatsapp-rust-bridge": "0.
|
|
85
|
+
"@oxidezap/whatsapp-rust-bridge": "0.15.0",
|
|
86
86
|
"long": "^5.3.2",
|
|
87
87
|
"pino": "^10.3.1",
|
|
88
88
|
"protobufjs": "^7.6.5"
|