Phase 2 part 1: the CRM bridge to EspoCRM through Hermes
Supermarket queues CRM work in crm_actions and never writes to EspoCRM itself. A Hermes cron job (supermarket-crm, set up by `supermarket hermes`) runs every 15 minutes behind a monitor script that prints Supermarket's crm-state file, so unchanged state skips the AI run. Hermes calls the new MCP tools crm_pending_actions, crm_report_result and crm_ingest, creating each record through the Core's MCP hub unless a match exists, and copying Leads, Accounts and Contacts back every 6 hours for duplicate checks. Schema 5 adds crm_actions and crm_records. Prospects -> CRM queue shows the queue, a test Lead, sync, Retry and Cancel. When an action fails with a connection error, the page checks EspoCRM from this computer and says whether the CRM is down or the hub can't reach it, with a note to send to the Core's maintainer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -129,6 +129,43 @@ CREATE TABLE subreddits (
|
||||
data TEXT NOT NULL,
|
||||
fetched_at TEXT NOT NULL
|
||||
);
|
||||
`,
|
||||
// 5: the CRM bridge. Supermarket never writes to EspoCRM itself: actions
|
||||
// wait here until Hermes carries them out through the Core's MCP hub and
|
||||
// reports back. Hermes also copies CRM records here, for dedupe.
|
||||
`
|
||||
CREATE TABLE crm_actions (
|
||||
id INTEGER PRIMARY KEY,
|
||||
key TEXT NOT NULL UNIQUE, -- one action per key, however often it's queued
|
||||
kind TEXT NOT NULL, -- create (later: update, note)
|
||||
entity TEXT NOT NULL, -- Lead, Account, Contact…
|
||||
fields TEXT NOT NULL, -- JSON: the record's fields
|
||||
match TEXT NOT NULL DEFAULT '{}', -- JSON: fields that identify an existing record
|
||||
origin TEXT NOT NULL DEFAULT '', -- what queued it, e.g. test, prospect:12
|
||||
status TEXT NOT NULL DEFAULT 'pending', -- pending, claimed, done, failed, cancelled
|
||||
outcome TEXT NOT NULL DEFAULT '', -- created, existing
|
||||
espo_id TEXT NOT NULL DEFAULT '',
|
||||
error TEXT NOT NULL DEFAULT '',
|
||||
attempts INTEGER NOT NULL DEFAULT 0,
|
||||
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
|
||||
claimed_at TEXT,
|
||||
done_at TEXT
|
||||
);
|
||||
CREATE INDEX crm_actions_by_status ON crm_actions (status, id);
|
||||
|
||||
CREATE TABLE crm_records (
|
||||
entity TEXT NOT NULL,
|
||||
espo_id TEXT NOT NULL,
|
||||
name TEXT NOT NULL DEFAULT '',
|
||||
email TEXT NOT NULL DEFAULT '' COLLATE NOCASE,
|
||||
domain TEXT NOT NULL DEFAULT '' COLLATE NOCASE, -- of the website, or the email
|
||||
data TEXT NOT NULL, -- JSON: the fields Hermes sent
|
||||
modified_at TEXT NOT NULL DEFAULT '',
|
||||
synced_at TEXT NOT NULL,
|
||||
PRIMARY KEY (entity, espo_id)
|
||||
);
|
||||
CREATE INDEX crm_records_by_email ON crm_records (email);
|
||||
CREATE INDEX crm_records_by_domain ON crm_records (domain);
|
||||
`,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user