Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

1.4 KB
Raw Blame
import { logger } from "../logger";
import { requestMemoKeys } from "../request-context/memo-keys";
import { requestMemoize } from "../request-context/request-memoizer";
import { triggerMicrosoftTeamsNotification } from "./notification-handlers/microsoft-teams";
import { triggerSlackNotification } from "./notification-handlers/slack";
import { TTriggerWorkflowNotificationDTO } from "./types";

export const triggerWorkflowIntegrationNotification = async (dto: TTriggerWorkflowNotificationDTO) => {
  try {
    const { projectId, notification } = dto.input;
    const { projectDAL, projectSlackConfigDAL, kmsService, projectMicrosoftTeamsConfigDAL, microsoftTeamsService } =
      dto.dependencies;

    const project = await requestMemoize(requestMemoKeys.projectFindById(projectId), () =>
      projectDAL.findById(projectId)
    );

    if (!project) {
      return;
    }

    const handlerPromises = [
      triggerSlackNotification({
        projectId,
        notification,
        orgId: project.orgId,
        projectSlackConfigDAL,
        kmsService
      }),

      triggerMicrosoftTeamsNotification({
        projectId,
        notification,
        orgId: project.orgId,
        projectMicrosoftTeamsConfigDAL,
        microsoftTeamsService
      })
    ];

    await Promise.allSettled(handlerPromises);
  } catch (error) {
    logger.error(error, "Error triggering workflow integration notification");
  }
};