Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

feat: sync investigation state changes to slack

Brad Barbin63bc283781cf
diff --git a/apps/erp/app/modules/quality/quality.service.ts b/apps/erp/app/modules/quality/quality.service.ts
index e909df2967..75cfcc5978 100644
--- a/apps/erp/app/modules/quality/quality.service.ts
+++ b/apps/erp/app/modules/quality/quality.service.ts
@@ -862,7 +862,9 @@ export async function updateIssueTaskStatus(
return client
.from(table)
.update({ status, updatedBy: userId, assignee: finalAssignee })
- .eq("id", id);
+ .eq("id", id)
+ .select("nonConformanceId")
+ .single();
}
export async function upsertGauge(
diff --git a/apps/erp/app/modules/quality/ui/Issue/IssueProperties.tsx b/apps/erp/app/modules/quality/ui/Issue/IssueProperties.tsx
index fb66f16b06..cfb3cd33a5 100644
--- a/apps/erp/app/modules/quality/ui/Issue/IssueProperties.tsx
+++ b/apps/erp/app/modules/quality/ui/Issue/IssueProperties.tsx
@@ -299,7 +299,7 @@ const IssueProperties = () => {
label: <Enumerable value={type.name} />,
}))}
isReadOnly={disableStructureUpdate}
- label="Non-conformance Type"
+ label="Issue Type"
name="nonConformanceTypeId"
inline={(value, options) => {
return (
@@ -313,7 +313,7 @@ const IssueProperties = () => {
}}
onChange={(value) => {
if (value) {
- onUpdate("source", value.value);
+ onUpdate("nonConformanceTypeId", value.value);
}
}}
/>
diff --git a/apps/erp/app/modules/quality/ui/IssueWorkflows/IssueWorkflowForm.tsx b/apps/erp/app/modules/quality/ui/IssueWorkflows/IssueWorkflowForm.tsx
index b588f2105b..dd695ec8d0 100644
--- a/apps/erp/app/modules/quality/ui/IssueWorkflows/IssueWorkflowForm.tsx
+++ b/apps/erp/app/modules/quality/ui/IssueWorkflows/IssueWorkflowForm.tsx
@@ -98,28 +98,11 @@ const IssueWorkflowForm = ({
<span className="hidden md:inline">Issue</span> Workflow
</Heading>
<p className="text-sm text-muted-foreground">
- Non-conformance workflows are used as a starting point for issues.
- Each issue workflow uses a workflow to create the issue. A single
+ Issue workflows are used as a starting point for issues. Each
+ issue workflow uses a workflow to create the issue. A single
workflow can be used in multiple workflows.
</p>
</VStack>
- {/* <div className="ml-auto">
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <IconButton aria-labell="More options" icon={<LuEllipsisVertical />} variant="secondary" />
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- <DropdownMenuItem>
- <span>Duplicate</span>
- </DropdownMenuItem>
-
- <DropdownMenuSeparator />
- <DropdownMenuItem destructive>
- <span>Delete</span>
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
- </div> */}
</HStack>
<Input name="name" label="Name" />
<VStack spacing={2}>
diff --git a/apps/erp/app/routes/x+/issue+/task.$id.status.tsx b/apps/erp/app/routes/x+/issue+/task.$id.status.tsx
index 15312ed430..b989062863 100644
--- a/apps/erp/app/routes/x+/issue+/task.$id.status.tsx
+++ b/apps/erp/app/routes/x+/issue+/task.$id.status.tsx
@@ -29,8 +29,6 @@ export async function action({ request, params }: ActionFunctionArgs) {
| "approval"
| "review";
const assignee = formData.get("assignee") as string;
- const nonConformanceId = formData.get("nonConformanceId") as string;
- const taskName = formData.get("taskName") as string;
const update = await updateIssueTaskStatus(client, {
id,
@@ -46,27 +44,23 @@ export async function action({ request, params }: ActionFunctionArgs) {
);
}
- // Sync task update to Slack if we have the required info (non-blocking)
- if (nonConformanceId && taskName && type !== "review") {
- try {
- const hasSlack = await hasSlackIntegration(client, companyId);
- if (hasSlack) {
- await syncIssueTaskToSlack(client, {
- assignedTo: assignee || undefined,
- completedAt:
- status === "Completed" ? new Date().toISOString() : undefined,
- companyId,
- nonConformanceId,
- status,
- taskName,
- taskType: type as "investigation" | "action" | "approval",
- userId,
- });
- }
- } catch (error) {
- console.error("Failed to sync task to Slack:", error);
- // Continue without blocking the main operation
+ try {
+ const hasSlack = await hasSlackIntegration(client, companyId);
+ if (hasSlack && update.data?.nonConformanceId) {
+ await syncIssueTaskToSlack(client, {
+ completedAt:
+ status === "Completed" ? new Date().toISOString() : undefined,
+ companyId,
+ id,
+ nonConformanceId: update.data.nonConformanceId,
+ status,
+ taskType: type as "investigation" | "action" | "approval",
+ userId,
+ });
}
+ } catch (error) {
+ console.error("Failed to sync task to Slack:", error);
+ // Continue without blocking the main operation
}
return json({});
diff --git a/packages/database/supabase/functions/create/index.ts b/packages/database/supabase/functions/create/index.ts
index 3bae7e994c..33aba055e4 100644
--- a/packages/database/supabase/functions/create/index.ts
+++ b/packages/database/supabase/functions/create/index.ts
@@ -322,6 +322,7 @@ serve(async (req: Request) => {
) {
// @ts-ignore -- content is json
const contentFromWorkflow = workflow?.data?.content?.content ?? [];
+
const insertedContent = {
type: "doc",
content: contentFromWorkflow,
@@ -336,13 +337,15 @@ serve(async (req: Request) => {
});
}
- await trx
- .updateTable("nonConformance")
- .set({
- content: insertedContent,
- })
- .where("id", "=", id)
- .execute();
+ if (insertedContent.content.length > 0) {
+ await trx
+ .updateTable("nonConformance")
+ .set({
+ content: insertedContent.content,
+ })
+ .where("id", "=", id)
+ .execute();
+ }
}
if (investigationTaskInserts.length > 0) {
diff --git a/packages/integrations/src/slack/lib/service.ts b/packages/integrations/src/slack/lib/service.ts
index b3bafe2216..321aed0a81 100644
--- a/packages/integrations/src/slack/lib/service.ts
+++ b/packages/integrations/src/slack/lib/service.ts
@@ -6,6 +6,7 @@ import type {
slackDocumentStatusUpdate,
slackDocumentTaskUpdate,
} from "@carbon/jobs/trigger/slack-document-sync";
+import { redis } from "@carbon/kv";
import type { SupabaseClient } from "@supabase/supabase-js";
import { tasks } from "@trigger.dev/sdk/v3";
import { createSlackWebClient } from "./client";
@@ -215,6 +216,29 @@ export async function getSlackAuth(
return null;
}
+ const slackUserId = await getSlackUserIdByCarbonId(
+ client,
+ metadata.access_token,
+ userId
+ );
+
+ return {
+ slackToken: metadata.access_token,
+ channelId: metadata.channel_id,
+ slackUserId: slackUserId || undefined,
+ };
+}
+
+export async function getSlackUserIdByCarbonId(
+ client: SupabaseClient<Database>,
+ accessToken: string,
+ userId: string
+) {
+ const cachedUserId = await redis.get(`slack-user:${userId}`);
+ if (cachedUserId && typeof cachedUserId === "string") {
+ return cachedUserId;
+ }
+
const user = await client
.from("user")
.select("email")
@@ -222,42 +246,22 @@ export async function getSlackAuth(
.single();
if (user.error || !user.data?.email) {
- return {
- slackToken: metadata.access_token,
- channelId: metadata.channel_id,
- };
+ return null;
}
try {
- const slackClient = createSlackWebClient({ token: metadata.access_token });
+ const slackClient = createSlackWebClient({ token: accessToken });
const slackUser = await slackClient.users.lookupByEmail({
email: user.data.email,
});
if (slackUser.ok && slackUser.user?.id) {
- return {
- slackToken: metadata.access_token,
- slackUserId: slackUser.user.id,
- channelId: metadata.channel_id,
- };
+ await redis.set(`slack-user:${userId}`, slackUser.user.id);
+ return slackUser.user.id;
}
} catch (error) {
console.error("Failed to lookup Slack user by email:", error);
}
-
- return {
- slackToken: metadata.access_token,
- channelId: metadata.channel_id,
- };
-}
-
-export async function getSlackUserIdForCarbonUser(
- client: SupabaseClient<Database>,
- companyId: string,
- userId: string
-): Promise<string | null> {
- const auth = await getSlackAuth(client, companyId, userId);
- return auth?.slackUserId || null;
}
export async function getSlackDocumentThread(
@@ -266,7 +270,6 @@ export async function getSlackDocumentThread(
documentId: string,
companyId: string
) {
- console.log({ documentType, documentId, companyId });
return client
.from("slackDocumentThread")
.select("*")
@@ -297,13 +300,10 @@ export async function getCarbonEmployeeFromSlackId(
try {
const slackClient = createSlackWebClient({ token: accessToken });
- // Get user info from Slack
const userInfo = await slackClient.users.info({
user: slackUserId,
});
- console.log({ userInfo: userInfo.user?.profile });
-
if (!userInfo.ok || !userInfo.user?.profile?.email) {
return { data: null, error: "Could not retrieve user email from Slack" };
}
@@ -350,53 +350,26 @@ export async function syncDocumentToSlack(
}
) {
const serviceRole = getCarbonServiceRole();
- const [thread, slackUserId] = await Promise.all([
+ const [thread, slackAuth] = await Promise.all([
getSlackDocumentThread(
serviceRole,
data.documentType,
data.documentId,
data.companyId
),
- getSlackUserIdForCarbonUser(serviceRole, data.companyId, data.userId),
+ getSlackAuth(serviceRole, data.companyId, data.userId),
]);
+ if (!slackAuth) {
+ console.error("Slack auth not found for company", data.companyId);
+ return {
+ data: null,
+ error: "Slack auth not found",
+ };
+ }
+
if (thread.data) {
try {
- // Check if Slack integration is enabled for this company
- const { data: integration } = await serviceRole
- .from("companyIntegration")
- .select("metadata")
- .eq("companyId", data.companyId)
- .eq("active", true)
- .single();
-
- if (!integration?.metadata) {
- console.log("Slack integration not active for company", data.companyId);
- return {
- data: { success: true, message: "Slack integration not active" },
- error: null,
- };
- }
-
- const metadata = integration.metadata as Record<string, unknown>;
-
- // Check if notifications are enabled for this document type
- const notificationKey = `${data.documentType}_notifications_enabled`;
- if (metadata[notificationKey] === false) {
- console.log(
- `${data.documentType} notifications disabled for company`,
- data.companyId
- );
- return {
- data: {
- success: true,
- message: `${data.documentType} notifications disabled`,
- },
- error: null,
- };
- }
-
- // Trigger the appropriate Trigger.dev job
let result;
switch (data.type) {
case "created":
@@ -421,25 +394,73 @@ export async function syncDocumentToSlack(
companyId: data.companyId,
previousStatus: data.payload.previousStatus,
newStatus: data.payload.newStatus,
- updatedBy: slackUserId || data.payload.updatedBy,
+ updatedBy: slackAuth.slackUserId || data.payload.updatedBy,
}
);
break;
case "task-update":
+ let taskName = "";
+ let assignee: string | null | undefined = null;
+ const taskId = data.payload.taskId || data.documentId; // fallback for backward compatibility
+ if (data.payload.taskType === "investigation") {
+ const task = await client
+ .from("nonConformanceInvestigationTask")
+ .select(
+ "assignee, status, ...nonConformanceInvestigationType(name)"
+ )
+ .eq("id", taskId)
+ .single();
+ taskName = task.data?.name || "";
+ assignee = task.data?.assignee
+ ? await getSlackUserIdByCarbonId(
+ client,
+ slackAuth.slackToken,
+ task.data?.assignee || ""
+ )
+ : null;
+ } else if (data.payload.taskType === "action") {
+ const task = await client
+ .from("nonConformanceActionTask")
+ .select("assignee,status, ...nonConformanceRequiredAction(name)")
+ .eq("id", taskId)
+ .single();
+
+ taskName = task.data?.name || "";
+ assignee = task.data?.assignee
+ ? await getSlackUserIdByCarbonId(
+ client,
+ slackAuth.slackToken,
+ task.data?.assignee || ""
+ )
+ : null;
+ } else if (data.payload.taskType === "approval") {
+ const task = await client
+ .from("nonConformanceApprovalTask")
+ .select("assignee, status, approvalType")
+ .eq("id", taskId)
+ .single();
+
+ taskName = task.data?.approvalType || "";
+ assignee = task.data?.assignee
+ ? await getSlackUserIdByCarbonId(
+ client,
+ slackAuth.slackToken,
+ task.data?.assignee || ""
+ )
+ : "";
+ }
result = await tasks.trigger<typeof slackDocumentTaskUpdate>(
"slack-document-task-update",
{
+ assignee,
documentType: data.documentType,
documentId: data.documentId,
companyId: data.companyId,
+ taskName,
taskType: data.payload.taskType,
- taskName: data.payload.taskName,
status: data.payload.status,
- assignedTo: data.payload.assignedTo,
- completedBy: data.payload.completedBy || slackUserId,
completedAt: data.payload.completedAt,
- notes: data.payload.notes,
}
);
break;
@@ -453,7 +474,7 @@ export async function syncDocumentToSlack(
companyId: data.companyId,
previousAssignee: data.payload.previousAssignee,
newAssignee: data.payload.newAssignee,
- updatedBy: slackUserId || data.payload.updatedBy,
+ updatedBy: slackAuth.slackUserId || data.payload.updatedBy,
}
);
break;
@@ -483,13 +504,13 @@ export async function syncDocumentToSlack(
export async function syncDocumentCreatedToSlack(
client: SupabaseClient<Database>,
data: {
- documentType: DocumentType;
- documentId: string;
- companyId: string;
- userId: string;
channelId: string;
- threadTs: string;
+ companyId: string;
+ documentId: string;
+ documentType: DocumentType;
metadata?: Record<string, any>;
+ threadTs: string;
+ userId: string;
}
) {
return syncDocumentToSlack(client, {
@@ -565,12 +586,12 @@ export async function syncDocumentAssignmentToSlack(
export async function syncDocumentCustomToSlack(
client: SupabaseClient<Database>,
data: {
- documentType: DocumentType;
- documentId: string;
companyId: string;
- userId: string;
customType: string;
+ documentId: string;
+ documentType: DocumentType;
payload: Record<string, any>;
+ userId: string;
}
) {
return syncDocumentToSlack(client, {
@@ -589,12 +610,12 @@ export async function syncDocumentCustomToSlack(
export async function syncIssueStatusToSlack(
client: SupabaseClient<Database>,
data: {
- nonConformanceId: string;
companyId: string;
- userId: string;
- previousStatus: string;
newStatus: string;
+ nonConformanceId: string;
+ previousStatus: string;
reason?: string;
+ userId: string;
}
) {
return syncDocumentStatusToSlack(client, {
@@ -611,15 +632,13 @@ export async function syncIssueStatusToSlack(
export async function syncIssueTaskToSlack(
client: SupabaseClient<Database>,
data: {
- nonConformanceId: string;
companyId: string;
- userId: string;
- taskType: "investigation" | "action" | "approval";
- taskName: string;
- status: string;
- assignedTo?: string;
completedAt?: string;
- notes?: string;
+ id: string;
+ nonConformanceId: string;
+ status: string;
+ taskType: "investigation" | "action" | "approval";
+ userId: string;
}
) {
return syncDocumentToSlack(client, {
@@ -629,13 +648,10 @@ export async function syncIssueTaskToSlack(
userId: data.userId,
type: "task-update",
payload: {
+ taskId: data.id,
taskType: data.taskType,
- taskName: data.taskName,
status: data.status,
- assignedTo: data.assignedTo,
- completedBy: data.status === "Completed" ? data.userId : undefined,
completedAt: data.completedAt,
- notes: data.notes,
},
});
}
diff --git a/packages/jobs/trigger/slack-document-sync.ts b/packages/jobs/trigger/slack-document-sync.ts
index e35febe7af..6238231c11 100644
--- a/packages/jobs/trigger/slack-document-sync.ts
+++ b/packages/jobs/trigger/slack-document-sync.ts
@@ -1,8 +1,9 @@
import { getCarbonServiceRole, VERCEL_URL } from "@carbon/auth";
+import type { Database } from "@carbon/database";
import { WebClient } from "@slack/web-api";
+import type { SupabaseClient } from "@supabase/supabase-js";
import { task } from "@trigger.dev/sdk/v3";
-// Type definitions
type DocumentType =
| "nonConformance"
| "quote"
@@ -45,7 +46,8 @@ interface TaskUpdate {
taskType: "investigation" | "action" | "approval";
taskName: string;
status: string;
- assignedTo?: string;
+ assignee?: string | null;
+ readableId?: string;
completedBy?: string;
completedAt?: string;
notes?: string;
@@ -57,9 +59,6 @@ interface AssignmentUpdate {
updatedBy: string;
}
-/**
- * Post initial document creation message to Slack
- */
export const slackDocumentCreated = task({
id: "slack-document-created",
run: async (payload: {
@@ -75,7 +74,6 @@ export const slackDocumentCreated = task({
try {
const serviceRole = await getCarbonServiceRole();
- // Get the document details based on type
const documentData = await getDocumentData(
serviceRole,
documentType,
@@ -87,7 +85,6 @@ export const slackDocumentCreated = task({
throw new Error(`${documentType} ${documentId} not found`);
}
- // Get the Slack integration
const { data: integration } = await serviceRole
.from("companyIntegration")
.select("metadata")
@@ -102,7 +99,6 @@ export const slackDocumentCreated = task({
const slackToken = (integration.metadata as any)?.access_token as string;
const baseUrl = VERCEL_URL || "http://localhost:3000";
- // Post detailed information to the thread
await postToSlackThread({
token: slackToken,
channelId,
@@ -118,9 +114,6 @@ export const slackDocumentCreated = task({
},
});
-/**
- * Post status update to Slack thread
- */
export const slackDocumentStatusUpdate = task({
id: "slack-document-status-update",
run: async (payload: {
@@ -145,7 +138,6 @@ export const slackDocumentStatusUpdate = task({
try {
const serviceRole = await getCarbonServiceRole();
- // Get the Slack thread for this document
const { data: thread } = await serviceRole
.from("slackDocumentThread")
.select("channelId, threadTs")
@@ -158,7 +150,6 @@ export const slackDocumentStatusUpdate = task({
return { success: true, message: "No Slack thread found" };
}
- // Get the Slack integration
const { data: integration } = await serviceRole
.from("companyIntegration")
.select("metadata")
@@ -172,8 +163,7 @@ export const slackDocumentStatusUpdate = task({
const slackToken = (integration.metadata as any).access_token as string;
- // Get the document identifier for display
- const documentIdentifier = await getDocumentIdentifier(
+ const documentIdentifier = await getDocumentReadableId(
serviceRole,
documentType,
documentId,
@@ -187,7 +177,6 @@ export const slackDocumentStatusUpdate = task({
reason,
};
- // Post status update to the thread
await postToSlackThread({
token: slackToken,
channelId: thread.channelId,
@@ -210,9 +199,6 @@ export const slackDocumentStatusUpdate = task({
},
});
-/**
- * Post task update to Slack thread (mainly for non-conformances)
- */
export const slackDocumentTaskUpdate = task({
id: "slack-document-task-update",
run: async (payload: {
@@ -222,10 +208,8 @@ export const slackDocumentTaskUpdate = task({
taskType: "investigation" | "action" | "approval";
taskName: string;
status: string;
- assignedTo?: string;
- completedBy?: string;
+ assignee?: string | null;
completedAt?: string;
- notes?: string;
}) => {
const {
documentType,
@@ -234,16 +218,13 @@ export const slackDocumentTaskUpdate = task({
taskType,
taskName,
status,
- assignedTo,
- completedBy,
+ assignee,
completedAt,
- notes,
} = payload;
try {
const serviceRole = await getCarbonServiceRole();
- // Get the Slack thread for this document
const { data: thread } = await serviceRole
.from("slackDocumentThread")
.select("channelId, threadTs")
@@ -256,7 +237,6 @@ export const slackDocumentTaskUpdate = task({
return { success: true, message: "No Slack thread found" };
}
- // Get the Slack integration
const { data: integration } = await serviceRole
.from("companyIntegration")
.select("metadata")
@@ -270,8 +250,7 @@ export const slackDocumentTaskUpdate = task({
const slackToken = (integration.metadata as any).access_token as string;
- // Get the document identifier for display
- const documentIdentifier = await getDocumentIdentifier(
+ const documentIdentifier = await getDocumentReadableId(
serviceRole,
documentType,
documentId,
@@ -282,13 +261,10 @@ export const slackDocumentTaskUpdate = task({
taskType,
taskName,
status,
- assignedTo,
- completedBy,
+ assignee,
completedAt,
- notes,
};
- // Post task update to the thread
await postToSlackThread({
token: slackToken,
channelId: thread.channelId,
@@ -307,9 +283,6 @@ export const slackDocumentTaskUpdate = task({
},
});
-/**
- * Post assignment update to Slack thread
- */
export const slackDocumentAssignmentUpdate = task({
id: "slack-document-assignment-update",
run: async (payload: {
@@ -332,7 +305,6 @@ export const slackDocumentAssignmentUpdate = task({
try {
const serviceRole = await getCarbonServiceRole();
- // Get the Slack thread for this document
const { data: thread } = await serviceRole
.from("slackDocumentThread")
.select("channelId, threadTs")
@@ -345,7 +317,6 @@ export const slackDocumentAssignmentUpdate = task({
return { success: true, message: "No Slack thread found" };
}
- // Get the Slack integration
const { data: integration } = await serviceRole
.from("companyIntegration")
.select("metadata")
@@ -359,8 +330,7 @@ export const slackDocumentAssignmentUpdate = task({
const slackToken = (integration.metadata as any).access_token as string;
- // Get the document identifier for display
- const documentIdentifier = await getDocumentIdentifier(
+ const documentIdentifier = await getDocumentReadableId(
serviceRole,
documentType,
documentId,
@@ -373,7 +343,6 @@ export const slackDocumentAssignmentUpdate = task({
updatedBy,
};
- // Post assignment update to the thread
await postToSlackThread({
token: slackToken,
channelId: thread.channelId,
@@ -396,11 +365,8 @@ export const slackDocumentAssignmentUpdate = task({
},
});
-/**
- * Helper function to get document data based on type
- */
async function getDocumentData(
- serviceRole: any,
+ serviceRole: SupabaseClient<Database>,
documentType: DocumentType,
documentId: string,
companyId: string
@@ -409,53 +375,25 @@ async function getDocumentData(
case "nonConformance": {
const { data } = await serviceRole
.from("nonConformance")
- .select(
- `
- *,
- type:typeId(name),
- workflow:workflowId(name)
- `
- )
+ .select("*")
.eq("id", documentId)
.eq("companyId", companyId)
.single();
if (!data) return null;
- // Get investigation and action tasks
- const [investigations, actions] = await Promise.all([
- serviceRole
- .from("nonConformanceInvestigationTask")
- .select("investigationType")
- .eq("nonConformanceId", documentId)
- .eq("companyId", companyId),
- serviceRole
- .from("nonConformanceActionTask")
- .select("actionType")
- .eq("nonConformanceId", documentId)
- .eq("companyId", companyId),
- ]);
-
return {
documentType: "nonConformance",
id: data.id,
nonConformanceId: data.nonConformanceId,
- title: data.title,
+ title: data.name,
description: data.description,
status: data.status,
- severity: data.severity,
- typeId: data.typeId,
- typeName: data.type?.name,
- workflowName: data.workflow?.name,
createdBy: data.createdBy,
createdAt: data.createdAt,
- investigationTypes:
- investigations.data?.map((i) => i.investigationType) || [],
- requiredActions: actions.data?.map((a) => a.actionType) || [],
} as NonConformanceData;
}
- // Add other document types here in the future
case "quote":
case "salesOrder":
case "job":
@@ -465,11 +403,8 @@ async function getDocumentData(
}
}
-/**
- * Helper function to get document identifier for display
- */
-async function getDocumentIdentifier(
- serviceRole: any,
+async function getDocumentReadableId(
+ serviceRole: SupabaseClient<Database>,
documentType: DocumentType,
documentId: string,
companyId: string
@@ -484,15 +419,11 @@ async function getDocumentIdentifier(
return data?.nonConformanceId || documentId;
}
- // Add other document types here
default:
return documentId;
}
}
-/**
- * Helper function to post messages to a Slack thread
- */
async function postToSlackThread(params: {
token: string;
channelId: string;
@@ -512,9 +443,6 @@ async function postToSlackThread(params: {
});
}
-/**
- * Format document creation message for Slack
- */
function formatDocumentCreated(data: DocumentData, baseUrl: string): any[] {
const blocks: any[] = [];
@@ -623,9 +551,6 @@ function formatDocumentCreated(data: DocumentData, baseUrl: string): any[] {
return blocks;
}
-/**
- * Format status update message for Slack
- */
function formatStatusUpdate(
documentType: DocumentType,
documentIdentifier: string,
@@ -639,7 +564,7 @@ function formatStatusUpdate(
type: "section",
text: {
type: "mrkdwn",
- text: `${emoji} *Status Updated*\n${documentIdentifier}`,
+ text: `${emoji} *Issue Status Updated*\n${documentIdentifier}`,
},
});
@@ -682,9 +607,6 @@ function formatStatusUpdate(
return blocks;
}
-/**
- * Format task update message for Slack
- */
function formatTaskUpdate(
documentType: DocumentType,
documentIdentifier: string,
@@ -719,17 +641,17 @@ function formatTaskUpdate(
},
];
- if (update.assignedTo) {
+ if (update.assignee) {
fields.push({
type: "mrkdwn",
- text: `*Assigned To:*\n${update.assignedTo}`,
+ text: `*Assigned To:*\n<@${update.assignee}>`,
});
}
if (update.completedBy) {
fields.push({
type: "mrkdwn",
- text: `*Completed By:*\n${update.completedBy}`,
+ text: `*Completed By:*\n<@${update.completedBy}>`,
});
}
@@ -763,9 +685,6 @@ function formatTaskUpdate(
return blocks;
}
-/**
- * Format assignment update message for Slack
- */
function formatAssignmentUpdate(
documentType: DocumentType,
documentIdentifier: string,
@@ -815,9 +734,6 @@ function formatAssignmentUpdate(
return blocks;
}
-/**
- * Get emoji for status
- */
function getStatusEmoji(status: string): string {
const statusLower = status.toLowerCase();
@@ -840,9 +756,6 @@ function getStatusEmoji(status: string): string {
return "📌";
}
-/**
- * Get emoji for task status
- */
function getTaskStatusEmoji(status: string): string {
const statusLower = status.toLowerCase();
@@ -859,7 +772,6 @@ function getTaskStatusEmoji(status: string): string {
return "📝";
}
-// Backward compatibility exports
export const slackNcrCreated = slackDocumentCreated;
export const slackNcrStatusUpdate = slackDocumentStatusUpdate;
export const slackNcrTaskUpdate = slackDocumentTaskUpdate;