feat: integrate formbricks in help feedback box (#12276)
* feat: integrate formbricks in help feedback box * Update yarn.lock * Update yarn.lock * fix: use formbricks/api@v1.1 & set user with userId linked to feedback * fix: use separate env vars as suggested * test: Add more orgs tests (#12241) * feat: integrate formbricks in help feedback box * Update yarn.lock * fix: yarn lockfile * fix: yarn lockfile again * feat: link cal and formbricks user.id and add attributes of email and username to formbricks person object * Update yarn.lock * Update yarn.lock * fix: type safety in enums --------- Co-authored-by: Peer Richelsen <peer@cal.com> Co-authored-by: Hariom Balhara <hariombalhara@gmail.com> Co-authored-by: Peer Richelsen <peeroke@gmail.com>
This commit is contained in:
parent
2181731d64
commit
f848a44f1a
|
@ -133,6 +133,11 @@ NEXT_PUBLIC_SENDGRID_SENDER_NAME=
|
|||
# Used for capturing exceptions and logging messages
|
||||
NEXT_PUBLIC_SENTRY_DSN=
|
||||
|
||||
# Formbricks Experience Management Integration
|
||||
FORMBRICKS_HOST_URL=https://app.formbricks.com
|
||||
FORMBRICKS_ENVIRONMENT_ID=
|
||||
FORMBRICKS_FEEDBACK_SURVEY_ID=
|
||||
|
||||
# Twilio
|
||||
# Used to send SMS reminders in workflows
|
||||
TWILIO_SID=
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
import { FormbricksAPI } from "@formbricks/api";
|
||||
|
||||
import type { Feedback } from "@calcom/emails/templates/feedback-email";
|
||||
|
||||
enum Rating {
|
||||
"Extremely unsatisfied" = 1,
|
||||
"Unsatisfied" = 2,
|
||||
"Satisfied" = 3,
|
||||
"Extremely satisfied" = 4,
|
||||
}
|
||||
|
||||
export const sendFeedbackFormbricks = async (userId: number, feedback: Feedback) => {
|
||||
if (!process.env.FORMBRICKS_HOST_URL || !process.env.FORMBRICKS_ENVIRONMENT_ID)
|
||||
throw new Error("Missing FORMBRICKS_HOST_URL or FORMBRICKS_ENVIRONMENT_ID env variable");
|
||||
const api = new FormbricksAPI({
|
||||
apiHost: process.env.FORMBRICKS_HOST_URL,
|
||||
environmentId: process.env.FORMBRICKS_ENVIRONMENT_ID,
|
||||
});
|
||||
if (process.env.FORMBRICKS_FEEDBACK_SURVEY_ID) {
|
||||
const formbricksUserId = userId.toString();
|
||||
const ratingValue = Object.keys(Rating).includes(feedback.rating)
|
||||
? Rating[feedback.rating as keyof typeof Rating]
|
||||
: undefined;
|
||||
if (ratingValue === undefined) throw new Error("Invalid rating value");
|
||||
|
||||
await api.client.response.create({
|
||||
surveyId: process.env.FORMBRICKS_FEEDBACK_SURVEY_ID,
|
||||
userId: formbricksUserId,
|
||||
finished: true,
|
||||
data: {
|
||||
"formbricks-share-comments-question": feedback.comment,
|
||||
"formbricks-rating-question": ratingValue,
|
||||
},
|
||||
});
|
||||
await api.client.people.update(formbricksUserId, {
|
||||
attributes: {
|
||||
email: feedback.email,
|
||||
username: feedback.username,
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
|
@ -14,6 +14,7 @@
|
|||
"dependencies": {
|
||||
"@calcom/config": "*",
|
||||
"@calcom/dayjs": "*",
|
||||
"@formbricks/api": "^1.1.0",
|
||||
"@sendgrid/client": "^7.7.0",
|
||||
"@vercel/og": "^0.5.0",
|
||||
"bcryptjs": "^2.4.3",
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import dayjs from "@calcom/dayjs";
|
||||
import { sendFeedbackEmail } from "@calcom/emails";
|
||||
import { sendFeedbackFormbricks } from "@calcom/lib/formbricks";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
|
||||
|
||||
|
@ -30,6 +31,8 @@ export const submitFeedbackHandler = async ({ ctx, input }: SubmitFeedbackOption
|
|||
comment: comment,
|
||||
},
|
||||
});
|
||||
if (process.env.FORMBRICKS_HOST_URL && process.env.FORMBRICKS_ENVIRONMENT_ID)
|
||||
sendFeedbackFormbricks(ctx.user.id, feedback);
|
||||
|
||||
if (process.env.SEND_FEEDBACK_EMAIL && comment) sendFeedbackEmail(feedback);
|
||||
};
|
||||
|
|
|
@ -256,6 +256,9 @@
|
|||
"EMAIL_SERVER_USER",
|
||||
"EMAIL_SERVER",
|
||||
"EXCHANGE_DEFAULT_EWS_URL",
|
||||
"FORMBRICKS_HOST_URL",
|
||||
"FORMBRICKS_ENVIRONMENT_ID",
|
||||
"FORMBRICKS_FEEDBACK_SURVEY_ID",
|
||||
"GIPHY_API_KEY",
|
||||
"GITHUB_API_REPO_TOKEN",
|
||||
"GOOGLE_API_CREDENTIALS",
|
||||
|
|
Loading…
Reference in New Issue
Block a user