2
0

🐛 (whatsapp) Fix force create session when flow is completed at first round

This commit is contained in:
Baptiste Arnaud
2023-10-03 16:06:37 +02:00
parent a7b784b446
commit bf051bebde
3 changed files with 6 additions and 5 deletions

View File

@ -66,7 +66,6 @@ export const sendMessage = publicProcedure
state: newSessionState,
})
: await saveStateToDatabase({
isFirstSave: true,
session: {
state: newSessionState,
},

View File

@ -7,19 +7,19 @@ import { createSession } from './queries/createSession'
import { deleteSession } from './queries/deleteSession'
type Props = {
isFirstSave?: boolean
session: Pick<ChatSession, 'state'> & { id?: string }
input: ChatReply['input']
logs: ChatReply['logs']
clientSideActions: ChatReply['clientSideActions']
forceCreateSession?: boolean
}
export const saveStateToDatabase = async ({
isFirstSave,
session: { state, id },
input,
logs,
clientSideActions,
forceCreateSession,
}: Props) => {
const containsSetVariableClientSideAction = clientSideActions?.some(
(action) => action.expectsDedicatedReply
@ -35,7 +35,9 @@ export const saveStateToDatabase = async ({
}
const session =
id && !isFirstSave ? { state, id } : await createSession({ id, state })
id && !forceCreateSession
? { state, id }
: await createSession({ id, state })
if (!resultId) return session

View File

@ -98,7 +98,7 @@ export const resumeWhatsAppFlow = async ({
})
await saveStateToDatabase({
isFirstSave: !session,
forceCreateSession: !session && isDefined(input),
clientSideActions: [],
input,
logs,