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:
@@ -0,0 +1,189 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"supermarket/internal/bridge"
|
||||
"supermarket/internal/core"
|
||||
"supermarket/internal/crm"
|
||||
)
|
||||
|
||||
// hermesCRMJob is the name of the Hermes cron job `supermarket hermes`
|
||||
// installs. It records the job's ID in hermes-crm-job in the data folder,
|
||||
// which `hermes cron run` needs.
|
||||
const hermesCRMJob = "supermarket-crm"
|
||||
|
||||
// crmJobID is the Hermes job's ID, or "" if it isn't set up.
|
||||
func (s *Server) crmJobID() string {
|
||||
raw, err := os.ReadFile(filepath.Join(s.DataDir, "hermes-crm-job"))
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return strings.TrimSpace(string(raw))
|
||||
}
|
||||
|
||||
func (s *Server) crmPage(w http.ResponseWriter, r *http.Request) {
|
||||
s.renderCRM(w, r, "")
|
||||
}
|
||||
|
||||
func (s *Server) renderCRM(w http.ResponseWriter, r *http.Request, errMsg string) {
|
||||
actions, err := crm.List(s.DB, 100)
|
||||
if err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
counts, err := crm.Counts(s.DB)
|
||||
if err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
records, err := crm.RecordCounts(s.DB)
|
||||
if err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
sync, err := crm.LoadSync(s.DB)
|
||||
if err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
last, err := bridge.Last(s.DB)
|
||||
if err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
var lastDone time.Time
|
||||
for _, a := range actions {
|
||||
if a.DoneAt.After(lastDone) {
|
||||
lastDone = a.DoneAt
|
||||
}
|
||||
}
|
||||
s.render(w, r, "crm", page{Title: "CRM queue", Nav: "prospects/crm", Error: errMsg, Data: map[string]any{
|
||||
"Actions": actions,
|
||||
"Counts": counts,
|
||||
"Records": records,
|
||||
"Entities": crm.SyncEntities,
|
||||
"Sync": sync,
|
||||
"SyncRequested": sync.Requested.After(sync.Last),
|
||||
"LastDone": lastDone,
|
||||
"Checkin": last,
|
||||
"Job": hermesCRMJob,
|
||||
"JobID": s.crmJobID(),
|
||||
"Waiting": counts[crm.StatusPending] + counts[crm.StatusClaimed],
|
||||
"Unreachable": s.Core != nil && unreachableError(actions) != "",
|
||||
}})
|
||||
}
|
||||
|
||||
// espoCRMURL is where Supermarket checks EspoCRM from; tests replace it.
|
||||
var espoCRMURL = (*core.Core).EspoCRMURL
|
||||
|
||||
// connErr spots a failed action whose error says the CRM couldn't be
|
||||
// reached, as opposed to EspoCRM refusing the record. Its second group is
|
||||
// the address that was tried, when the error names one.
|
||||
var connErr = regexp.MustCompile(`(?i)(ECONNREFUSED|ETIMEDOUT|EHOSTUNREACH|ENETUNREACH|ENOTFOUND|EAI_AGAIN|connection refused|no such host|timed out|unreachable)(?:\s+([\w-]+(?:\.[\w-]+)+(?::\d+)?))?`)
|
||||
|
||||
// unreachableError is the newest failed action's error, if it's a
|
||||
// connection error.
|
||||
func unreachableError(actions []crm.Action) string {
|
||||
for _, a := range actions { // newest first
|
||||
if a.Status == crm.StatusFailed && connErr.MatchString(a.Error) {
|
||||
return a.Error
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// crmReach is an htmx fragment shown when Hermes couldn't reach EspoCRM.
|
||||
// Hermes goes through the Core's MCP hub, which connects to EspoCRM with
|
||||
// its own settings; checking EspoCRM from here tells the user which side
|
||||
// to look at.
|
||||
func (s *Server) crmReach(w http.ResponseWriter, r *http.Request) {
|
||||
actions, err := crm.List(s.DB, 100)
|
||||
if err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
failure := unreachableError(actions)
|
||||
if s.Core == nil || failure == "" {
|
||||
s.fragment(w, "crm", "reach", nil)
|
||||
return
|
||||
}
|
||||
check := probe(r.Context(), core.Service{Name: "EspoCRM", URL: espoCRMURL(s.Core)})
|
||||
tried := ""
|
||||
for _, m := range connErr.FindAllStringSubmatch(failure, -1) {
|
||||
if m[2] != "" {
|
||||
tried = m[2]
|
||||
break
|
||||
}
|
||||
}
|
||||
s.fragment(w, "crm", "reach", map[string]any{
|
||||
"Check": check,
|
||||
"Tried": tried,
|
||||
"Error": failure,
|
||||
"HubHost": "mcphub." + s.Core.Domain,
|
||||
})
|
||||
}
|
||||
|
||||
// crmAction handles the page's buttons.
|
||||
func (s *Server) crmAction(w http.ResponseWriter, r *http.Request) {
|
||||
now := time.Now()
|
||||
switch r.PathValue("action") {
|
||||
case "test":
|
||||
// A new key each time, so the test can be repeated.
|
||||
_, err := crm.Enqueue(s.DB, crm.Action{
|
||||
Key: "test:" + strconv.FormatInt(now.UnixNano(), 36),
|
||||
Entity: "Lead",
|
||||
Fields: map[string]any{
|
||||
"firstName": "Supermarket",
|
||||
"lastName": "Test " + now.Format("2 Jan 15:04"),
|
||||
"accountName": "Supermarket bridge test",
|
||||
"source": "Other",
|
||||
"description": "Created by Supermarket to check that Hermes can write to EspoCRM. Delete it.",
|
||||
},
|
||||
Match: map[string]string{"lastName": "Test " + now.Format("2 Jan 15:04")},
|
||||
Origin: "test",
|
||||
})
|
||||
if err != nil {
|
||||
s.renderCRM(w, r, err.Error())
|
||||
return
|
||||
}
|
||||
redirect(w, r, "/crm", "crm-test")
|
||||
case "sync":
|
||||
if err := crm.RequestSync(s.DB, now); err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
redirect(w, r, "/crm", "crm-sync")
|
||||
default:
|
||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
switch r.PathValue("action") {
|
||||
case "retry":
|
||||
err = crm.Retry(s.DB, id)
|
||||
case "cancel":
|
||||
err = crm.Cancel(s.DB, id)
|
||||
default:
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
if errors.Is(err, crm.ErrNoAction) {
|
||||
s.renderCRM(w, r, "That action has changed meanwhile: Hermes may have just carried it out.")
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
redirect(w, r, "/crm", "saved")
|
||||
}
|
||||
}
|
||||
+37
-26
@@ -289,6 +289,42 @@ type serviceCheck struct {
|
||||
OK bool
|
||||
}
|
||||
|
||||
// probeClient checks whether a service answers. A redirect (e.g. to a
|
||||
// login page) means the service is there.
|
||||
var probeClient = &http.Client{
|
||||
Timeout: 6 * time.Second,
|
||||
CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse },
|
||||
}
|
||||
|
||||
// probe asks one service whether it answers, from this computer.
|
||||
func probe(ctx context.Context, svc core.Service) serviceCheck {
|
||||
c := serviceCheck{Name: svc.Name, URL: svc.URL}
|
||||
ctx, cancel := context.WithTimeout(ctx, 6*time.Second)
|
||||
defer cancel()
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, svc.URL, nil)
|
||||
if err != nil {
|
||||
c.Status = "isn't a valid address"
|
||||
return c
|
||||
}
|
||||
res, err := probeClient.Do(req)
|
||||
switch {
|
||||
case err != nil:
|
||||
c.Status = "doesn't answer"
|
||||
var dnsErr interface{ Timeout() bool }
|
||||
if errors.As(err, &dnsErr) && dnsErr.Timeout() {
|
||||
c.Status = "timed out"
|
||||
}
|
||||
case res.StatusCode >= 500:
|
||||
c.Status = "error " + res.Status
|
||||
res.Body.Close()
|
||||
default:
|
||||
c.OK = true
|
||||
c.Status = "answers (" + res.Status + ")"
|
||||
res.Body.Close()
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// coreChecks asks each Core service whether it answers. It's an htmx
|
||||
// fragment, loaded after the page so a slow service doesn't hold it up.
|
||||
func (s *Server) coreChecks(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -298,37 +334,12 @@ func (s *Server) coreChecks(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
services := s.Core.Services()
|
||||
checks := make([]serviceCheck, len(services))
|
||||
client := &http.Client{
|
||||
Timeout: 6 * time.Second,
|
||||
// A redirect (e.g. to a login page) means the service is there.
|
||||
CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse },
|
||||
}
|
||||
var wg sync.WaitGroup
|
||||
for i, svc := range services {
|
||||
wg.Add(1)
|
||||
go func(i int, svc core.Service) {
|
||||
defer wg.Done()
|
||||
c := serviceCheck{Name: svc.Name, URL: svc.URL}
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 6*time.Second)
|
||||
defer cancel()
|
||||
req, _ := http.NewRequestWithContext(ctx, http.MethodGet, svc.URL, nil)
|
||||
res, err := client.Do(req)
|
||||
switch {
|
||||
case err != nil:
|
||||
c.Status = "doesn't answer"
|
||||
var dnsErr interface{ Timeout() bool }
|
||||
if errors.As(err, &dnsErr) && dnsErr.Timeout() {
|
||||
c.Status = "timed out"
|
||||
}
|
||||
case res.StatusCode >= 500:
|
||||
c.Status = "error " + res.Status
|
||||
res.Body.Close()
|
||||
default:
|
||||
c.OK = true
|
||||
c.Status = "answers (" + res.Status + ")"
|
||||
res.Body.Close()
|
||||
}
|
||||
checks[i] = c
|
||||
checks[i] = probe(r.Context(), svc)
|
||||
}(i, svc)
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
+10
-1
@@ -127,6 +127,11 @@ func (s *Server) Handler() (http.Handler, error) {
|
||||
mux.HandleFunc("POST /drafts/{id}/{action}", s.draftAction)
|
||||
mux.HandleFunc("POST /reddit/rules/{name}", s.refreshRules)
|
||||
|
||||
mux.HandleFunc("GET /crm", s.crmPage)
|
||||
mux.HandleFunc("GET /crm/reach", s.crmReach)
|
||||
mux.HandleFunc("POST /crm/{action}", s.crmAction)
|
||||
mux.HandleFunc("POST /crm/{id}/{action}", s.crmAction)
|
||||
|
||||
mux.HandleFunc("GET /settings/core", s.corePage)
|
||||
mux.HandleFunc("GET /settings/core/checks", s.coreChecks)
|
||||
|
||||
@@ -267,6 +272,8 @@ func (p page) Section() string {
|
||||
return ""
|
||||
case strings.HasPrefix(p.Nav, "content"):
|
||||
return "Content"
|
||||
case strings.HasPrefix(p.Nav, "prospects"):
|
||||
return "Prospects"
|
||||
case strings.HasPrefix(p.Nav, "settings"):
|
||||
return "Settings"
|
||||
case p.Nav == "inventory":
|
||||
@@ -283,7 +290,7 @@ type module struct {
|
||||
|
||||
var modules = []module{
|
||||
{"content", "Content", "Phase 1", "Draft posts from partner and competitor news and your own products; review and publish to X, LinkedIn and Reddit.", "/content"},
|
||||
{"prospects", "Prospects", "Phase 2", "Find companies and people who fit your targets, and add the ones you approve to EspoCRM through Hermes.", ""},
|
||||
{"prospects", "Prospects", "Phase 2", "Find companies and people who fit your targets, and add the ones you approve to EspoCRM through Hermes.", "/crm"},
|
||||
{"seo", "SEO", "Phase 3", "Audit your websites and open fixes as pull requests on your Hugo repositories.", ""},
|
||||
{"metrics", "Metrics", "Phase 4", "Pipeline influence, CAC, CLV and NRR from Stripe, EspoCRM and Plausible.", ""},
|
||||
{"sites", "Sites", "Phase 5", "Build pages and sites from a component library and publish them through Gitea.", ""},
|
||||
@@ -331,6 +338,8 @@ var flashes = map[string]string{
|
||||
"x-connected": "X is connected.",
|
||||
"li-connected": "LinkedIn is connected.",
|
||||
"reddit-connected": "Reddit is connected.",
|
||||
"crm-test": "Test Lead queued. Hermes creates it on its next run; or run it now (below).",
|
||||
"crm-sync": "Sync requested: Hermes copies CRM records on its next run.",
|
||||
"rules-refreshed": "Rules refreshed.",
|
||||
"imported": "Imported.",
|
||||
"oauth-expired": "That sign-in took too long or was already used. Try again.",
|
||||
|
||||
@@ -9,7 +9,9 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -17,6 +19,7 @@ import (
|
||||
"supermarket/internal/bridge"
|
||||
"supermarket/internal/content"
|
||||
"supermarket/internal/core"
|
||||
"supermarket/internal/crm"
|
||||
"supermarket/internal/db"
|
||||
"supermarket/internal/inventory"
|
||||
"supermarket/internal/mcpserver"
|
||||
@@ -92,7 +95,7 @@ func TestEveryPageRenders(t *testing.T) {
|
||||
|
||||
for _, path := range []string{"/", "/?msg=saved", "/settings/profile", "/inventory", "/inventory?relationship=partner",
|
||||
"/inventory/new", "/inventory/1", "/inventory/import", "/inventory/export",
|
||||
"/settings/ai", "/settings/accounts", "/settings/core", "/static/app.css", "/favicon.ico", "/static/favicon.png", "/static/logo.png", "/static/apple-touch-icon.png", "/search", "/search?q=rival", "/search?q=nothing+here", "/static/htmx.min.js", "/healthz",
|
||||
"/settings/ai", "/settings/accounts", "/settings/core", "/static/app.css", "/favicon.ico", "/static/favicon.png", "/static/logo.png", "/static/apple-touch-icon.png", "/search", "/crm", "/search?q=rival", "/search?q=nothing+here", "/static/htmx.min.js", "/healthz",
|
||||
"/content", "/content/1", "/content/1?dismissed=1", "/posts", "/posts?msg=drafted",
|
||||
"/content/scheduled", "/content/published"} {
|
||||
rec := do(h, http.MethodGet, path, nil, nil)
|
||||
@@ -444,3 +447,94 @@ func TestLinkedInExpiryReminders(t *testing.T) {
|
||||
t.Errorf("expired publish: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCRMQueuePage(t *testing.T) {
|
||||
s, h := newTestServer(t, nil)
|
||||
if body := do(h, http.MethodGet, "/crm", nil, nil).Body.String(); !strings.Contains(body, "Nothing queued yet") ||
|
||||
!strings.Contains(body, "isn't set up yet") || !strings.Contains(body, `href="/crm" aria-current="page"`) {
|
||||
t.Error("empty CRM page")
|
||||
}
|
||||
_ = os.WriteFile(filepath.Join(s.DataDir, "hermes-crm-job"), []byte("9fd45c690814\n"), 0o600)
|
||||
if body := do(h, http.MethodGet, "/crm", nil, nil).Body.String(); !strings.Contains(body, "hermes cron run 9fd45c690814") {
|
||||
t.Error("the job's run command isn't shown")
|
||||
}
|
||||
if rec := postForm(h, "/crm/test", nil); rec.Code != http.StatusSeeOther {
|
||||
t.Fatalf("test lead: %d %s", rec.Code, rec.Body.String())
|
||||
}
|
||||
as, _ := crm.List(s.DB, 10)
|
||||
if len(as) != 1 || as[0].Entity != "Lead" || as[0].Origin != "test" || as[0].Status != crm.StatusPending {
|
||||
t.Fatalf("queued: %+v", as)
|
||||
}
|
||||
id := strconv.FormatInt(as[0].ID, 10)
|
||||
if body := do(h, http.MethodGet, "/crm", nil, nil).Body.String(); !strings.Contains(body, "1 waiting") || !strings.Contains(body, "Supermarket Test") {
|
||||
t.Error("the queued test lead isn't shown")
|
||||
}
|
||||
// Retry only applies to failed actions.
|
||||
if rec := postForm(h, "/crm/"+id+"/retry", nil); !strings.Contains(rec.Body.String(), "has changed meanwhile") {
|
||||
t.Error("retrying a pending action should be refused")
|
||||
}
|
||||
crm.Claim(s.DB, time.Now(), 10)
|
||||
crm.Report(s.DB, as[0].ID, crm.Result{Outcome: "failed", Error: "hub said no"}, time.Now())
|
||||
if body := do(h, http.MethodGet, "/crm", nil, nil).Body.String(); !strings.Contains(body, "hub said no") || !strings.Contains(body, "/crm/"+id+"/retry") {
|
||||
t.Error("failed action not shown with Retry")
|
||||
}
|
||||
postForm(h, "/crm/"+id+"/retry", nil)
|
||||
if a, _ := crm.Get(s.DB, as[0].ID); a.Status != crm.StatusPending {
|
||||
t.Errorf("retry: %+v", a)
|
||||
}
|
||||
postForm(h, "/crm/"+id+"/cancel", nil)
|
||||
if a, _ := crm.Get(s.DB, as[0].ID); a.Status != crm.StatusCancelled {
|
||||
t.Errorf("cancel: %+v", a)
|
||||
}
|
||||
if rec := postForm(h, "/crm/sync", nil); rec.Code != http.StatusSeeOther {
|
||||
t.Errorf("sync: %d", rec.Code)
|
||||
}
|
||||
if body := do(h, http.MethodGet, "/crm", nil, nil).Body.String(); !strings.Contains(body, "A sync is requested") {
|
||||
t.Error("sync request not shown")
|
||||
}
|
||||
}
|
||||
|
||||
// When Hermes reports that EspoCRM couldn't be reached, the CRM page checks
|
||||
// EspoCRM from here, to tell the user whether the CRM or the hub is at fault.
|
||||
func TestCRMReachHint(t *testing.T) {
|
||||
up := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
|
||||
defer up.Close()
|
||||
down := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
|
||||
downURL := down.URL
|
||||
down.Close()
|
||||
|
||||
s, h := newTestServer(t, &core.Core{Domain: "example.com", Email: "pat@example.com"})
|
||||
if body := do(h, http.MethodGet, "/crm", nil, nil).Body.String(); strings.Contains(body, "/crm/reach") {
|
||||
t.Error("hint shown with nothing failed")
|
||||
}
|
||||
fail := func(msg string) {
|
||||
crm.Enqueue(s.DB, crm.Action{Key: "k:" + msg, Entity: "Lead", Fields: map[string]any{"lastName": "X"}})
|
||||
as, _ := crm.Claim(s.DB, time.Now(), 10)
|
||||
for _, a := range as {
|
||||
crm.Report(s.DB, a.ID, crm.Result{Outcome: "failed", Error: msg}, time.Now())
|
||||
}
|
||||
}
|
||||
// A record EspoCRM refused isn't a connection problem.
|
||||
fail("Validation failed: lastName is required")
|
||||
if body := do(h, http.MethodGet, "/crm", nil, nil).Body.String(); strings.Contains(body, "/crm/reach") {
|
||||
t.Error("hint shown for a non-connection error")
|
||||
}
|
||||
fail("EspoCRM unreachable: connect ECONNREFUSED 192.168.0.39:443 on the search")
|
||||
if body := do(h, http.MethodGet, "/crm", nil, nil).Body.String(); !strings.Contains(body, `hx-get="/crm/reach"`) {
|
||||
t.Fatal("no hint for a connection error")
|
||||
}
|
||||
|
||||
defer func(f func(*core.Core) string) { espoCRMURL = f }(espoCRMURL)
|
||||
espoCRMURL = func(*core.Core) string { return up.URL }
|
||||
body := do(h, http.MethodGet, "/crm/reach", nil, nil).Body.String()
|
||||
for _, want := range []string{"answers from this computer", "<code>192.168.0.39:443</code>", "mcphub.example.com", up.URL} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Errorf("reachable: missing %q in %s", want, body)
|
||||
}
|
||||
}
|
||||
espoCRMURL = func(*core.Core) string { return downURL }
|
||||
body = do(h, http.MethodGet, "/crm/reach", nil, nil).Body.String()
|
||||
if !strings.Contains(body, "doesn't answer from this computer either") {
|
||||
t.Errorf("unreachable: %s", body)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
{{define "content"}}{{with .Data}}{{$job := .Job}}
|
||||
<div class="page-head">
|
||||
<h1>CRM queue</h1>
|
||||
<p class="lede">What Supermarket has asked Hermes to do in EspoCRM. Supermarket never writes to the CRM itself: Hermes takes these actions, creates each record unless a matching one is already there, and reports back. It also copies your Leads, Accounts and Contacts here, so Supermarket can spot people and companies you already have.</p>
|
||||
</div>
|
||||
|
||||
{{if .Unreachable}}<div hx-get="/crm/reach" hx-trigger="load" hx-swap="outerHTML"><p class="help">Hermes couldn't reach EspoCRM. Checking it from here…</p></div>{{end}}
|
||||
|
||||
<div class="grid">
|
||||
<section class="card">
|
||||
<h2>Queue</h2>
|
||||
<p>{{if .Waiting}}<strong>{{.Waiting}} waiting</strong> for Hermes{{else}}Nothing waiting{{end}}{{with index .Counts "failed"}} · <span class="warn-text">{{.}} failed</span>{{end}}{{with index .Counts "done"}} · {{.}} done{{end}}.</p>
|
||||
<p class="help">{{if .LastDone.IsZero}}Hermes hasn't reported a result yet.{{else}}Hermes last reported a result {{ago .LastDone}}.{{end}}</p>
|
||||
<form method="post" action="/crm/test" class="inline">
|
||||
<button type="submit" class="secondary">Send a test Lead</button>
|
||||
</form>
|
||||
<p class="help">Queues a Lead named “Supermarket Test …” to check the whole path. Delete it in EspoCRM afterwards.</p>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<h2>Copied from the CRM</h2>
|
||||
<p>{{range $i, $e := .Entities}}{{if $i}} · {{end}}{{index $.Data.Records $e}} {{$e}}{{end}}</p>
|
||||
<p class="help">{{if .Sync.Last.IsZero}}Not synced yet.{{else}}Last synced {{ago .Sync.Last}}; Hermes copies changes every 6 hours.{{end}}{{if .SyncRequested}} A sync is requested.{{end}}</p>
|
||||
<form method="post" action="/crm/sync" class="inline">
|
||||
<button type="submit" class="secondary" {{if .SyncRequested}}disabled{{end}}>Sync on the next run</button>
|
||||
</form>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<section class="card">
|
||||
<h2>How Hermes runs it</h2>
|
||||
{{if .JobID}}
|
||||
<p>Hermes has a scheduled job, <code>{{$job}}</code>, set up by <code>supermarket hermes</code>. Every 15 minutes it checks a small file Supermarket keeps up to date, and only wakes the AI when there's something to do. To run it now, in a terminal:</p>
|
||||
<div class="copy"><pre id="run-now">hermes cron run {{.JobID}}</pre><button type="button" class="secondary" data-copy="run-now">Copy</button></div>
|
||||
<p class="help">Or ask Hermes: “Run the {{$job}} job.” Its runs are listed by <code>hermes cron runs {{.JobID}}</code>.</p>
|
||||
{{else}}
|
||||
<p class="warn-text">Hermes' CRM job isn't set up yet, so nothing queued here reaches your CRM. In a terminal, run:</p>
|
||||
<div class="copy"><pre id="setup">supermarket hermes</pre><button type="button" class="secondary" data-copy="setup">Copy</button></div>
|
||||
{{end}}
|
||||
{{if not .Checkin}}<p class="help">Hermes hasn't checked in with Supermarket yet: see <a href="/settings/core">Settings → Core & Hermes</a>.</p>{{end}}
|
||||
</section>
|
||||
|
||||
{{if .Actions}}
|
||||
<h2>Actions</h2>
|
||||
<table class="list">
|
||||
<thead><tr><th>Queued</th><th>Action</th><th>Status</th><th></th></tr></thead>
|
||||
<tbody>
|
||||
{{range .Actions}}
|
||||
<tr>
|
||||
<td>{{ago .CreatedAt}}{{if eq .Origin "test"}}<br><span class="muted small">test</span>{{end}}</td>
|
||||
<td>{{if eq .Kind "create"}}Create{{else}}{{.Kind}}{{end}} {{.Entity}} <strong>{{.Name}}</strong>
|
||||
{{with .Match}}<br><span class="muted small">unless one exists with {{range $k, $v := .}}{{$k}} = {{$v}} {{end}}</span>{{end}}</td>
|
||||
<td>
|
||||
{{if eq .Status "done"}}<span class="badge published">{{if eq .Outcome "existing"}}already there{{else}}created{{end}}</span> <span class="muted small">{{.EspoID}}</span>
|
||||
{{else if eq .Status "failed"}}<span class="badge failed">failed</span><br><span class="small">{{.Error}}</span>
|
||||
{{else if eq .Status "claimed"}}<span class="badge scheduled">with Hermes</span> <span class="muted small">since {{ago .ClaimedAt}}</span>
|
||||
{{else if eq .Status "cancelled"}}<span class="badge">cancelled</span>
|
||||
{{else}}<span class="badge draft">waiting</span>{{end}}
|
||||
{{if gt .Attempts 1}}<br><span class="muted small">{{.Attempts}} tries</span>{{end}}
|
||||
</td>
|
||||
<td class="row-actions">
|
||||
{{if eq .Status "failed"}}<form method="post" action="/crm/{{.ID}}/retry"><button type="submit" class="small">Retry</button></form>{{end}}
|
||||
{{if or (eq .Status "pending") (eq .Status "failed") (eq .Status "claimed")}}<form method="post" action="/crm/{{.ID}}/cancel" data-confirm="Take this action back?{{if eq .Status "claimed"}} Hermes may already be carrying it out.{{end}}"><button type="submit" class="secondary small">Cancel</button></form>{{end}}
|
||||
</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{else}}
|
||||
<section class="card empty"><p>Nothing queued yet. Send a test Lead to check that Hermes can write to your CRM; prospects you approve will be queued here.</p></section>
|
||||
{{end}}
|
||||
{{end}}{{end}}
|
||||
|
||||
{{define "reach"}}{{with .}}
|
||||
<section class="card warn">
|
||||
<h2>Hermes couldn't reach EspoCRM</h2>
|
||||
{{if .Check.OK}}
|
||||
<p>EspoCRM <strong>answers from this computer</strong>, at <code>{{.Check.URL}}</code>. So it's running. The problem is between your Core's MCP hub and EspoCRM: Hermes never connects to EspoCRM itself, it asks the hub, and the hub connects with its own settings{{with .Tried}}, which sent it to <code>{{.}}</code>{{end}}.</p>
|
||||
<p>Changing anything in Supermarket or Hermes won't fix this. Send this to whoever looks after your Core:</p>
|
||||
<div class="copy"><pre id="hub-note">The MCP hub ({{.HubHost}}) can't reach EspoCRM. Its EspoCRM tools fail with:
|
||||
{{.Error}}
|
||||
|
||||
EspoCRM itself answers at {{.Check.URL}}.{{with .Tried}} The hub's EspoCRM address, or the DNS it uses, points at {{.}} instead.{{end}}</pre><button type="button" class="secondary" data-copy="hub-note">Copy</button></div>
|
||||
{{else}}
|
||||
<p class="warn-text">EspoCRM doesn't answer from this computer either, at <code>{{.Check.URL}}</code> ({{.Check.Status}}).</p>
|
||||
<p>It's probably down: check that it's running on your Core{{with .Tried}}; the hub tried <code>{{.}}</code>{{end}}. If EspoCRM lives at a different address, that's the hub's setting to change, not Supermarket's.</p>
|
||||
{{end}}
|
||||
<p class="help">When it's fixed, press Retry on the failed actions below.</p>
|
||||
</section>
|
||||
{{end}}{{end}}
|
||||
@@ -38,6 +38,11 @@
|
||||
<a href="/content/published" {{if eq $nav "content/published"}}aria-current="page"{{end}}>Published</a>
|
||||
</div>
|
||||
{{end}}
|
||||
{{if eq .ID "prospects"}}
|
||||
<div class="subnav">
|
||||
<a href="/crm" {{if eq $nav "prospects/crm"}}aria-current="page"{{end}}>CRM queue</a>
|
||||
</div>
|
||||
{{end}}
|
||||
{{else}}
|
||||
<span class="soon" title="{{.Body}}">{{template "icon" .ID}}<span>{{.Name}}</span><small>{{.Phase}}</small></span>
|
||||
{{end}}
|
||||
|
||||
Reference in New Issue
Block a user