import type { IntegrationAccountRequirement, TriggerDefinition } from "../types" const SLACK_APP_MENTION_ACCOUNT = { connectionOptions: [ { requiredScopes: ["app_mentions:read"], }, ], serviceId: "slack", } as const satisfies IntegrationAccountRequirement const SLACK_MESSAGE_ACCOUNT = { connectionOptions: [ { requiredScopes: [ { requirements: [ "channels:history", "groups:history", "im:history", "mpim:history", ], type: "and", }, ], }, ], serviceId: "slack", } as const satisfies IntegrationAccountRequirement const SLACK_REACTION_ACCOUNT = { connectionOptions: [ { requiredScopes: ["reactions:read"], }, ], serviceId: "slack", } as const satisfies IntegrationAccountRequirement const SLACK_CHANNEL_MEMBER_JOINED_ACCOUNT = slackAccount([ "channels:read", "groups:read", "mpim:read", ]) const SLACK_CHANNEL_MEMBER_LEFT_ACCOUNT = slackAccount([ "channels:read", "groups:read", ]) const SLACK_FILE_ACCOUNT = slackAccount(["files:read"]) const SLACK_WORKSPACE_MEMBER_ACCOUNT = slackAccount(["users:read"]) const SLACK_PUBLIC_CHANNEL_ACCOUNT = slackAccount(["channels:read"]) const SLACK_SHARED_CHANNEL_ACCOUNT = slackAccount([ "channels:read", "groups:read", ]) const SLACK_PIN_ACCOUNT = slackAccount(["pins:read"]) const SLACK_EVENT_ACCOUNT = slackAccount([ "app_mentions:read", "channels:history", "groups:history", "im:history", "mpim:history", "reactions:read", "channels:read", "groups:read", "mpim:read", "files:read", "users:read", "pins:read", ]) export const slackTriggerDefinitions = { slackAppMentioned: { account: SLACK_APP_MENTION_ACCOUNT, type: "slack.app.mentioned", }, slackMessagePosted: { account: SLACK_MESSAGE_ACCOUNT, type: "slack.message.posted", }, slackChannelCreated: { account: SLACK_PUBLIC_CHANNEL_ACCOUNT, type: "slack.channel.created", }, slackChannelMemberJoined: { account: SLACK_CHANNEL_MEMBER_JOINED_ACCOUNT, type: "slack.channel.member.joined", }, slackChannelMemberLeft: { account: SLACK_CHANNEL_MEMBER_LEFT_ACCOUNT, type: "slack.channel.member.left", }, slackChannelRenamed: { account: SLACK_PUBLIC_CHANNEL_ACCOUNT, type: "slack.channel.renamed", }, slackChannelShared: { account: SLACK_SHARED_CHANNEL_ACCOUNT, type: "slack.channel.shared", }, slackChannelUnshared: { account: SLACK_SHARED_CHANNEL_ACCOUNT, type: "slack.channel.unshared", }, slackEvent: { account: SLACK_EVENT_ACCOUNT, type: "slack.event.received", }, slackFileCreated: { account: SLACK_FILE_ACCOUNT, type: "slack.file.created", }, slackFileDeleted: { account: SLACK_FILE_ACCOUNT, type: "slack.file.deleted", }, slackFileShared: { account: SLACK_FILE_ACCOUNT, type: "slack.file.shared", }, slackMessageChanged: { account: SLACK_MESSAGE_ACCOUNT, type: "slack.message.changed", }, slackMessageDeleted: { account: SLACK_MESSAGE_ACCOUNT, type: "slack.message.deleted", }, slackPinAdded: { account: SLACK_PIN_ACCOUNT, type: "slack.pin.added", }, slackPinRemoved: { account: SLACK_PIN_ACCOUNT, type: "slack.pin.removed", }, slackReactionAdded: { account: SLACK_REACTION_ACCOUNT, type: "slack.reaction.added", }, slackReactionEvent: { account: SLACK_REACTION_ACCOUNT, type: "slack.reaction.event", }, slackReactionRemoved: { account: SLACK_REACTION_ACCOUNT, type: "slack.reaction.removed", }, slackThreadReplyPosted: { account: SLACK_MESSAGE_ACCOUNT, type: "slack.thread.reply.posted", }, slackWorkspaceMemberChanged: { account: SLACK_WORKSPACE_MEMBER_ACCOUNT, type: "slack.workspace.member.changed", }, slackWorkspaceMemberJoined: { account: SLACK_WORKSPACE_MEMBER_ACCOUNT, type: "slack.workspace.member.joined", }, } as const satisfies Record /** * Builds one bot-token account requirement from its least-privilege scopes. * * @param scopes - Slack bot OAuth scopes required by the trigger. */ function slackAccount(scopes: readonly string[]) { return { connectionOptions: [{ requiredScopes: [...scopes] }], serviceId: "slack", } as const satisfies IntegrationAccountRequirement }