mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-16 13:03:31 +08:00
WeChat and DingTalk were using different pairing, attachment, and response state paths, which made the new IM channels behave differently from Feishu and Telegram. Align the shared pairing model, wire inbound media into the existing attachment bridge, and map platform response capabilities to their real APIs: WeChat block streaming plus typing, DingTalk AI Card streaming. Constraint: WeChat iLink exposes typing and block streaming, but no editable message/card streaming API Constraint: DingTalk streaming depends on the AI Card create/deliver/stream/finalize lifecycle Rejected: Fake DingTalk typing with standalone markdown | it would add chat noise instead of platform state Rejected: Auto-pair WeChat after QR login | it bypasses the shared IM pairing model Confidence: high Scope-risk: moderate Directive: Keep WeChat streaming as block-send unless iLink adds editable messages; keep DingTalk streaming on AI Card APIs Tested: bun run check:adapters; bun run check:server; cd desktop && bun run test src/stores/adapterStore.test.ts; cd desktop && bun run build; bunx tsc -p adapters/tsconfig.json --noEmit; git diff --check Not-tested: Live WeChat and DingTalk platform smoke with real production credentials
59 lines
2.0 KiB
TypeScript
59 lines
2.0 KiB
TypeScript
import { describe, expect, it } from 'bun:test'
|
|
import {
|
|
extractDingTalkAttachments,
|
|
extractDingTalkText,
|
|
getDingTalkChatId,
|
|
getDingTalkSenderId,
|
|
isDingTalkDirectMessage,
|
|
parseDingTalkPayload,
|
|
} from '../helpers.js'
|
|
|
|
describe('DingTalk helpers', () => {
|
|
it('parses robot payload JSON safely', () => {
|
|
expect(parseDingTalkPayload('{"msgtype":"text"}')?.msgtype).toBe('text')
|
|
expect(parseDingTalkPayload('not-json')).toBeNull()
|
|
})
|
|
|
|
it('extracts sender and chat ids for direct messages', () => {
|
|
const data = {
|
|
conversationType: '1',
|
|
senderStaffId: 'staff-1',
|
|
conversationId: 'cid-1',
|
|
}
|
|
|
|
expect(isDingTalkDirectMessage(data)).toBe(true)
|
|
expect(getDingTalkSenderId(data)).toBe('staff-1')
|
|
expect(getDingTalkChatId(data)).toBe('dingtalk:dm:staff-1')
|
|
})
|
|
|
|
it('extracts text from common DingTalk content shapes', () => {
|
|
expect(extractDingTalkText({ text: { content: ' hello ' } })).toBe('hello')
|
|
expect(extractDingTalkText({ content: '{"text":"from content"}' })).toBe('from content')
|
|
expect(extractDingTalkText({
|
|
content: {
|
|
richText: [
|
|
{ text: 'hello' },
|
|
{ text: ' world' },
|
|
],
|
|
},
|
|
})).toBe('hello world')
|
|
})
|
|
|
|
it('extracts image and file attachment candidates', () => {
|
|
expect(extractDingTalkAttachments({
|
|
msgtype: 'picture',
|
|
content: { pictureUrl: 'https://example.com/a.jpg', downloadCode: 'pic-code' },
|
|
})).toEqual([{ kind: 'image', url: 'https://example.com/a.jpg', downloadCode: 'pic-code' }])
|
|
|
|
expect(extractDingTalkAttachments({
|
|
msgtype: 'file',
|
|
content: '{"fileName":"report.pdf","downloadCode":"file-code"}',
|
|
})).toEqual([{ kind: 'file', downloadCode: 'file-code', fileName: 'report.pdf' }])
|
|
|
|
expect(extractDingTalkAttachments({
|
|
msgtype: 'richText',
|
|
content: { richText: [{ text: 'hi' }, { type: 'picture', downloadCode: 'rich-pic' }] },
|
|
})).toEqual([{ kind: 'image', url: undefined, downloadCode: 'rich-pic' }])
|
|
})
|
|
})
|