Skip to content

feat: add recipient filter to automation rules - #488

Open
Norbiros wants to merge 1 commit into
abhinavxd:mainfrom
Norbiros:feature/automation-filter-email-to
Open

feat: add recipient filter to automation rules#488
Norbiros wants to merge 1 commit into
abhinavxd:mainfrom
Norbiros:feature/automation-filter-email-to

Conversation

@Norbiros

@Norbiros Norbiros commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

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

    • Added a “To email address” filter for new and existing conversations.
    • Conversation automations can now evaluate incoming recipient addresses.
    • Incoming conversation webhook events now include email recipients.
  • Bug Fixes

    • Improved recipient matching for case sensitivity, whitespace, multiple addresses, containment, and empty values.
    • Reserved “to” as a custom attribute key to prevent conflicts.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Incoming email recipients now pass through conversation hooks, webhook payloads, and automation evaluation. The automation evaluator supports multi-recipient matching. Conversation filters expose a localized to email-address filter, and "to" is reserved as a custom attribute key.

Changes

Conversation recipient propagation

Layer / File(s) Summary
Propagate incoming recipients
internal/conversation/..., cmd/chat.go
Email metadata supplies to addresses to conversation hooks. Conversation webhook data stores them in the in-memory IncomingTo field. Live chat and contact creation pass nil.

Automation recipient evaluation

Layer / File(s) Summary
Evaluate recipient rule values
internal/automation/...
The evaluator adds the to field and centralizes string, numeric, set, case, whitespace, and multi-recipient comparisons. Tests cover recipient matching and empty values.

Recipient filtering

Layer / File(s) Summary
Expose recipient filters
frontend/apps/main/src/composables/useConversationFilters.js, i18n/en-US.json, cmd/custom_attributes.go
New and existing conversation filters support recipient email text matching. The English label is added, and "to" is blocked as a custom attribute key.

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
Loading

Possibly related PRs

  • abhinavxd/libredesk#469: Both changes modify recipient handling, automation evaluation, filters, and conversation message processing.

Suggested reviewers: abhinavxd, jleroy

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding a recipient filter to automation rules.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between b138b22 and 0f09898.

📒 Files selected for processing (9)
  • cmd/chat.go
  • cmd/custom_attributes.go
  • frontend/apps/main/src/composables/useConversationFilters.js
  • i18n/en-US.json
  • internal/automation/evaluator.go
  • internal/automation/models/models.go
  • internal/automation/recipient_test.go
  • internal/conversation/message.go
  • internal/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:"-"`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ 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.go

Repository: 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"
fi

Repository: 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.

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