From ca7aad6a0a2ef5f348565a8eb48716bd958da80f Mon Sep 17 00:00:00 2001 From: Abhinav Raut Date: Fri, 7 Aug 2026 21:37:41 +0530 Subject: [PATCH] snapshot previous values before reopening conversation on incoming message --- internal/conversation/message.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/conversation/message.go b/internal/conversation/message.go index aae4e97c..94591878 100644 --- a/internal/conversation/message.go +++ b/internal/conversation/message.go @@ -1376,6 +1376,12 @@ func (m *Manager) ProcessIncomingMessageHooks(conversationUUID string, isNewConv return nil } + // Snapshot before reopening so previous_* filters see the pre-reopen state. + var previousValues map[string]string + if preReopen, err := m.GetConversation(0, conversationUUID, ""); err == nil { + previousValues = amodels.PreviousValues(preReopen) + } + // Reopen conversation if it's not Open. systemUser, err := m.userStore.GetSystemUser() if err != nil { @@ -1393,7 +1399,10 @@ func (m *Manager) ProcessIncomingMessageHooks(conversationUUID string, isNewConv m.lo.Error("error fetching conversation for incoming message hooks", "conversation_uuid", conversationUUID, "error", err) } else { // Trigger automations on incoming message event. - m.automation.EvaluateConversationUpdateRules(conversation, amodels.EventConversationMessageIncoming, amodels.PreviousValues(conversation), umodels.User{ID: conversation.ContactID}) + if previousValues == nil { + previousValues = amodels.PreviousValues(conversation) + } + m.automation.EvaluateConversationUpdateRules(conversation, amodels.EventConversationMessageIncoming, previousValues, umodels.User{ID: conversation.ContactID}) // If assigned to an AI assistant, let it respond to this inbound customer message. if m.aiAgent != nil && conversation.AssignedUserID.Valid {