feat: survey add webhook url field which can send webhook when receive any survey
This commit is contained in:
parent
fd63f2a22e
commit
8a6a75f3f5
@ -2,7 +2,7 @@ import { createFileRoute, useNavigate } from '@tanstack/react-router';
|
||||
import { useTranslation } from '@i18next-toolkit/react';
|
||||
import { useEvent } from '@/hooks/useEvent';
|
||||
import { useCurrentWorkspaceId } from '@/store/user';
|
||||
import { trpc } from '@/api/trpc';
|
||||
import { defaultErrorHandler, trpc } from '@/api/trpc';
|
||||
import { Card, CardContent } from '@/components/ui/card';
|
||||
import { CommonWrapper } from '@/components/CommonWrapper';
|
||||
import { routeAuthBeforeLoad } from '@/utils/route';
|
||||
@ -25,7 +25,9 @@ function PageComponent() {
|
||||
const { surveyId } = Route.useParams<{ surveyId: string }>();
|
||||
const workspaceId = useCurrentWorkspaceId();
|
||||
const navigate = useNavigate();
|
||||
const mutation = trpc.survey.update.useMutation();
|
||||
const mutation = trpc.survey.update.useMutation({
|
||||
onError: defaultErrorHandler,
|
||||
});
|
||||
const { data: survey, isLoading } = trpc.survey.get.useQuery({
|
||||
workspaceId,
|
||||
surveyId,
|
||||
|
@ -1,3 +1,8 @@
|
||||
import { version } from '@tianji/shared';
|
||||
import axios from 'axios';
|
||||
|
||||
axios.defaults.headers.common['User-Agent'] = `tianji/${version}`;
|
||||
|
||||
(BigInt.prototype as any).toJSON = function () {
|
||||
const int = Number.parseInt(this.toString());
|
||||
return int ?? this.toString();
|
||||
|
@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Survey" ADD COLUMN "webhookUrl" TEXT NOT NULL DEFAULT '';
|
@ -18,6 +18,7 @@ export const SurveyModelSchema = z.object({
|
||||
payload: imports.SurveyPayloadSchema,
|
||||
feedChannelIds: z.string().array(),
|
||||
feedTemplate: z.string(),
|
||||
webhookUrl: z.string(),
|
||||
createdAt: z.date(),
|
||||
updatedAt: z.date(),
|
||||
})
|
||||
|
@ -192,7 +192,7 @@ export const surveyRouter = router({
|
||||
survey.feedTemplate ||
|
||||
'survey {{_surveyName}} receive a new record.';
|
||||
|
||||
survey.feedChannelIds.forEach((channelId) => {
|
||||
survey.feedChannelIds.forEach(async (channelId) => {
|
||||
try {
|
||||
const surveyPayload = SurveyPayloadSchema.parse(survey.payload);
|
||||
|
||||
@ -220,11 +220,13 @@ export const surveyRouter = router({
|
||||
|
||||
if (survey && survey.webhookUrl) {
|
||||
axios
|
||||
.post(survey.webhookUrl)
|
||||
.then(() => {
|
||||
return axios.post(survey.webhookUrl, {
|
||||
.post(survey.webhookUrl, {
|
||||
...result,
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
logger.info(
|
||||
`[surveySubmitWebhook] send webhooks to ${survey.webhookUrl} success!`
|
||||
);
|
||||
})
|
||||
.catch((err) => logger.error('[surveySubmitWebhook]', err));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user