🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(support): improve context in initial support email (#8966)
Michael Fröhlich06bb3bbf4341
diff --git a/web/src/features/support-chat/plain/plainClient.ts b/web/src/features/support-chat/plain/plainClient.tsindex 11fbb8aa70..55f821b824 100644--- a/web/src/features/support-chat/plain/plainClient.ts+++ b/web/src/features/support-chat/plain/plainClient.ts@@ -73,8 +73,8 @@ function unwrap<T>(label: string, res: { data?: T; error?: unknown }): T {if (res.error) {logger.error(`${label} failed`, describeSdkError(res.error));throw new TRPCError({- code: "BAD_REQUEST",- message: `${label} failed`,+ code: "INTERNAL_SERVER_ERROR",+ message: `Plain Client: ${label} failed`,cause: res.error,});}@@ -82,7 +82,7 @@ function unwrap<T>(label: string, res: { data?: T; error?: unknown }): T {logger.error(`${label} returned no data`, res);throw new TRPCError({code: "INTERNAL_SERVER_ERROR",- message: `${label} returned no data`,+ message: `Plain Client: ${label} returned no data`,});}return res.data;@@ -112,7 +112,7 @@ export async function ensureCustomer(},});- const upsertData = unwrap("upsertCustomer", upsert);+ const upsertData = unwrap("upsertCustomer", upsert); // throws on errorconst customerId = upsertData.customer?.id;if (!customerId) {throw new TRPCError({@@ -140,7 +140,7 @@ export async function createAttachmentUploadUrls(attachmentType: AttachmentType.Email,});- const data = unwrap("createAttachmentUploadUrl", r);+ const data = unwrap("createAttachmentUploadUrl", r); // throws on errorout.push({attachmentId: data.attachment.id,uploadFormUrl: data.uploadFormUrl,@@ -426,7 +426,7 @@ export async function createSupportThread(attachmentIds: attachmentIds.length ? attachmentIds : undefined,});- const thread = unwrap("createThread (retry without threadFields)", retry);+ const thread = unwrap("createThread (retry without threadFields)", retry); // throws on errorconst createdAt =thread.createdAt?.__typename === "DateTime"? thread.createdAt.iso8601@@ -440,7 +440,7 @@ export async function createSupportThread(};}- const thread = unwrap("createThread", createdWithFields);+ const thread = unwrap("createThread", createdWithFields); // throws on errorconst createdAt =thread.createdAt?.__typename === "DateTime"? thread.createdAt.iso8601@@ -474,6 +474,11 @@ export async function createThreadEvent(if (res.error) {logger.error("createThreadEvent failed", describeSdkError(res.error));+ throw new TRPCError({+ code: "INTERNAL_SERVER_ERROR",+ message: "Plain Client: createThreadEvent failed",+ cause: res.error,+ });}}@@ -511,6 +516,11 @@ export async function replyToThread(if (res.error) {logger.error("replyToThread failed", describeSdkError(res.error));+ throw new TRPCError({+ code: "INTERNAL_SERVER_ERROR",+ message: "Plain Client: replyToThread failed",+ cause: res.error,+ });}return res;@@ -529,6 +539,7 @@ export async function createThread(url?: string;integrationType?: string;tenantExternalId?: string;+ message?: string;},): Promise<CreateSupportThreadResult> {const { client } = ctx;@@ -550,6 +561,7 @@ export async function createThread(tenantIdentifier: input.tenantExternalId? { externalId: input.tenantExternalId }: undefined,+ description: input.message,});if (createdWithFields.error) {@@ -565,6 +577,7 @@ export async function createThread(tenantIdentifier: input.tenantExternalId? { externalId: input.tenantExternalId }: undefined,+ description: input.message,});const thread = unwrap(@@ -597,34 +610,3 @@ export async function createThread(createdWithThreadFields: true,};}--// ===== Email acknowledgement (best-effort / non-throwing) =====-export async function sendAcknowledgementEmail(- ctx: PlainCtx,- input: {- threadId: string;- customerId: string;- userEmail: string;- originalMessage: string;- },-) {- const { client } = ctx;- const subject = "Langfuse: We received your message";- const textContent = `You have opened a new thread with Langfuse Support.\n\nYour message:\n\n${input.originalMessage}\n\nRespond to this email to add any additional context.`;- const markdownContent = `You have opened a new thread with Langfuse Support\n\n\n**Your message:**\n\n\n${input.originalMessage}\n\n\nRespond to this email to add any additional context.`;-- const res = await client.sendNewEmail({- customerId: input.customerId,- threadId: input.threadId,- subject,- textContent,- markdownContent,- });-- if (res.error) {- logger.error(- "sendNewEmail (acknowledgement) failed",- describeSdkError(res.error),- );- }-}diff --git a/web/src/features/support-chat/trpc/plainRouter.ts b/web/src/features/support-chat/trpc/plainRouter.tsindex 24c611fe26..848b976c6f 100644--- a/web/src/features/support-chat/trpc/plainRouter.ts+++ b/web/src/features/support-chat/trpc/plainRouter.ts@@ -257,36 +257,30 @@ export const plainRouter = createTRPCRouter({// best-effort; errors are logged in helpers}- // (5) Post the user's original message as the first reply (impersonated), including attachments+ // (5) Write user email as part of first reply to trigger emailawait replyToThread(plain, {threadId,userEmail: email,- originalMessage: input.message,+ originalMessage: [+ "Hi there,",+ "",+ " thanks for reaching out! We’ve received your request and will follow up as soon as possible.",+ "",+ "To help us move faster, feel free to reply to this email with:",+ "- any error messages or screenshots",+ "- links to where you’re seeing the issue (trace, page, dataset)",+ "- steps to reproduce (if relevant)",+ "",+ "Thanks,",+ "",+ "Team Langfuse",+ "",+ `${email} wrote:`,+ "",+ input.message,+ "",+ ].join("\n"),attachmentIds: input.attachmentIds ?? [],- impersonate: true,- });-- // Note: Plain seems to process the message asynchronously, so we need to wait a bit- // to ensure the first message is processed. If we send the second message too early, the user- // will receive only the second message and not their own below it.- //- // Monkey-Testing:- // - 1000ms: doesn't work- // - 2000ms: doesn't work- // - 3000ms: doesn't work- // - 4000ms: works sometimes- // - 5000ms: works sometimes- //- // Observation: The more attachments, the longer we need to wait and PDFs seem to- // take longer to process on plain's side.- const waitTimeInMs = 5000 + (input.attachmentIds?.length ?? 0) * 1000;- await new Promise((resolve) => setTimeout(resolve, waitTimeInMs));-- // (6) Acknowledge non-impersonated so it appears from Langfuse Cloud- await replyToThread(plain, {- threadId,- userEmail: email,- originalMessage: `Hi there,\n\n thanks for reaching out! We’ve received your request and will follow up as soon as possible.\n\nTo help us move faster, feel free to reply to this email with:\n- any error messages or screenshots\n- links to where you’re seeing the issue (trace, page, dataset)\n- steps to reproduce (if relevant)\n\nThanks,\n\nTeam Langfuse`,impersonate: false,});