feat(channels): add structured attachment support for file handling

- Add Attachment interface with type, data, filePath, mimeType, fileName
- Resolve attachments in ChannelBase before prompting bridge
- Update DingTalk, Telegram, Weixin adapters to use structured attachments
- Clean up placeholder text when files are received
- Export Attachment type from base package index

This enables proper handling of images and files across all channels,
separating attachment metadata from message text.

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
tanzhenxin 2026-03-27 14:50:24 +00:00
parent 3d24a9c3fe
commit 3e0f213ea3
6 changed files with 84 additions and 17 deletions

View file

@ -415,10 +415,17 @@ export class DingtalkChannel extends ChannelBase {
if (!media) return;
if (mediaType === 'image') {
envelope.imageBase64 = media.buffer.toString('base64');
envelope.imageMimeType = media.mimeType.startsWith('image/')
const mimeType = media.mimeType.startsWith('image/')
? media.mimeType
: 'image/jpeg';
envelope.attachments = [
...(envelope.attachments || []),
{
type: 'image',
data: media.buffer.toString('base64'),
mimeType,
},
];
} else {
// Save non-image files to temp dir so the agent can read them
const dir = join(tmpdir(), 'channel-files');
@ -427,15 +434,24 @@ export class DingtalkChannel extends ChannelBase {
const filePath = join(dir, safeName);
writeFileSync(filePath, media.buffer);
const prefix =
envelope.text &&
envelope.text !== `(file: ${fileName || 'file'})` &&
envelope.text !== '(audio)' &&
envelope.text !== '(video)'
? envelope.text + '\n\n'
: '';
envelope.text =
prefix + `User sent a ${mediaType}. It has been saved to: ${filePath}`;
// Clean up placeholder text like "(audio)", "(video)", "(file: name)"
if (
envelope.text === `(file: ${fileName || 'file'})` ||
envelope.text === '(audio)' ||
envelope.text === '(video)'
) {
envelope.text = '';
}
envelope.attachments = [
...(envelope.attachments || []),
{
type: mediaType,
filePath,
mimeType: media.mimeType,
fileName: safeName,
},
];
}
}