Skip to content
Draft
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

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

14 changes: 7 additions & 7 deletions apps/api/src/handlers/mcp/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -971,16 +971,19 @@ slackMcp.post('/thread_reply', async (c) => {
blocks.push(...imageBlocks);
blocks.push(...rootFooterBlocks);

const rootMessageTs = await slack.postMessage({
const rootPost = await slack.postTopLevelMessage({
channel: slackReplyTarget.channel,
text: getSlackFallbackText(fallbackText, imageBlocks.length),
unfurl_links: false,
unfurl_media: false,
blocks,
});
const rootMessageTs = rootPost.messageTs;

if (!rootMessageTs) {
throw new Error('Slack chat.postMessage returned no message timestamp');
throw new Error(
`Slack chat.postMessage failed${rootPost.error ? `: ${rootPost.error}` : ' without a message timestamp'}`,
);
}

// The root message is already visible in Slack; failing the reply here
Expand Down Expand Up @@ -1343,11 +1346,8 @@ slackMcp.post('/thread_reply', async (c) => {
);
}

if (message === 'Slack chat.postMessage returned no message timestamp') {
return c.json(
{ error: 'Slack chat.postMessage returned no message timestamp' },
502,
);
if (message.startsWith('Slack chat.postMessage failed')) {
return c.json({ error: message }, 502);
}

if (message === 'Slack thread source message no longer exists') {
Expand Down

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

23 changes: 23 additions & 0 deletions packages/sdk/src/server/automations/custom-automations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
listConnectedCommunicationProviders,
type ResolvedAutomationDestination,
} from './destination';
import { getCommunicationProviderAdapter } from '../lib/communication-providers';
import {
isCronRunDue,
resolveDeploymentTimeZone,
Expand Down Expand Up @@ -246,6 +247,28 @@ async function launchCustomAutomationRow(
});
return result;
}

if (destination.provider === 'slack') {
const slack = await getCommunicationProviderAdapter('slack');
const isMember =
slack?.provider === 'slack'
? await slack.isAppInChannel(destination.channelId)
: null;
if (isMember !== true) {
const message =
isMember === false
? `Slack app cannot access report channel ${destination.channelId}. Invite the app to the channel or choose another destination.`
: `Slack report channel ${destination.channelId} could not be verified. Try again before running this automation.`;
result.skippedReason = message;
result.errors.push(message);
await recordCustomAutomationRunOutcome(db, {
id: automation.id,
status: 'failed',
error: message,
});
return result;
}
}
}

// The short claim fence prevents concurrent launchers from double-launching
Expand Down
14 changes: 14 additions & 0 deletions packages/slack/src/__tests__/slack-notifier.test.ts

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

20 changes: 20 additions & 0 deletions packages/slack/src/slack-notifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,26 @@ export class SlackNotifier {
return response?.ts;
}

/**
* Posts a top-level message while preserving Slack's API error code for
* callers that need to report why a new conversation could not be created.
*/
public async postTopLevelMessage(message: SlackMessage): Promise<{
messageTs?: string;
error?: string;
}> {
const response = await this.sendMessage(
'chat.postMessage',
message,
'regular',
);

return {
...(response?.ts ? { messageTs: response.ts } : {}),
...(response?.error ? { error: response.error } : {}),
};
}

public async postEphemeralMessage(message: SlackMessage & { user: string }) {
const response = await this.sendMessage(
'chat.postEphemeral',
Expand Down
Loading