-
-
Notifications
You must be signed in to change notification settings - Fork 4
Add trusted forwarded contact intake #404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
michaelmwu
wants to merge
7
commits into
main
Choose a base branch
from
michaelmwu/forward-emails-into-espocrm-contact-ingestion
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ec622cd
Add contact email intake onboarding panel
michaelmwu b7d910f
Route forwarded contact emails to review queue
michaelmwu bb2970a
Autocreate contacts from trusted intro emails
michaelmwu a84f09e
Support explicit contact creation forwards
michaelmwu 9c5649e
Classify workflow mailbox actions with LLM
michaelmwu 6618509
Authorize workflow mail before LLM routing
michaelmwu c250a54
Extract contact candidates with LLM
michaelmwu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
apps/admin_dashboard/src/views/contact-email-candidates.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { cleanup, fireEvent, render, screen } from "@testing-library/react" | ||
| import { afterEach, describe, expect, it, vi } from "vitest" | ||
|
|
||
| import { ContactEmailCandidatesPanel } from "./contact-email-candidates" | ||
|
|
||
| afterEach(cleanup) | ||
|
|
||
| describe("ContactEmailCandidatesPanel", () => { | ||
| it("keeps the candidate editable and dispatches an explicit approval action", () => { | ||
| const onReview = vi.fn() | ||
| render( | ||
| <ContactEmailCandidatesPanel | ||
| canWrite | ||
| loading={false} | ||
| onReview={onReview} | ||
| candidates={[ | ||
| { | ||
| id: "candidate-1", | ||
| status: "pending", | ||
| delivered_to: "contacts@508.dev", | ||
| proposed_name: "Ada Lovelace", | ||
| proposed_email: "ada@example.com", | ||
| subject: "Introduction", | ||
| body_text: "See https://example.com/ada", | ||
| links: ["https://example.com/ada"], | ||
| extraction_method: "inline_forward", | ||
| }, | ||
| ]} | ||
| />, | ||
| ) | ||
|
|
||
| fireEvent.change(screen.getByLabelText("Contact name for candidate-1"), { | ||
| target: { value: "Ada Byron" }, | ||
| }) | ||
| fireEvent.click(screen.getByRole("button", { name: "Approve contact" })) | ||
|
|
||
| expect(onReview).toHaveBeenCalledWith(expect.objectContaining({ id: "candidate-1" }), { | ||
| decision: "approve", | ||
| name: "Ada Byron", | ||
| email: "ada@example.com", | ||
| }) | ||
| expect(screen.getByRole("link", { name: /https:\/\/example.com\/ada/ })).toHaveAttribute( | ||
| "href", | ||
| "https://example.com/ada", | ||
| ) | ||
| }) | ||
| }) |
172 changes: 172 additions & 0 deletions
172
apps/admin_dashboard/src/views/contact-email-candidates.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| import { ExternalLink, UserCheck, UserX } from "lucide-react" | ||
| import { useState } from "react" | ||
|
|
||
| import { Empty } from "@/components/empty" | ||
| import { Badge } from "@/components/ui/badge" | ||
| import { Button } from "@/components/ui/button" | ||
| import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" | ||
| import { Input } from "@/components/ui/input" | ||
| import { Label } from "@/components/ui/label" | ||
|
|
||
| export type ContactEmailCandidate = { | ||
| id: string | ||
| status: "pending" | "approved" | "dismissed" | ||
| delivered_to: string | ||
| forwarded_by_name?: string | null | ||
| forwarded_by_email?: string | null | ||
| proposed_name?: string | null | ||
| proposed_email?: string | null | ||
| subject?: string | null | ||
| body_text?: string | null | ||
| links?: string[] | ||
| extraction_method?: string | ||
| created_at?: string | ||
| } | ||
|
|
||
| export type ContactEmailCandidateDecision = { | ||
| decision: "approve" | "dismiss" | ||
| name?: string | ||
| email?: string | ||
| } | ||
|
|
||
| function CandidateCard({ | ||
| candidate, | ||
| canWrite, | ||
| loading, | ||
| onReview, | ||
| }: { | ||
| candidate: ContactEmailCandidate | ||
| canWrite: boolean | ||
| loading: boolean | ||
| onReview: (candidate: ContactEmailCandidate, decision: ContactEmailCandidateDecision) => void | ||
| }) { | ||
| const [name, setName] = useState(candidate.proposed_name || "") | ||
| const [email, setEmail] = useState(candidate.proposed_email || "") | ||
| const forwarder = [candidate.forwarded_by_name, candidate.forwarded_by_email] | ||
| .filter(Boolean) | ||
| .join(" · ") | ||
|
|
||
| return ( | ||
| <article className="grid gap-3 rounded-md border p-3"> | ||
| <div className="flex flex-wrap items-start justify-between gap-2"> | ||
| <div> | ||
| <h3 className="font-semibold">{candidate.subject || "Forwarded contact"}</h3> | ||
| <p className="text-sm text-muted-foreground"> | ||
| {forwarder ? `Forwarded by ${forwarder}` : "Forwarded email"} ·{" "} | ||
| {candidate.extraction_method?.replace(/_/g, " ") || "deterministic extraction"} | ||
| </p> | ||
| </div> | ||
| <Badge variant="queued">Needs review</Badge> | ||
| </div> | ||
|
|
||
| <div className="grid gap-3 md:grid-cols-2"> | ||
| <Label> | ||
| Contact name | ||
| <Input | ||
| aria-label={`Contact name for ${candidate.id}`} | ||
| value={name} | ||
| autoComplete="off" | ||
| onChange={(event) => setName(event.target.value)} | ||
| disabled={!canWrite || loading} | ||
| /> | ||
| </Label> | ||
| <Label> | ||
| Contact email | ||
| <Input | ||
| aria-label={`Contact email for ${candidate.id}`} | ||
| value={email} | ||
| type="email" | ||
| autoComplete="off" | ||
| onChange={(event) => setEmail(event.target.value)} | ||
| disabled={!canWrite || loading} | ||
| /> | ||
| </Label> | ||
| </div> | ||
|
|
||
| {candidate.links?.length ? ( | ||
| <div className="flex flex-wrap gap-2 text-sm"> | ||
| {candidate.links.map((link) => ( | ||
| <a | ||
| key={link} | ||
| className="inline-flex max-w-full items-center gap-1 text-primary underline" | ||
| href={link} | ||
| target="_blank" | ||
| rel="noreferrer" | ||
| > | ||
| <span className="truncate">{link}</span> | ||
| <ExternalLink className="size-3 shrink-0" aria-hidden="true" /> | ||
| </a> | ||
| ))} | ||
| </div> | ||
| ) : null} | ||
|
|
||
| {candidate.body_text ? ( | ||
| <details className="rounded-md bg-muted/40 p-3 text-sm"> | ||
| <summary className="cursor-pointer font-semibold">Source email</summary> | ||
| <pre className="mt-2 whitespace-pre-wrap break-words font-sans text-muted-foreground"> | ||
| {candidate.body_text} | ||
| </pre> | ||
| </details> | ||
| ) : null} | ||
|
|
||
| {canWrite ? ( | ||
| <div className="flex flex-wrap gap-2"> | ||
| <Button | ||
| type="button" | ||
| disabled={loading || !name.trim() || !email.trim()} | ||
| onClick={() => onReview(candidate, { decision: "approve", name, email })} | ||
| > | ||
| <UserCheck /> | ||
| Approve contact | ||
| </Button> | ||
| <Button | ||
| type="button" | ||
| variant="outline" | ||
| disabled={loading} | ||
| onClick={() => onReview(candidate, { decision: "dismiss" })} | ||
| > | ||
| <UserX /> | ||
| Dismiss | ||
| </Button> | ||
| </div> | ||
| ) : null} | ||
| </article> | ||
| ) | ||
| } | ||
|
|
||
| export function ContactEmailCandidatesPanel({ | ||
| candidates, | ||
| canWrite, | ||
| loading, | ||
| onReview, | ||
| }: { | ||
| candidates: ContactEmailCandidate[] | ||
| canWrite: boolean | ||
| loading: boolean | ||
| onReview: (candidate: ContactEmailCandidate, decision: ContactEmailCandidateDecision) => void | ||
| }) { | ||
| return ( | ||
| <Card> | ||
| <CardHeader> | ||
| <CardTitle>Contact candidates</CardTitle> | ||
| <span className="text-sm text-muted-foreground"> | ||
| {loading ? "Loading" : `${candidates.length} awaiting review`} | ||
| </span> | ||
| </CardHeader> | ||
| <CardContent className="grid gap-3"> | ||
| <Empty hidden={candidates.length !== 0}> | ||
| No forwarded contacts are waiting for review. | ||
| </Empty> | ||
| {candidates.map((candidate) => ( | ||
| <CandidateCard | ||
| key={candidate.id} | ||
| candidate={candidate} | ||
| canWrite={canWrite} | ||
| loading={loading} | ||
| onReview={onReview} | ||
| /> | ||
| ))} | ||
| </CardContent> | ||
| </Card> | ||
| ) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Do not block the onboarding queue when candidate loading fails.
If
/dashboard/api/onboarding/contact-candidatesreturns an error,Promise.allrejects beforesetOnboarding(peoplePayload)runs. A candidate-storage outage then hides the existing onboarding queue even when/dashboard/api/onboardingsucceeded. Handle the two results independently and show a candidate-panel error without discarding the onboarding result.🤖 Prompt for AI Agents