From 578456b8de0b2ac46ea92700091e21babb782da2 Mon Sep 17 00:00:00 2001 From: Nikhil-Doye Date: Thu, 23 Oct 2025 15:07:35 -0400 Subject: [PATCH] Add slackProcessor function for handling Slack operations - Implemented slackProcessor to validate Slack configuration and execute operations using SlackService. - Added error handling for configuration validation and operation execution to ensure robust integration. - Standardized response format for successful operations, including relevant metadata. --- src/services/processors/slackProcessor.ts | 47 +++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/services/processors/slackProcessor.ts diff --git a/src/services/processors/slackProcessor.ts b/src/services/processors/slackProcessor.ts new file mode 100644 index 0000000..b22814a --- /dev/null +++ b/src/services/processors/slackProcessor.ts @@ -0,0 +1,47 @@ +import { ExecutionContext, ExecutionPlan } from "../executionEngine"; +import { SlackService } from "../slack/SlackService"; +import { SlackConfig } from "../../types/slack"; + +export default async function slackProcessor( + context: ExecutionContext, + plan: ExecutionPlan +): Promise { + const { config } = context; + + try { + // Validate configuration + const service = new SlackService(); + const validation = service.validateConfig(config as SlackConfig); + + if (!validation.valid) { + throw new Error( + `Invalid Slack configuration: ${validation.errors.join(", ")}` + ); + } + + // Execute the operation + const result = await service.executeOperation(config as SlackConfig); + + if (!result.success) { + throw new Error(result.error || "Slack operation failed"); + } + + // Return standardized response + return { + success: true, + operation: config.operation, + data: result.data, + channelId: result.metadata?.channelId, + messageTs: result.metadata?.messageTs, + userId: result.metadata?.userId, + executionTime: result.metadata?.executionTime, + type: "slack", + }; + } catch (error) { + throw new Error( + `Slack operation failed: ${ + error instanceof Error ? error.message : "Unknown error" + }` + ); + } +}