diff --git a/packages/sdk/src/server/lib/fast-agent-parent-event.test.ts b/packages/sdk/src/server/lib/fast-agent-parent-event.test.ts index 02ad1b29a..07d6dbf71 100644 --- a/packages/sdk/src/server/lib/fast-agent-parent-event.test.ts +++ b/packages/sdk/src/server/lib/fast-agent-parent-event.test.ts @@ -2242,6 +2242,73 @@ describe('deliverFastAgentParentEvent', () => { }); }); + it.each([ + { + kickoff: true, + eventType: 'automation_triggered' as const, + expectedPrefix: 'Automation "Weekly scan" is running.', + }, + { + kickoff: false, + eventType: 'task_settled' as const, + expectedPrefix: 'Automation: Weekly scan', + }, + ])( + 'identifies a Telegram $eventType automation message', + async ({ kickoff, eventType, expectedPrefix }) => { + const message = kickoff + ? 'Starting the repository scan.' + : 'No issues found.'; + const telegramParent = { + ...parent, + conversation: { + surface: 'telegram' as const, + workspaceId: 'telegram-chat-1', + conversationId: 'automation-1:occurrence-1', + replyTarget: { channelId: 'telegram-chat-1' }, + }, + }; + mocks.answerQuestion.mockImplementationOnce(async ({ adapter }) => + adapter.postReply({ + purpose: kickoff ? 'progress' : 'closeout', + message, + kickoff, + }), + ); + + await deliverFastAgentParentEvent({ + parent: telegramParent, + event: + eventType === 'automation_triggered' + ? { + type: eventType, + eventId: 'automation-1:occurrence-1', + automationId: 'automation-1', + automationName: 'Weekly scan', + prompt: 'Find actionable regressions.', + trigger: 'schedule', + } + : { + type: eventType, + taskId: 'child-task-1', + runId: 42, + customAutomationId: 'automation-1', + status: 'completed', + taskUrl: 'https://roomote.example/task/child-task-1', + pullRequests: [], + }, + }); + + expect(mocks.telegramPostMessage).toHaveBeenCalledWith( + expect.objectContaining({ + channelId: 'telegram-chat-1', + text: `${expectedPrefix}\n\n${message}\n\nReply anytime ยท [Open in Roomote](https://api.roomote.example/sessions/${parent.sessionId}?utm_source=telegram&utm_medium=link&utm_campaign=telegram.fast_reply)`, + textFormat: 'markdown', + }), + ); + }, + ); + it.each(['new report', 'existing report', 'task settled'] as const)( 'reasserts Discord typing after %s and its suggestion messages', async (scenario) => { diff --git a/packages/sdk/src/server/lib/fast-agent-parent-event.ts b/packages/sdk/src/server/lib/fast-agent-parent-event.ts index ad1fc74b3..e42e8cbef 100644 --- a/packages/sdk/src/server/lib/fast-agent-parent-event.ts +++ b/packages/sdk/src/server/lib/fast-agent-parent-event.ts @@ -435,6 +435,17 @@ function isFastAutomationReportEvent( ); } +function buildTelegramAutomationMessage(params: { + automationName: string; + message: string; + running: boolean; +}): string { + const label = params.running + ? `Automation "${params.automationName}" is running.` + : `Automation: ${params.automationName}`; + return `${label}\n\n${params.message}`; +} + /** Groups a report's suggestion cards; unique per run occurrence. */ function buildFastAutomationSuggestionEventId( event: Extract< @@ -1906,14 +1917,15 @@ async function createTelegramFastAgentParentTurn( sessionId: session.id, footerContext: params.footerContext, }); + const automation = await resolveFastAutomationLaunchContext({ + event: params.event, + conversation, + }); const launchTask = createFastAgentCommunicationTaskLauncher({ userId: actorUserId, conversation, telegramLiveTaskProvider: provider, - automation: await resolveFastAutomationLaunchContext({ - event: params.event, - conversation, - }), + automation, }); return { userId: actorUserId, @@ -1949,6 +1961,14 @@ async function createTelegramFastAgentParentTurn( suggestions.length > 0, ) : message; + const displayedMessage = + automation && (kickoff || isFastAutomationReportEvent(params.event)) + ? buildTelegramAutomationMessage({ + automationName: automation.automationName, + message: reportMessage, + running: Boolean(kickoff), + }) + : reportMessage; const action = params.event.type === 'pull_request_feedback' && params.event.suggestedActionQuestion && @@ -1985,7 +2005,7 @@ async function createTelegramFastAgentParentTurn( ...(conversation.replyTarget.threadId ? { threadId: conversation.replyTarget.threadId } : {}), - text: reportMessage, + text: displayedMessage, textFormat: 'markdown', images, ...(action