Skip to content

Commit ab3ebcb

Browse files
committed
feat(api,framework,dal): surface inbound attachments through agent bridge pipeline
Inbound media from chat platforms (images, documents, audio, video) was silently dropped — the pipeline only passed message.text. This wires up the full passthrough: Chat SDK Message.attachments → persist as richContent on ConversationActivity → include in bridge payload and history replay → expose as ctx.message.attachments in the framework. Made-with: Cursor
1 parent a7da098 commit ab3ebcb

File tree

6 files changed

+52
-1
lines changed

6 files changed

+52
-1
lines changed

apps/api/src/app/agents/services/agent-conversation.service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export interface PersistInboundMessageParams {
3232
senderId: string;
3333
senderName?: string;
3434
content: string;
35+
richContent?: Record<string, unknown>;
3536
platformMessageId?: string;
3637
environmentId: string;
3738
organizationId: string;
@@ -140,6 +141,7 @@ export class AgentConversationService {
140141
senderId: params.senderId,
141142
senderName: params.senderName,
142143
content: params.content,
144+
richContent: params.richContent,
143145
platformMessageId: params.platformMessageId,
144146
environmentId: params.environmentId,
145147
organizationId: params.organizationId,

apps/api/src/app/agents/services/agent-inbound-handler.service.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ export class AgentInboundHandler {
9090
? ConversationActivitySenderTypeEnum.SUBSCRIBER
9191
: ConversationActivitySenderTypeEnum.PLATFORM_USER;
9292

93+
const richContent = message.attachments?.length
94+
? {
95+
attachments: message.attachments.map((a) => ({
96+
type: a.type,
97+
url: a.url,
98+
name: a.name,
99+
mimeType: a.mimeType,
100+
size: a.size,
101+
})),
102+
}
103+
: undefined;
104+
93105
await this.conversationService.persistInboundMessage({
94106
conversationId: conversation._id,
95107
platform: config.platform,
@@ -99,6 +111,7 @@ export class AgentInboundHandler {
99111
senderId: participantId,
100112
senderName: message.author.fullName,
101113
content: message.text,
114+
richContent,
102115
platformMessageId: message.id,
103116
environmentId: config.environmentId,
104117
organizationId: config.organizationId,

apps/api/src/app/agents/services/bridge-executor.service.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,20 @@ interface BridgeMessageAuthor {
5151
isBot: boolean | 'unknown';
5252
}
5353

54+
interface BridgeAttachment {
55+
type: string;
56+
url?: string;
57+
name?: string;
58+
mimeType?: string;
59+
size?: number;
60+
}
61+
5462
interface BridgeMessage {
5563
text: string;
5664
platformMessageId: string;
5765
author: BridgeMessageAuthor;
5866
timestamp: string;
67+
attachments?: BridgeAttachment[];
5968
}
6069

6170
export interface BridgeAction {
@@ -87,6 +96,7 @@ interface BridgeHistoryEntry {
8796
role: ConversationActivitySenderTypeEnum;
8897
type: ConversationActivityTypeEnum;
8998
content: string;
99+
richContent?: Record<string, unknown>;
90100
senderName?: string;
91101
signalData?: { type: string; payload?: Record<string, unknown> };
92102
createdAt: string;
@@ -282,7 +292,7 @@ export class BridgeExecutorService {
282292
}
283293

284294
private mapMessage(message: Message): BridgeMessage {
285-
return {
295+
const mapped: BridgeMessage = {
286296
text: message.text,
287297
platformMessageId: message.id,
288298
author: {
@@ -293,6 +303,18 @@ export class BridgeExecutorService {
293303
},
294304
timestamp: message.metadata?.dateSent?.toISOString() ?? new Date().toISOString(),
295305
};
306+
307+
if (message.attachments?.length) {
308+
mapped.attachments = message.attachments.map((a) => ({
309+
type: a.type,
310+
url: a.url,
311+
name: a.name,
312+
mimeType: a.mimeType,
313+
size: a.size,
314+
}));
315+
}
316+
317+
return mapped;
296318
}
297319

298320
private mapConversation(conversation: ConversationEntity): BridgeConversation {
@@ -337,6 +359,7 @@ export class BridgeExecutorService {
337359
role: activity.senderType,
338360
type: activity.type,
339361
content: activity.content,
362+
richContent: activity.richContent || undefined,
340363
senderName: activity.senderName || undefined,
341364
signalData: activity.signalData || undefined,
342365
createdAt: activity.createdAt,

libs/dal/src/repositories/conversation-activity/conversation-activity.repository.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export class ConversationActivityRepository extends BaseRepositoryV2<
5454
senderType: ConversationActivitySenderTypeEnum;
5555
senderId: string;
5656
content: string;
57+
richContent?: Record<string, unknown>;
5758
platformMessageId?: string;
5859
senderName?: string;
5960
environmentId: string;
@@ -69,6 +70,7 @@ export class ConversationActivityRepository extends BaseRepositoryV2<
6970
senderType: params.senderType,
7071
senderId: params.senderId,
7172
content: params.content,
73+
richContent: params.richContent,
7274
platformMessageId: params.platformMessageId,
7375
senderName: params.senderName,
7476
_environmentId: params.environmentId,

packages/framework/src/resources/agent/agent.types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,20 @@ export interface AgentMessageAuthor {
1818
isBot: boolean | 'unknown';
1919
}
2020

21+
export interface AgentAttachment {
22+
type: string;
23+
url?: string;
24+
name?: string;
25+
mimeType?: string;
26+
size?: number;
27+
}
28+
2129
export interface AgentMessage {
2230
text: string;
2331
platformMessageId: string;
2432
author: AgentMessageAuthor;
2533
timestamp: string;
34+
attachments?: AgentAttachment[];
2635
}
2736

2837
export interface AgentConversation {
@@ -49,6 +58,7 @@ export interface AgentHistoryEntry {
4958
role: string;
5059
type: string;
5160
content: string;
61+
richContent?: Record<string, unknown>;
5262
senderName?: string;
5363
signalData?: { type: string; payload?: Record<string, unknown> };
5464
createdAt: string;

packages/framework/src/resources/agent/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export { agent } from './agent.resource';
1616
export type {
1717
Agent,
1818
AgentAction,
19+
AgentAttachment,
1920
AgentBridgeRequest,
2021
AgentContext,
2122
AgentConversation,

0 commit comments

Comments
 (0)