🚸 (bot) Update reply if we get new format from backend
This commit is contained in:
@@ -744,6 +744,9 @@
|
||||
"properties": {
|
||||
"url": {
|
||||
"type": "string"
|
||||
},
|
||||
"isAutoplayEnabled": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
@@ -1986,6 +1989,7 @@
|
||||
"Custom",
|
||||
"Empty",
|
||||
"User ID",
|
||||
"Now",
|
||||
"Today",
|
||||
"Yesterday",
|
||||
"Tomorrow",
|
||||
|
||||
@@ -312,6 +312,9 @@
|
||||
"properties": {
|
||||
"url": {
|
||||
"type": "string"
|
||||
},
|
||||
"isAutoplayEnabled": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
@@ -1554,6 +1557,7 @@
|
||||
"Custom",
|
||||
"Empty",
|
||||
"User ID",
|
||||
"Now",
|
||||
"Today",
|
||||
"Yesterday",
|
||||
"Tomorrow",
|
||||
@@ -4031,6 +4035,9 @@
|
||||
"properties": {
|
||||
"url": {
|
||||
"type": "string"
|
||||
},
|
||||
"isAutoplayEnabled": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
@@ -6021,6 +6028,10 @@
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"lastMessageNewFormat": {
|
||||
"type": "string",
|
||||
"description": "The sent message is validated and formatted on the backend. This is set only if the message differs from the formatted version."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
||||
@@ -79,8 +79,14 @@ export const sendMessage = publicProcedure
|
||||
clientSideActions,
|
||||
}
|
||||
} else {
|
||||
const { messages, input, clientSideActions, newSessionState, logs } =
|
||||
await continueBotFlow(session.state)(message)
|
||||
const {
|
||||
messages,
|
||||
input,
|
||||
clientSideActions,
|
||||
newSessionState,
|
||||
logs,
|
||||
lastMessageNewFormat,
|
||||
} = await continueBotFlow(session.state)(message)
|
||||
|
||||
const allLogs = clientLogs ? [...(logs ?? []), ...clientLogs] : logs
|
||||
|
||||
@@ -101,6 +107,7 @@ export const sendMessage = publicProcedure
|
||||
clientSideActions,
|
||||
dynamicTheme: parseDynamicThemeReply(newSessionState),
|
||||
logs,
|
||||
lastMessageNewFormat,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ export const continueBotFlow =
|
||||
message: 'Current block is not an input block',
|
||||
})
|
||||
|
||||
let formattedReply = null
|
||||
let formattedReply: string | undefined
|
||||
|
||||
if (isInputBlock(block)) {
|
||||
if (reply && !isReplyValid(reply, block))
|
||||
@@ -116,25 +116,46 @@ export const continueBotFlow =
|
||||
const nextEdgeId = getOutgoingEdgeId(newSessionState)(block, formattedReply)
|
||||
|
||||
if (groupHasMoreBlocks && !nextEdgeId) {
|
||||
return executeGroup(newSessionState)({
|
||||
const chatReply = await executeGroup(newSessionState)({
|
||||
...group,
|
||||
blocks: group.blocks.slice(blockIndex + 1),
|
||||
})
|
||||
return {
|
||||
...chatReply,
|
||||
lastMessageNewFormat:
|
||||
formattedReply !== reply ? formattedReply : undefined,
|
||||
}
|
||||
}
|
||||
|
||||
if (!nextEdgeId && state.linkedTypebots.queue.length === 0)
|
||||
return { messages: [], newSessionState }
|
||||
return {
|
||||
messages: [],
|
||||
newSessionState,
|
||||
lastMessageNewFormat:
|
||||
formattedReply !== reply ? formattedReply : undefined,
|
||||
}
|
||||
|
||||
const nextGroup = getNextGroup(newSessionState)(nextEdgeId)
|
||||
|
||||
if (!nextGroup) return { messages: [], newSessionState }
|
||||
if (!nextGroup)
|
||||
return {
|
||||
messages: [],
|
||||
newSessionState,
|
||||
lastMessageNewFormat:
|
||||
formattedReply !== reply ? formattedReply : undefined,
|
||||
}
|
||||
|
||||
return executeGroup(newSessionState)(nextGroup.group)
|
||||
const chatReply = executeGroup(newSessionState)(nextGroup.group)
|
||||
return {
|
||||
...chatReply,
|
||||
lastMessageNewFormat:
|
||||
formattedReply !== reply ? formattedReply : undefined,
|
||||
}
|
||||
}
|
||||
|
||||
const processAndSaveAnswer =
|
||||
(state: SessionState, block: InputBlock, itemId?: string) =>
|
||||
async (reply: string | null): Promise<SessionState> => {
|
||||
async (reply: string | undefined): Promise<SessionState> => {
|
||||
if (!reply) return state
|
||||
let newState = await saveAnswer(state, block, itemId)(reply)
|
||||
newState = saveVariableValueIfAny(newState, block)(reply)
|
||||
@@ -236,7 +257,7 @@ const getOutgoingEdgeId =
|
||||
({ typebot: { variables } }: Pick<SessionState, 'typebot'>) =>
|
||||
(
|
||||
block: InputBlock | SetVariableBlock | OpenAIBlock | WebhookBlock,
|
||||
reply: string | null
|
||||
reply: string | undefined
|
||||
) => {
|
||||
if (
|
||||
block.type === InputBlockType.CHOICE &&
|
||||
@@ -264,8 +285,8 @@ const getOutgoingEdgeId =
|
||||
export const formatReply = (
|
||||
inputValue: string | undefined,
|
||||
blockType: BlockType
|
||||
): string | null => {
|
||||
if (!inputValue) return null
|
||||
): string | undefined => {
|
||||
if (!inputValue) return
|
||||
switch (blockType) {
|
||||
case InputBlockType.PHONE:
|
||||
return formatPhoneNumber(inputValue)
|
||||
|
||||
Reference in New Issue
Block a user