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.
This commit is contained in:
Nikhil-Doye
2025-10-23 15:07:35 -04:00
parent e518a70d37
commit 578456b8de
+47
View File
@@ -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<any> {
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"
}`
);
}
}