@ezychat/wa 0.1.45 → 0.1.47
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/dist/fake/fake-adapter.d.ts +15 -0
- package/dist/fake/fake-adapter.js +23 -7
- package/package.json +2 -2
|
@@ -17,6 +17,9 @@ export declare const FAKE_RUN: string;
|
|
|
17
17
|
export declare class FakeWaAdapter extends EventEmitter implements WaAdapter {
|
|
18
18
|
private _status;
|
|
19
19
|
private readonly autoOpen;
|
|
20
|
+
private awaitScan;
|
|
21
|
+
private readonly me;
|
|
22
|
+
private readonly idPrefix;
|
|
20
23
|
private inCounter;
|
|
21
24
|
private outCounter;
|
|
22
25
|
private nextSendError;
|
|
@@ -36,8 +39,20 @@ export declare class FakeWaAdapter extends EventEmitter implements WaAdapter {
|
|
|
36
39
|
chatJid: string;
|
|
37
40
|
presence: 'composing' | 'paused';
|
|
38
41
|
}>;
|
|
42
|
+
/**
|
|
43
|
+
* `me`: the linked account (default the fake number 60000000000); `idPrefix`: start of every
|
|
44
|
+
* message id (default `FAKE`), so adapters of different inboxes never share an id.
|
|
45
|
+
* `awaitScan`: a phone that was never linked — `connect()` shows a QR code and stays there
|
|
46
|
+
* until `setConnected(true)` (the dev stand-in for the scan).
|
|
47
|
+
*/
|
|
39
48
|
constructor(opts?: {
|
|
40
49
|
autoOpen?: boolean;
|
|
50
|
+
me?: {
|
|
51
|
+
jid: string;
|
|
52
|
+
name: string;
|
|
53
|
+
};
|
|
54
|
+
idPrefix?: string;
|
|
55
|
+
awaitScan?: boolean;
|
|
41
56
|
});
|
|
42
57
|
get status(): WaStatus;
|
|
43
58
|
on<K extends keyof WaAdapterEvents>(ev: K, fn: (...a: WaAdapterEvents[K]) => void): this;
|
|
@@ -9,6 +9,9 @@ export const FAKE_RUN = Date.now().toString(36);
|
|
|
9
9
|
export class FakeWaAdapter extends EventEmitter {
|
|
10
10
|
_status = { state: 'disconnected', me: null, qr: null, lastError: null };
|
|
11
11
|
autoOpen;
|
|
12
|
+
awaitScan;
|
|
13
|
+
me;
|
|
14
|
+
idPrefix;
|
|
12
15
|
inCounter = 0;
|
|
13
16
|
outCounter = 0;
|
|
14
17
|
nextSendError = null;
|
|
@@ -22,9 +25,18 @@ export class FakeWaAdapter extends EventEmitter {
|
|
|
22
25
|
sent = [];
|
|
23
26
|
reads = [];
|
|
24
27
|
presences = [];
|
|
28
|
+
/**
|
|
29
|
+
* `me`: the linked account (default the fake number 60000000000); `idPrefix`: start of every
|
|
30
|
+
* message id (default `FAKE`), so adapters of different inboxes never share an id.
|
|
31
|
+
* `awaitScan`: a phone that was never linked — `connect()` shows a QR code and stays there
|
|
32
|
+
* until `setConnected(true)` (the dev stand-in for the scan).
|
|
33
|
+
*/
|
|
25
34
|
constructor(opts) {
|
|
26
35
|
super();
|
|
27
36
|
this.autoOpen = opts?.autoOpen ?? true;
|
|
37
|
+
this.awaitScan = opts?.awaitScan ?? false;
|
|
38
|
+
this.me = { ...(opts?.me ?? FAKE_ME) };
|
|
39
|
+
this.idPrefix = opts?.idPrefix ?? 'FAKE';
|
|
28
40
|
}
|
|
29
41
|
get status() {
|
|
30
42
|
return this._status;
|
|
@@ -46,8 +58,10 @@ export class FakeWaAdapter extends EventEmitter {
|
|
|
46
58
|
if (this._status.state === 'open' || this._status.state === 'connecting')
|
|
47
59
|
return;
|
|
48
60
|
this.setStatus({ state: 'connecting', qr: null, lastError: null });
|
|
49
|
-
if (this.
|
|
50
|
-
this.setStatus({ state: '
|
|
61
|
+
if (this.awaitScan)
|
|
62
|
+
this.setStatus({ state: 'qr', me: null, qr: `FAKE-QR-${this.idPrefix}` });
|
|
63
|
+
else if (this.autoOpen)
|
|
64
|
+
this.setStatus({ state: 'open', me: { ...this.me }, qr: null });
|
|
51
65
|
}
|
|
52
66
|
async disconnect() {
|
|
53
67
|
if (this._status.state === 'disconnected')
|
|
@@ -59,7 +73,7 @@ export class FakeWaAdapter extends EventEmitter {
|
|
|
59
73
|
}
|
|
60
74
|
async takeover() {
|
|
61
75
|
this.setStatus({ state: 'connecting', qr: null, lastError: null });
|
|
62
|
-
this.setStatus({ state: 'open', me: { ...
|
|
76
|
+
this.setStatus({ state: 'open', me: { ...this.me }, qr: null });
|
|
63
77
|
}
|
|
64
78
|
/** test helper: last phone number a pairing code was requested for */
|
|
65
79
|
pairingRequests = [];
|
|
@@ -86,13 +100,13 @@ export class FakeWaAdapter extends EventEmitter {
|
|
|
86
100
|
}
|
|
87
101
|
async sendText(chatJid, text, opts) {
|
|
88
102
|
this.beforeSend();
|
|
89
|
-
const id =
|
|
103
|
+
const id = `${this.idPrefix}-OUT-${FAKE_RUN}-${++this.outCounter}`;
|
|
90
104
|
this.sent.push({ chatJid, text, id, ...(opts?.quotedId ? { reply: opts } : {}) });
|
|
91
105
|
return this.afterSend(chatJid, id);
|
|
92
106
|
}
|
|
93
107
|
async sendMedia(chatJid, file, opts) {
|
|
94
108
|
this.beforeSend();
|
|
95
|
-
const id =
|
|
109
|
+
const id = `${this.idPrefix}-OUT-${FAKE_RUN}-${++this.outCounter}`;
|
|
96
110
|
this.sent.push({ chatJid, file, id, ...(opts?.quotedId ? { reply: opts } : {}) });
|
|
97
111
|
this.media.set(id, file.buffer);
|
|
98
112
|
return this.afterSend(chatJid, id);
|
|
@@ -175,7 +189,7 @@ export class FakeWaAdapter extends EventEmitter {
|
|
|
175
189
|
/** Emit an incoming live message. Generates id `FAKE-<run>-<n>` unless given. */
|
|
176
190
|
simulateIncoming(p) {
|
|
177
191
|
// Unique per process start: a restarted dev server must not reuse ids already stored in app.db.
|
|
178
|
-
const id = p.id ??
|
|
192
|
+
const id = p.id ?? `${this.idPrefix}-${FAKE_RUN}-${++this.inCounter}`;
|
|
179
193
|
const isGroup = p.chatJid.endsWith('@g.us');
|
|
180
194
|
const msg = {
|
|
181
195
|
id,
|
|
@@ -203,7 +217,9 @@ export class FakeWaAdapter extends EventEmitter {
|
|
|
203
217
|
}
|
|
204
218
|
setConnected(connected) {
|
|
205
219
|
if (connected)
|
|
206
|
-
this.
|
|
220
|
+
this.awaitScan = false;
|
|
221
|
+
if (connected)
|
|
222
|
+
this.setStatus({ state: 'open', me: { ...this.me }, qr: null, lastError: null });
|
|
207
223
|
else
|
|
208
224
|
this.setStatus({ state: 'disconnected', qr: null });
|
|
209
225
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ezychat/wa",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.47",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "EzyChat core: WhatsApp adapter interface, Baileys adapter and fake adapter.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"typecheck": "tsc --noEmit"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@ezychat/shared": "0.1.
|
|
40
|
+
"@ezychat/shared": "0.1.47",
|
|
41
41
|
"baileys": "^7.0.0-rc14",
|
|
42
42
|
"pino": "^10.4.0",
|
|
43
43
|
"qrcode": "^1.5.4"
|