mirror of
https://github.com/Nikhil-Doye/workflow-builder.git
synced 2026-07-22 02:01:56 +02:00
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:
@@ -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"
|
||||
}`
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user