⚡ (analytics) Improve analytics graph accuracy
This commit is contained in:
@@ -96,7 +96,18 @@ export const continueBotFlow =
|
||||
return parseRetryMessage(block)
|
||||
}
|
||||
|
||||
newSessionState = await processAndSaveAnswer(state, block)(formattedReply)
|
||||
const nextEdgeId = getOutgoingEdgeId(newSessionState)(
|
||||
block,
|
||||
formattedReply
|
||||
)
|
||||
const itemId = nextEdgeId
|
||||
? state.typebot.edges.find(byId(nextEdgeId))?.from.itemId
|
||||
: undefined
|
||||
newSessionState = await processAndSaveAnswer(
|
||||
state,
|
||||
block,
|
||||
itemId
|
||||
)(formattedReply)
|
||||
}
|
||||
|
||||
const groupHasMoreBlocks = blockIndex < group.blocks.length - 1
|
||||
@@ -121,10 +132,10 @@ export const continueBotFlow =
|
||||
}
|
||||
|
||||
const processAndSaveAnswer =
|
||||
(state: SessionState, block: InputBlock) =>
|
||||
(state: SessionState, block: InputBlock, itemId?: string) =>
|
||||
async (reply: string | null): Promise<SessionState> => {
|
||||
if (!reply) return state
|
||||
let newState = await saveAnswer(state, block)(reply)
|
||||
let newState = await saveAnswer(state, block, itemId)(reply)
|
||||
newState = await saveVariableValueIfAny(newState, block)(reply)
|
||||
return newState
|
||||
}
|
||||
@@ -179,13 +190,13 @@ const parseRetryMessage = (
|
||||
}
|
||||
|
||||
const saveAnswer =
|
||||
(state: SessionState, block: InputBlock) =>
|
||||
(state: SessionState, block: InputBlock, itemId?: string) =>
|
||||
async (reply: string): Promise<SessionState> => {
|
||||
const resultId = state.result?.id
|
||||
const answer = {
|
||||
resultId,
|
||||
blockId: block.id,
|
||||
groupId: block.groupId,
|
||||
itemId,
|
||||
content: reply,
|
||||
variableId: block.options.variableId,
|
||||
storageUsed: 0,
|
||||
@@ -207,8 +218,8 @@ const saveAnswer =
|
||||
where: {
|
||||
resultId_blockId_groupId: {
|
||||
resultId,
|
||||
groupId: block.groupId,
|
||||
blockId: block.id,
|
||||
groupId: block.groupId,
|
||||
},
|
||||
},
|
||||
create: answer as Prisma.AnswerUncheckedCreateInput,
|
||||
|
||||
Reference in New Issue
Block a user