fix(channels): forward line and zalo URL attachments

This commit is contained in:
William Valentin
2026-02-17 10:19:00 -08:00
parent 27b3acf5e6
commit 288ef5ac3c
4 changed files with 130 additions and 8 deletions
+44
View File
@@ -63,6 +63,50 @@ describe('ZaloAdapter', () => {
expect(String(mockFetch.mock.calls[0]?.[0])).toContain('/v3.0/oa/message/cs');
});
it('send emits URL attachments and warns for binary attachments', async () => {
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
const adapter = new ZaloAdapter({ oaAccessToken: 'token' });
await adapter.connect();
mockFetch.mockResolvedValue({
ok: true,
status: 200,
text: async () => '',
} as Response);
await adapter.send('uid-1', {
text: 'hello zalo',
attachments: [
{ mimeType: 'text/plain', url: 'https://example.com/file.txt', filename: 'file.txt' },
{ mimeType: 'application/pdf', data: 'aGVsbG8=' },
],
});
expect(mockFetch).toHaveBeenCalledTimes(2);
const secondBody = JSON.parse(String(mockFetch.mock.calls[1]?.[1]?.body ?? '{}'));
expect(secondBody.message?.text).toBe('file.txt: https://example.com/file.txt');
expect(warnSpy).toHaveBeenCalledWith('Zalo: skipping attachment data (application/pdf) — upload not implemented');
warnSpy.mockRestore();
});
it('send delivers URL attachment even when text is empty', async () => {
const adapter = new ZaloAdapter({ oaAccessToken: 'token' });
await adapter.connect();
mockFetch.mockResolvedValue({
ok: true,
status: 200,
text: async () => '',
} as Response);
await adapter.send('uid-1', {
text: ' ',
attachments: [{ mimeType: 'text/plain', url: 'https://example.com/file.txt', filename: 'file.txt' }],
});
expect(mockFetch).toHaveBeenCalledTimes(1);
const body = JSON.parse(String(mockFetch.mock.calls[0]?.[1]?.body ?? '{}'));
expect(body.message?.text).toBe('file.txt: https://example.com/file.txt');
});
it('handleEvent emits inbound message', async () => {
const adapter = new ZaloAdapter({ oaAccessToken: 'token', requireMention: false });
const inbound: Array<{ channel: string; senderId: string; text: string }> = [];