feat(signal): add typing + read receipts
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const sendTypingMock = vi.fn();
|
||||
const sendReadReceiptMock = vi.fn();
|
||||
|
||||
vi.mock("./send.js", () => ({
|
||||
sendMessageSignal: vi.fn(),
|
||||
sendTypingSignal: (...args: unknown[]) => sendTypingMock(...args),
|
||||
sendReadReceiptSignal: (...args: unknown[]) => sendReadReceiptMock(...args),
|
||||
}));
|
||||
|
||||
vi.mock("../auto-reply/reply/dispatch-from-config.js", () => ({
|
||||
dispatchReplyFromConfig: vi.fn(
|
||||
async (params: { replyOptions?: { onReplyStart?: () => void } }) => {
|
||||
await params.replyOptions?.onReplyStart?.();
|
||||
return { queuedFinal: false, counts: { tool: 0, block: 0, final: 0 } };
|
||||
},
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock("../pairing/pairing-store.js", () => ({
|
||||
readChannelAllowFromStore: vi.fn().mockResolvedValue([]),
|
||||
upsertChannelPairingRequest: vi.fn(),
|
||||
}));
|
||||
|
||||
describe("signal event handler typing + read receipts", () => {
|
||||
beforeEach(() => {
|
||||
sendTypingMock.mockReset().mockResolvedValue(true);
|
||||
sendReadReceiptMock.mockReset().mockResolvedValue(true);
|
||||
});
|
||||
|
||||
it("sends typing + read receipt for allowed DMs", async () => {
|
||||
const { createSignalEventHandler } = await import("./monitor/event-handler.js");
|
||||
const handler = createSignalEventHandler({
|
||||
runtime: { log: () => {}, error: () => {} } as any,
|
||||
cfg: {
|
||||
messages: { inbound: { debounceMs: 0 } },
|
||||
channels: { signal: { dmPolicy: "open", allowFrom: ["*"] } },
|
||||
} as any,
|
||||
baseUrl: "http://localhost",
|
||||
account: "+15550009999",
|
||||
accountId: "default",
|
||||
blockStreaming: false,
|
||||
historyLimit: 0,
|
||||
groupHistories: new Map(),
|
||||
textLimit: 4000,
|
||||
dmPolicy: "open",
|
||||
allowFrom: ["*"],
|
||||
groupAllowFrom: ["*"],
|
||||
groupPolicy: "open",
|
||||
reactionMode: "off",
|
||||
reactionAllowlist: [],
|
||||
mediaMaxBytes: 1024,
|
||||
ignoreAttachments: true,
|
||||
sendReadReceipts: true,
|
||||
readReceiptsViaDaemon: false,
|
||||
fetchAttachment: async () => null,
|
||||
deliverReplies: async () => {},
|
||||
resolveSignalReactionTargets: () => [],
|
||||
isSignalReactionMessage: () => false as any,
|
||||
shouldEmitSignalReactionNotification: () => false,
|
||||
buildSignalReactionSystemEventText: () => "reaction",
|
||||
});
|
||||
|
||||
await handler({
|
||||
event: "receive",
|
||||
data: JSON.stringify({
|
||||
envelope: {
|
||||
sourceNumber: "+15550001111",
|
||||
sourceName: "Alice",
|
||||
timestamp: 1700000000000,
|
||||
dataMessage: {
|
||||
message: "hi",
|
||||
},
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
expect(sendTypingMock).toHaveBeenCalledWith("signal:+15550001111", expect.any(Object));
|
||||
expect(sendReadReceiptMock).toHaveBeenCalledWith(
|
||||
"signal:+15550001111",
|
||||
1700000000000,
|
||||
expect.any(Object),
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user