📈 Add telemetry webhook

Closes #357
This commit is contained in:
Baptiste Arnaud
2023-03-14 14:18:05 +01:00
parent e7132116f4
commit 9ca17e4e0b
22 changed files with 523 additions and 34 deletions

View File

@@ -107,7 +107,13 @@ export const createCheckoutSession = authenticatedProcedure
name: 'never',
},
mode: 'subscription',
metadata: { workspaceId, plan, additionalChats, additionalStorage },
metadata: {
workspaceId,
plan,
additionalChats,
additionalStorage,
userId: user.id,
},
currency,
billing_address_collection: 'required',
automatic_tax: { enabled: true },

View File

@@ -1,3 +1,4 @@
import { sendTelemetryEvents } from 'utils/telemetry/sendTelemetryEvent'
import prisma from '@/lib/prisma'
import { authenticatedProcedure } from '@/utils/server/trpc'
import { TRPCError } from '@trpc/server'
@@ -141,6 +142,19 @@ export const updateSubscription = authenticatedProcedure
},
})
await sendTelemetryEvents([
{
name: 'Subscription updated',
workspaceId,
userId: user.id,
data: {
plan,
additionalChatsIndex: additionalChats,
additionalStorageIndex: additionalStorage,
},
},
])
return { workspace: updatedWorkspace }
}
)