Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

markdownToSlackMrkdwn

Pedro Ladeirac9b3b73303d9
diff --git a/apps/web/app/api/ai/support-chat/route.ts b/apps/web/app/api/ai/support-chat/route.ts
index 539e9634d8..b09bb0f4a1 100644
--- a/apps/web/app/api/ai/support-chat/route.ts
+++ b/apps/web/app/api/ai/support-chat/route.ts
@@ -118,7 +118,7 @@ export const POST = withSession(async ({ req, session }) => {
await postSupportChatMessage({
channel: slackChannel,
threadTs: slackThreadTs,
- text: `*Dub AI:* ${text}`,
+ text: `*Dub AI:*\n${markdownToSlackMrkdwn(text)}`,
});
}
},
@@ -170,3 +170,13 @@ const getAccountContextLines = (globalContext?: GlobalChatContext) => {
return [globalContext?.chatLocation ?? "Unknown context"];
};
+
+const markdownToSlackMrkdwn = (text: string) =>
+ text
+ .replace(/\[([^\]]+)\]\(([^)]+)\)/g, "<$2|$1>")
+ .replace(/\*\*([^*]+)\*\*/g, "*$1*")
+ .replace(/__([^_]+)__/g, "*$1*")
+ .replace(/~~([^~]+)~~/g, "~$1~")
+ .replace(/^#{1,6}\s+(.+)$/gm, "*$1*")
+ .replace(/^[*+]\s+/gm, "- ")
+ .trim();