Skip to content

Commit d0010de

Browse files
committed
Merge remote-tracking branch 'origin/pr/32'
2 parents 093cf03 + ea47190 commit d0010de

2 files changed

Lines changed: 20 additions & 8 deletions

File tree

src/commands.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,14 +1354,25 @@ async function handleEscalationButton(
13541354
actor: string,
13551355
_baseUrl: string,
13561356
): Promise<unknown> {
1357+
// Button custom_id format: esc_{action}_{companyId}_{escalationId}
1358+
// Legacy format (pre-fix): esc_{action}_{escalationId}
1359+
// CompanyId is a UUID (contains hyphens), escalationId starts with "esc_".
1360+
// We split on "_" to get the action, then look for a UUID-shaped segment.
13571361
const parts = customId.split("_");
13581362
const action = parts[1];
1359-
const escalationId = parts.slice(2).join("_");
1363+
const remaining = parts.slice(2).join("_");
13601364

1361-
ctx.logger.info("Escalation button clicked", { escalationId, action, actor });
1365+
// Try to extract embedded companyId: UUID pattern before the escalation ID
1366+
const uuidEscMatch = remaining.match(
1367+
/^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})_(esc_.+)$/i,
1368+
);
1369+
const embeddedCompanyId = uuidEscMatch ? uuidEscMatch[1] : null;
1370+
const escalationId = uuidEscMatch ? uuidEscMatch[2] : remaining;
1371+
1372+
ctx.logger.info("Escalation button clicked", { escalationId, action, actor, embeddedCompanyId });
13621373

1363-
const resolvedCompanyId = await resolveCompanyId(ctx);
1364-
const record = await getEscalation(ctx, escalationId, resolvedCompanyId) as {
1374+
const companyIdForLookup = embeddedCompanyId ?? await resolveCompanyId(ctx);
1375+
const record = await getEscalation(ctx, escalationId, companyIdForLookup) as {
13651376
escalationId: string; companyId: string; agentName: string;
13661377
reason: string; suggestedReply?: string; status: string;
13671378
} | null;

src/worker.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -612,20 +612,21 @@ const plugin = definePlugin({
612612
];
613613

614614
const buttons: DiscordComponent[] = [];
615+
const cid = payload.companyId || "default";
615616

616617
if (payload.suggestedReply) {
617618
buttons.push({
618619
type: 2,
619620
style: 3,
620621
label: "Use Suggested Reply",
621-
custom_id: `esc_suggest_${payload.escalationId}`,
622+
custom_id: `esc_suggest_${cid}_${payload.escalationId}`,
622623
});
623624
}
624625

625626
buttons.push(
626-
{ type: 2, style: 1, label: "Reply to Customer", custom_id: `esc_reply_${payload.escalationId}` },
627-
{ type: 2, style: 2, label: "Override Agent", custom_id: `esc_override_${payload.escalationId}` },
628-
{ type: 2, style: 4, label: "Dismiss", custom_id: `esc_dismiss_${payload.escalationId}` },
627+
{ type: 2, style: 1, label: "Reply to Customer", custom_id: `esc_reply_${cid}_${payload.escalationId}` },
628+
{ type: 2, style: 2, label: "Override Agent", custom_id: `esc_override_${cid}_${payload.escalationId}` },
629+
{ type: 2, style: 4, label: "Dismiss", custom_id: `esc_dismiss_${cid}_${payload.escalationId}` },
629630
);
630631

631632
const components: DiscordComponent[] = [{ type: 1, components: buttons }];

0 commit comments

Comments
 (0)