fix: long answer (#4654)

Co-authored-by: Dhruwang <dhruwangjariwala18@gmail.com>
Co-authored-by: Dhruwang Jariwala <67850763+Dhruwang@users.noreply.github.com>
Co-authored-by: Piyush Gupta <piyushguptaa2z123@gmail.com>
This commit is contained in:
Paribesh Nepal
2025-01-27 13:03:29 +05:30
committed by GitHub
parent e691c076a1
commit d28f321aa2
6 changed files with 46 additions and 5 deletions
@@ -1,5 +1,6 @@
import { TPipelineInput } from "@/app/api/(internal)/pipeline/types/pipelines";
import { writeData as airtableWriteData } from "@formbricks/lib/airtable/service";
import { NOTION_RICH_TEXT_LIMIT } from "@formbricks/lib/constants";
import { writeData } from "@formbricks/lib/googleSheet/service";
import { getLocalizedValue } from "@formbricks/lib/i18n/utils";
import { writeData as writeNotionData } from "@formbricks/lib/notion/service";
@@ -7,6 +8,7 @@ import { processResponseData } from "@formbricks/lib/responses";
import { writeDataToSlack } from "@formbricks/lib/slack/service";
import { getFormattedDateTimeString } from "@formbricks/lib/utils/datetime";
import { parseRecallInfo } from "@formbricks/lib/utils/recall";
import { truncateText } from "@formbricks/lib/utils/strings";
import { TAttributes } from "@formbricks/types/attributes";
import { TContactAttributes } from "@formbricks/types/contact-attribute";
import { Result } from "@formbricks/types/error-handlers";
@@ -392,6 +394,16 @@ const getValue = (colType: string, value: string | string[] | Date | number | Re
},
];
case "rich_text":
if (typeof value === "string") {
return [
{
text: {
content:
value.length > NOTION_RICH_TEXT_LIMIT ? truncateText(value, NOTION_RICH_TEXT_LIMIT) : value,
},
},
];
}
return [
{
text: {
+8 -3
View File
@@ -11,8 +11,9 @@ import {
ZIntegrationAirtableTablesWithFields,
ZIntegrationAirtableTokenSchema,
} from "@formbricks/types/integration/airtable";
import { AIRTABLE_CLIENT_ID } from "../constants";
import { AIRTABLE_CLIENT_ID, AIRTABLE_MESSAGE_LIMIT } from "../constants";
import { createOrUpdateIntegration, deleteIntegration, getIntegrationByType } from "../integration/service";
import { truncateText } from "../utils/strings";
export const getBases = async (key: string) => {
const req = await fetch("https://api.airtable.com/v0/meta/bases", {
@@ -153,8 +154,9 @@ const addRecords = async (
typecast: true,
}),
});
const res = await req.json();
return await req.json();
return res;
};
const addField = async (
@@ -185,7 +187,10 @@ export const writeData = async (
const data: Record<string, string> = {};
for (let i = 0; i < questions.length; i++) {
data[questions[i]] = responses[i];
data[questions[i]] =
responses[i].length > AIRTABLE_MESSAGE_LIMIT
? truncateText(responses[i], AIRTABLE_MESSAGE_LIMIT)
: responses[i];
}
const req = await tableFetcher(key, configData.baseId);
+5
View File
@@ -88,6 +88,11 @@ export const MAX_RESPONSES_FOR_INSIGHT_GENERATION = 500;
export const DEFAULT_ORGANIZATION_ID = env.DEFAULT_ORGANIZATION_ID;
export const DEFAULT_ORGANIZATION_ROLE = env.DEFAULT_ORGANIZATION_ROLE;
export const SLACK_MESSAGE_LIMIT = 2995;
export const GOOGLE_SHEET_MESSAGE_LIMIT = 49995;
export const AIRTABLE_MESSAGE_LIMIT = 99995;
export const NOTION_RICH_TEXT_LIMIT = 1995;
// Storage constants
export const S3_ACCESS_KEY = env.S3_ACCESS_KEY;
export const S3_SECRET_KEY = env.S3_SECRET_KEY;
+9 -1
View File
@@ -12,7 +12,9 @@ import {
GOOGLE_SHEETS_CLIENT_SECRET,
GOOGLE_SHEETS_REDIRECT_URL,
} from "../constants";
import { GOOGLE_SHEET_MESSAGE_LIMIT } from "../constants";
import { createOrUpdateIntegration } from "../integration/service";
import { truncateText } from "../utils/strings";
import { validateInputs } from "../utils/validate";
const { google } = require("googleapis");
@@ -31,7 +33,13 @@ export const writeData = async (
try {
const authClient = await authorize(integrationData);
const sheets = google.sheets({ version: "v4", auth: authClient });
const responses = { values: [values[0]] };
const responses = {
values: [
values[0].map((value) =>
value.length > GOOGLE_SHEET_MESSAGE_LIMIT ? truncateText(value, GOOGLE_SHEET_MESSAGE_LIMIT) : value
),
],
};
const question = { values: [values[1]] };
sheets.spreadsheets.values.update(
{
+8 -1
View File
@@ -2,7 +2,9 @@ import { Prisma } from "@prisma/client";
import { DatabaseError, UnknownError } from "@formbricks/types/errors";
import { TIntegration, TIntegrationItem } from "@formbricks/types/integration";
import { TIntegrationSlack, TIntegrationSlackCredential } from "@formbricks/types/integration/slack";
import { SLACK_MESSAGE_LIMIT } from "../constants";
import { deleteIntegration, getIntegrationByType } from "../integration/service";
import { truncateText } from "../utils/strings";
export const fetchChannels = async (slackIntegration: TIntegration): Promise<TIntegrationItem[]> => {
let channels: TIntegrationItem[] = [];
@@ -98,11 +100,16 @@ export const writeDataToSlack = async (
text: `*${questions[i]}*`,
},
};
const responseText = responses[i];
const text =
responseText.length > SLACK_MESSAGE_LIMIT
? truncateText(responseText, SLACK_MESSAGE_LIMIT)
: responseText;
let responseSection = {
type: "section",
text: {
type: "mrkdwn",
text: `${responses[i]}\n`,
text: `${text}\n`,
},
};
blockResponse.push(questionSection, responseSection);
+4
View File
@@ -24,3 +24,7 @@ export const isCapitalized = (str: string) => str.charAt(0) === str.charAt(0).to
export const startsWithVowel = (str: string): boolean => {
return /^[aeiouAEIOU]/.test(str);
};
export const truncateText = (text: string, limit: number): string => {
return text.length > limit ? `${text.substring(0, limit)}...` : text;
};