🚸 Only execute reply event with outgoind edge id

This commit is contained in:
Baptiste Arnaud 2025-05-28 14:52:33 +02:00
parent 0c883b9a11
commit 45f7e2ca5e
No known key found for this signature in database
3 changed files with 16 additions and 6 deletions

View File

@ -943,10 +943,12 @@ export const safeJsonParse = (value: string): unknown => {
}
};
const findReplyEvent = (state: SessionState): ReplyEvent | undefined =>
const findReplyEvent = (
state: SessionState,
): (ReplyEvent & { outgoingEdgeId: string }) | undefined =>
state.typebotsQueue[0].typebot.events?.find(
(e) => e.type === EventType.REPLY,
);
(e) => e.type === EventType.REPLY && e.outgoingEdgeId,
) as (ReplyEvent & { outgoingEdgeId: string }) | undefined;
const findInvalidReplyEvent = (
state: SessionState,

View File

@ -10,8 +10,15 @@ type Props = {
reply: InputMessage;
};
type ReplyEventWithDefinedOutgoingEdgeId = Omit<
ReplyEvent,
"outgoingEdgeId"
> & {
outgoingEdgeId: string;
};
export const executeReplyEvent = (
event: ReplyEvent,
event: ReplyEventWithDefinedOutgoingEdgeId,
{ state, reply }: Props,
) => {
if (!state.currentBlockId)

View File

@ -5,7 +5,7 @@ import { addDummyFirstBlockToGroupIfMissing } from "../addDummyFirstBlockToGroup
type Props = {
state: SessionState;
event: TDraggableEvent;
event: TDraggableEvent & { outgoingEdgeId: string };
};
export const updateCurrentBlockIdWithEvent = ({ state, event }: Props) => {
@ -14,10 +14,11 @@ export const updateCurrentBlockIdWithEvent = ({ state, event }: Props) => {
const edge = newSessionState.typebotsQueue[0].typebot.edges.find(
(edge) => edge.id === event.outgoingEdgeId,
);
if (!edge)
throw new TRPCError({
code: "BAD_REQUEST",
message: "Event is not connected",
message: `Could not find outgoing edge`,
});
newSessionState = addDummyFirstBlockToGroupIfMissing(