import { DestinationServer, sendServer } from '@walkeros/server-core'; import { ChatPostMessageArguments, ChatPostMessageResponse, ChatPostEphemeralArguments, ChatPostEphemeralResponse, ConversationsOpenArguments, ConversationsOpenResponse, WebClient } from '@slack/web-api'; import { Flow } from '@walkeros/core'; /** A single Block Kit block (kept loose -- Slack does not export a union type). */ type SlackBlock = Record; interface Settings { /** Slack Bot token (xoxb-...). Enables Web API mode. */ token?: string; /** Incoming Webhook URL. Enables webhook mode. */ webhookUrl?: string; /** Default channel ID or name. Required for Web API mode unless every rule provides one. */ channel?: string; /** Default text template. Supports `${data.field}` interpolation against the walkerOS event. */ text?: string; /** Default Block Kit blocks applied when no mapping override is set. */ blocks?: SlackBlock[]; /** Auto-add an event-name header block when generating default blocks. Default: true. */ includeHeader?: boolean; /** Enable link unfurling. Default: false. */ unfurlLinks?: boolean; /** Enable media unfurling. Default: false. */ unfurlMedia?: boolean; /** Use mrkdwn formatting. Default: true. */ mrkdwn?: boolean; /** Static thread_ts to reply to (rarely set at destination level). */ threadTs?: string; /** Retry policy passed to WebClient. Default: 'default'. */ retryConfig?: 'default' | 'fiveRetriesInFiveMinutes' | 'none'; _client?: WebClient; } /** * Mock-friendly interface for the WebClient methods the destination calls. * Tests inject this via env.slackClient. */ interface SlackClientMock { chat: { postMessage: (opts: ChatPostMessageArguments) => Promise; postEphemeral: (opts: ChatPostEphemeralArguments) => Promise; }; conversations: { open: (opts: ConversationsOpenArguments) => Promise; }; } /** * Env -- optional SDK / transport overrides. Production leaves these undefined. * Tests inject `slackClient` (Web API mode) and/or `sendServer` (webhook mode). */ interface Env extends DestinationServer.Env { slackClient?: SlackClientMock; sendServer?: typeof sendServer; } declare const push: Env; declare const simulation: string[]; declare const env_push: typeof push; declare const env_simulation: typeof simulation; declare namespace env { export { env_push as push, env_simulation as simulation }; } /** * Extended step example that may carry destination-level settings overrides. */ type SlackStepExample = Flow.StepExample & { settings?: Partial; }; /** * Slack server destination operates in two modes: * * 1. Web API mode - calls the injected `env.slackClient` SDK methods * (`chat.postMessage`, `chat.postEphemeral`, `conversations.open`). * Captured as `[callable, args]` with dotted callable names such as * `'slackClient.chat.postMessage'`. * * 2. Webhook mode - calls `env.sendServer(url, JSON.stringify(body))`. * Captured as `['sendServer', url, bodyAsString]` where `bodyAsString` * is the already-stringified JSON body. Key insertion order in the * source object matters for string equality. * * A single push may emit multiple calls (e.g. a DM opens a conversation * then posts to the returned channel id), so every `out` is wrapped as * `[[callable, ...args], ...]`. */ /** * Purchase notification -- Web API mode, channel from mapping override, * text template interpolated against event.data. */ declare const purchaseAlert: SlackStepExample; /** * Error alert -- routes to a different channel via mapping override. */ declare const errorAlert: SlackStepExample; /** * Welcome DM -- conversations.open(users) -> chat.postMessage(channel: D-id). */ declare const welcomeDM: SlackStepExample; /** * Threaded checkout step -- thread_ts override puts the reply into a thread. */ declare const threadedCheckoutStep: SlackStepExample; /** * Ephemeral message -- visible to one user in the target channel. */ declare const ephemeralMessage: SlackStepExample; /** * Default blocks -- no custom text/blocks, destination auto-generates a * Block Kit message from the event data. */ declare const defaultBlocks: SlackStepExample; /** * Webhook mode -- no token, just webhookUrl. The destination calls * `env.sendServer(url, JSON.stringify(body))`. Channel is baked into the * URL by Slack. */ declare const deployNotification: SlackStepExample; type step_SlackStepExample = SlackStepExample; declare const step_defaultBlocks: typeof defaultBlocks; declare const step_deployNotification: typeof deployNotification; declare const step_ephemeralMessage: typeof ephemeralMessage; declare const step_errorAlert: typeof errorAlert; declare const step_purchaseAlert: typeof purchaseAlert; declare const step_threadedCheckoutStep: typeof threadedCheckoutStep; declare const step_welcomeDM: typeof welcomeDM; declare namespace step { export { type step_SlackStepExample as SlackStepExample, step_defaultBlocks as defaultBlocks, step_deployNotification as deployNotification, step_ephemeralMessage as ephemeralMessage, step_errorAlert as errorAlert, step_purchaseAlert as purchaseAlert, step_threadedCheckoutStep as threadedCheckoutStep, step_welcomeDM as welcomeDM }; } export { env, step };