Skip to content

Fix: evaluate automation rules for API-created conversations#277

Open
josephsellers wants to merge 1 commit intoabhinavxd:mainfrom
josephsellers:fix/api-automation-rules
Open

Fix: evaluate automation rules for API-created conversations#277
josephsellers wants to merge 1 commit intoabhinavxd:mainfrom
josephsellers:fix/api-automation-rules

Conversation

@josephsellers
Copy link
Copy Markdown
Contributor

Summary

Conversations created via POST /api/v1/conversations (e.g. from external integrations, email workers, or webhook-based form submissions) are not evaluated against automation rules. Only conversations created through the incoming message flow trigger EvaluateNewConversationRules.

This adds the missing call in handleCreateConversation, matching the existing behaviour in the incoming message handler (internal/conversation/message.go).

The bug

In cmd/conversation.go, handleCreateConversation triggers the webhook event but does not call EvaluateNewConversationRules:

// Before (line 827-831)
conversation, err := app.conversation.GetConversation(conversationID, "", "")
if err == nil {
    app.webhook.TriggerEvent(wmodels.EventConversationCreated, conversation)
}

Compare to internal/conversation/message.go (line 776-782), which does both:

if isNewConversation {
    conversation, err := m.GetConversation(in.Message.ConversationID, "", "")
    if err == nil {
        m.webhookStore.TriggerEvent(wmodels.EventConversationCreated, conversation)
        m.automation.EvaluateNewConversationRules(conversation)
    }
}

The fix

One-line addition after the webhook trigger:

app.automation.EvaluateNewConversationRules(conversation)

How we found it

We have a new_conversation automation rule that auto-closes tickets from known spam domains using the contains operator on contact_email. It never fired. Tracing through the code, we found that all our inbound tickets arrive via the API (Cloudflare email worker and Gravity Forms webhooks), which bypasses the automation engine entirely.

Conversations created via the POST /api/v1/conversations endpoint
(e.g. from external integrations, email workers, or form webhooks)
were not evaluated against automation rules. Only conversations
created through the incoming message flow (IMAP/POP) triggered
automation rule evaluation.

This adds the missing EvaluateNewConversationRules call to
handleCreateConversation, matching the existing behaviour in
the incoming message handler (internal/conversation/message.go).

[Used Claude Code 🤖]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant