mirror of
https://github.com/baptisteArno/typebot.io.git
synced 2026-06-05 21:04:43 +08:00
🐛 Make saveClientLogs retro compatible
This commit is contained in:
parent
c83cfbcb4c
commit
a67204c8dc
@ -1,4 +1,4 @@
|
||||
---
|
||||
title: 'Save logs'
|
||||
openapi: POST /v1/sessions/{sessionId}/clientLogs
|
||||
openapi: POST /v2/sessions/{sessionId}/clientLogs
|
||||
---
|
||||
|
||||
@ -3808,6 +3808,98 @@
|
||||
}
|
||||
},
|
||||
"/v1/sessions/{sessionId}/clientLogs": {
|
||||
"post": {
|
||||
"operationId": "saveClientLogsV1",
|
||||
"summary": "Save logs",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "sessionId",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
},
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"required": true,
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"clientLogs": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"status": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
"context": {
|
||||
"type": "string"
|
||||
},
|
||||
"details": {}
|
||||
},
|
||||
"required": [
|
||||
"description"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"clientLogs"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Successful response",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"message": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"message"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid input data",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/error.BAD_REQUEST"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal server error",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/error.INTERNAL_SERVER_ERROR"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v2/sessions/{sessionId}/clientLogs": {
|
||||
"post": {
|
||||
"operationId": "saveClientLogs",
|
||||
"summary": "Save logs",
|
||||
|
||||
34
apps/viewer/src/features/chat/api/legacy/saveClientLogsV1.ts
Normal file
34
apps/viewer/src/features/chat/api/legacy/saveClientLogsV1.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import { publicProcedure } from "@/helpers/server/trpc";
|
||||
import { saveClientLogs as saveClientLogsFn } from "@typebot.io/bot-engine/apiHandlers/saveClientLogs";
|
||||
import { safeStringify } from "@typebot.io/lib/safeStringify";
|
||||
import { logInSessionSchema } from "@typebot.io/logs/schemas";
|
||||
import { z } from "@typebot.io/zod";
|
||||
|
||||
export const saveClientLogsV1 = publicProcedure
|
||||
.meta({
|
||||
openapi: {
|
||||
method: "POST",
|
||||
path: "/v1/sessions/{sessionId}/clientLogs",
|
||||
summary: "Save logs",
|
||||
},
|
||||
})
|
||||
.input(
|
||||
z.object({
|
||||
sessionId: z.string(),
|
||||
clientLogs: z.array(
|
||||
logInSessionSchema
|
||||
.omit({ details: true })
|
||||
.extend({ details: z.unknown().optional() }),
|
||||
),
|
||||
}),
|
||||
)
|
||||
.output(z.object({ message: z.string() }))
|
||||
.mutation(({ input: { sessionId, clientLogs } }) => {
|
||||
const parsedLogs = clientLogs.map((log) => ({
|
||||
...log,
|
||||
details: log.details
|
||||
? (safeStringify(log.details) ?? undefined)
|
||||
: undefined,
|
||||
}));
|
||||
return saveClientLogsFn({ sessionId, clientLogs: parsedLogs });
|
||||
});
|
||||
@ -7,7 +7,7 @@ export const saveClientLogs = publicProcedure
|
||||
.meta({
|
||||
openapi: {
|
||||
method: "POST",
|
||||
path: "/v1/sessions/{sessionId}/clientLogs",
|
||||
path: "/v2/sessions/{sessionId}/clientLogs",
|
||||
summary: "Save logs",
|
||||
},
|
||||
})
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { continueChat } from "@/features/chat/api/continueChat";
|
||||
import { saveClientLogsV1 } from "@/features/chat/api/legacy/saveClientLogsV1";
|
||||
import { sendMessageV1 } from "@/features/chat/api/legacy/sendMessageV1";
|
||||
import { sendMessageV2 } from "@/features/chat/api/legacy/sendMessageV2";
|
||||
import { saveClientLogs } from "@/features/chat/api/saveClientLogs";
|
||||
@ -24,6 +25,7 @@ export const appRouter = router({
|
||||
generateUploadUrl,
|
||||
updateTypebotInSession,
|
||||
whatsAppRouter,
|
||||
saveClientLogsV1,
|
||||
saveClientLogs,
|
||||
});
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@typebot.io/js",
|
||||
"version": "0.3.58",
|
||||
"version": "0.3.59",
|
||||
"description": "Javascript library to display typebots on your website",
|
||||
"license": "FSL-1.1-ALv2",
|
||||
"type": "module",
|
||||
|
||||
@ -16,7 +16,7 @@ export const saveClientLogsQuery = async ({
|
||||
await ky.post(
|
||||
`${
|
||||
isNotEmpty(apiHost) ? apiHost : guessApiHost()
|
||||
}/api/v1/sessions/${sessionId}/clientLogs`,
|
||||
}/api/v2/sessions/${sessionId}/clientLogs`,
|
||||
{
|
||||
json: {
|
||||
clientLogs,
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@typebot.io/nextjs",
|
||||
"version": "0.3.58",
|
||||
"version": "0.3.59",
|
||||
"license": "FSL-1.1-ALv2",
|
||||
"description": "Convenient library to display typebots on your Next.js website",
|
||||
"type": "module",
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@typebot.io/react",
|
||||
"version": "0.3.58",
|
||||
"version": "0.3.59",
|
||||
"description": "Convenient library to display typebots on your React app",
|
||||
"license": "FSL-1.1-ALv2",
|
||||
"type": "module",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user