Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 34 additions & 22 deletions apps/api/src/handlers/tasks/submitTaskSuggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1308,34 +1308,46 @@ export async function submitTaskSuggestions(
resolveScheduledSuggestionSlackConfig(payload.suggestionSource)
.automationKey,
);
const slackDelivered =
suggestionRuntime.destination?.provider === 'discord'
? false
: await postSuggestedTasksSummaryToSlack({
sourceTaskId: taskId,
createdByUserId,
suggestionSource: payload.suggestionSource,
historicalThreadFeedbackDebugSnippet:
payload.historicalThreadFeedbackDebugSnippet ?? null,
suggestions: persistedSuggestions,
});

if (!slackDelivered) {
const discordDelivered = await postScheduledSuggestionsToDiscord({
sourceTaskId: taskId,
createdByUserId,
suggestionSource: payload.suggestionSource,
suggestions: persistedSuggestions,
});

if (!discordDelivered) {
const telegramDelivered = await postScheduledSuggestionsToTelegram({
// An automation with its own non-Slack destination skips higher-precedence
// surfaces — the summary belongs on that surface.
const preferredProvider = suggestionRuntime.destination?.provider;
const preferredNonSlack =
preferredProvider === 'discord' ||
preferredProvider === 'telegram' ||
preferredProvider === 'teams';
const slackDelivered = preferredNonSlack
? false
: await postSuggestedTasksSummaryToSlack({
sourceTaskId: taskId,
createdByUserId,
suggestionSource: payload.suggestionSource,
historicalThreadFeedbackDebugSnippet:
payload.historicalThreadFeedbackDebugSnippet ?? null,
suggestions: persistedSuggestions,
});

if (!slackDelivered) {
const discordDelivered =
preferredProvider === 'telegram' || preferredProvider === 'teams'
? false
: await postScheduledSuggestionsToDiscord({
sourceTaskId: taskId,
createdByUserId,
suggestionSource: payload.suggestionSource,
suggestions: persistedSuggestions,
});

if (!discordDelivered) {
const telegramDelivered =
preferredProvider === 'teams'
? false
: await postScheduledSuggestionsToTelegram({
sourceTaskId: taskId,
createdByUserId,
suggestionSource: payload.suggestionSource,
suggestions: persistedSuggestions,
});

if (!telegramDelivered) {
await postScheduledSuggestionsToTeams({
sourceTaskId: taskId,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 36 additions & 5 deletions apps/api/src/handlers/teams/automation-suggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import {
db,
environments,
eq,
getAutomationRuntime,
inArray,
isNotNull,
sql,
teamsInstallations,
trackedMessages,
} from '@roomote/db/server';
import { getScheduledSuggestionBackgroundAutomationDescriptor } from '@roomote/types';
Expand Down Expand Up @@ -56,7 +59,39 @@ export async function postScheduledSuggestionsToTeams(params: {
return;
}

const conversation = await findTeamsPrimaryConversation();
const slackConfig = resolveScheduledSuggestionSlackConfig(
params.suggestionSource,
);
const runtime = await getAutomationRuntime(slackConfig.automationKey);
let conversation =
runtime.destination?.provider === 'teams'
? await (async () => {
const [row] = await db
.select({
conversationId: teamsInstallations.conversationId,
serviceUrl: teamsInstallations.serviceUrl,
})
.from(teamsInstallations)
.where(
and(
eq(
teamsInstallations.conversationId,
runtime.destination!.channelId,
),
eq(teamsInstallations.isActive, true),
isNotNull(teamsInstallations.serviceUrl),
),
)
.limit(1);
return row?.serviceUrl
? {
conversationId: row.conversationId,
serviceUrl: row.serviceUrl,
}
: null;
})()
: null;
conversation ??= await findTeamsPrimaryConversation();

if (!conversation) {
apiLogger.debug(
Expand All @@ -65,10 +100,6 @@ export async function postScheduledSuggestionsToTeams(params: {
return;
}

const slackConfig = resolveScheduledSuggestionSlackConfig(
params.suggestionSource,
);

const [existingSummaryMessage] = await db
.select({ id: trackedMessages.id })
.from(trackedMessages)
Expand Down
Loading
Loading