📈 Add convenient isFirstOfKind field in total results digest
This commit is contained in:
@@ -73,6 +73,7 @@ const newResultsCollectedEventSchema = typebotEvent.merge(
|
|||||||
name: z.literal('New results collected'),
|
name: z.literal('New results collected'),
|
||||||
data: z.object({
|
data: z.object({
|
||||||
total: z.number(),
|
total: z.number(),
|
||||||
|
isFirstOfKind: z.literal(true).optional(),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -52,31 +52,39 @@ export const sendTotalResultsDigest = async () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const resultsWithWorkspaces = results
|
const resultsWithWorkspaces = results
|
||||||
.flatMap((result) => {
|
.flatMap((result, resultIndex) => {
|
||||||
const workspace = workspaces.find((workspace) =>
|
const workspace = workspaces.find((workspace) =>
|
||||||
workspace.typebots.some((typebot) => typebot.id === result.typebotId)
|
workspace.typebots.some((typebot) => typebot.id === result.typebotId)
|
||||||
)
|
)
|
||||||
if (!workspace) return
|
if (!workspace) return
|
||||||
return workspace.members
|
return workspace.members
|
||||||
.filter((member) => member.role !== WorkspaceRole.GUEST)
|
.filter((member) => member.role !== WorkspaceRole.GUEST)
|
||||||
.map((member) => ({
|
.map((member, memberIndex) => ({
|
||||||
userId: member.userId,
|
userId: member.userId,
|
||||||
workspaceId: workspace.id,
|
workspaceId: workspace.id,
|
||||||
typebotId: result.typebotId,
|
typebotId: result.typebotId,
|
||||||
totalResultsYesterday: result._count._all,
|
totalResultsYesterday: result._count._all,
|
||||||
|
isFirstOfKind:
|
||||||
|
resultIndex === 0 && memberIndex === 0
|
||||||
|
? (true as const)
|
||||||
|
: undefined,
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
.filter(isDefined)
|
.filter(isDefined)
|
||||||
|
|
||||||
const events = resultsWithWorkspaces.map((result) => ({
|
const events = resultsWithWorkspaces.map(
|
||||||
name: 'New results collected',
|
(result) =>
|
||||||
userId: result.userId,
|
({
|
||||||
workspaceId: result.workspaceId,
|
name: 'New results collected',
|
||||||
typebotId: result.typebotId,
|
userId: result.userId,
|
||||||
data: {
|
workspaceId: result.workspaceId,
|
||||||
total: result.totalResultsYesterday,
|
typebotId: result.typebotId,
|
||||||
},
|
data: {
|
||||||
})) satisfies TelemetryEvent[]
|
total: result.totalResultsYesterday,
|
||||||
|
isFirstOfKind: result.isFirstOfKind,
|
||||||
|
},
|
||||||
|
} satisfies TelemetryEvent)
|
||||||
|
)
|
||||||
|
|
||||||
await sendTelemetryEvents(events)
|
await sendTelemetryEvents(events)
|
||||||
console.log(`Sent ${events.length} events.`)
|
console.log(`Sent ${events.length} events.`)
|
||||||
|
|||||||
Reference in New Issue
Block a user