feat: add recipient filter to automation rules - #488
Conversation
📝 WalkthroughWalkthroughIncoming email recipients now pass through conversation hooks, webhook payloads, and automation evaluation. The automation evaluator supports multi-recipient matching. Conversation filters expose a localized ChangesConversation recipient propagation
Automation recipient evaluation
Recipient filtering
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant EmailMessage
participant ProcessIncomingMessage
participant ProcessIncomingMessageHooks
participant AutomationEvaluator
EmailMessage->>ProcessIncomingMessage: provide message metadata
ProcessIncomingMessage->>ProcessIncomingMessageHooks: pass extracted to addresses
ProcessIncomingMessageHooks->>AutomationEvaluator: evaluate conversation rules
AutomationEvaluator-->>ProcessIncomingMessageHooks: return rule matches
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/conversation/models/models.go`:
- Line 188: Keep IncomingTo hidden on the shared conversation model, but update
the EventConversationCreated webhook payload construction to include it under
the to field. Ensure the webhook-specific serialized payload uses IncomingTo
without changing the model’s existing json:"-" behavior.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 12dab44a-161b-4083-9520-22b9887ca1a2
📒 Files selected for processing (9)
cmd/chat.gocmd/custom_attributes.gofrontend/apps/main/src/composables/useConversationFilters.jsi18n/en-US.jsoninternal/automation/evaluator.gointernal/automation/models/models.gointernal/automation/recipient_test.gointernal/conversation/message.gointernal/conversation/models/models.go
| InboxChannel string `db:"inbox_channel" json:"inbox_channel"` | ||
| Tags null.JSON `db:"tags" json:"tags"` | ||
| Meta json.RawMessage `db:"meta" json:"meta"` | ||
| IncomingTo []string `db:"-" json:"-"` |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect how conversation webhook payloads are constructed and serialized.
rg -n -C 8 --glob '*.go' 'func \(.*\) TriggerEvent|\.TriggerEvent\(' .
rg -n -C 8 --glob '*.go' 'EventConversationCreated|IncomingTo|json\.(Marshal|NewEncoder)' .Repository: abhinavxd/libredesk
Length of output: 50375
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the webhook delivery path and the exact payload for conversation-created events.
sed -n '1,340p' internal/webhook/webhook.go
rg -n -C 12 --glob '*.go' 'EventConversationCreated|DeliveryTask|deliveryQueue|json.Marshal|json.NewEncoder|Payload|data' internal/webhook cmd/conversation.go internal/conversation/message.goRepository: abhinavxd/libredesk
Length of output: 47506
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Demonstrate the Go JSON behavior for the exact Conversation field tag without
# importing or executing repository code.
if command -v go >/dev/null 2>&1; then
tmp="$(mktemp --suffix=.go)"
trap 'rm -f "$tmp"' EXIT
cat >"$tmp" <<'EOF'
package main
import (
"encoding/json"
"fmt"
)
type Conversation struct {
IncomingTo []string `json:"-"`
}
func main() {
b, err := json.Marshal(map[string]any{
"event": "conversation.created",
"payload": Conversation{IncomingTo: []string{"a@example.com"}},
})
if err != nil {
panic(err)
}
fmt.Println(string(b))
}
EOF
go run "$tmp"
else
echo "go compiler unavailable"
fiRepository: abhinavxd/libredesk
Length of output: 203
Include recipients in conversation-created webhooks.
IncomingTo is set before EventConversationCreated, but json:"-" removes it from the serialized payload. Add to in a webhook-specific payload while keeping the shared model field hidden.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/conversation/models/models.go` at line 188, Keep IncomingTo hidden
on the shared conversation model, but update the EventConversationCreated
webhook payload construction to include it under the to field. Ensure the
webhook-specific serialized payload uses IncomingTo without changing the model’s
existing json:"-" behavior.
Basically, there may be cases where you have a single inbox but use services like Cloudflare Email Routing, causing emails sent to multiple addresses to end up in the same inbox. Adding this configuration option allows you to filter those emails accordingly.
Summary by CodeRabbit
New Features
Bug Fixes