Phase 2 part 3: buying signals, the funnel and the scorecard

Schema 7 adds signals (hypothesis, how to spot it, angle, status, utm
slug), funnel_events (stage, channel, subject, campaign, source, deduped
by external ID) and outside_campaigns. Prospects -> Signals is the
scorecard: each signal's funnel from found to paid, people once per
stage, with revenue and outside spend, by period and channel. Each
signal's page shows its funnel by channel, its campaigns and its latest
steps. Prospects carry a signal (filter, change, "found" recorded) and
outcomes can be recorded by hand.

Settings -> Lead sources holds origami.chat and explee.com API keys. Every
6 hours (or Import now) Supermarket reads their campaigns, numbers and
spend, contacted people, replies and hot leads, read-only: interested
people and repliers become prospects, unsubscribes are suppressed, and
each campaign is assigned to a signal. The explee.com client follows its
OpenAPI schema; origami.chat's responses are undocumented, so its client
reads fields loosely and its Test shows the real response.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-21 18:06:58 -07:00
co-authored by Claude Opus 5.5
parent ee579ec9f4
commit b025a97e4a
27 changed files with 3031 additions and 53 deletions
+74 -12
View File
@@ -9,6 +9,7 @@ import (
"supermarket/internal/crm"
"supermarket/internal/prospects"
"supermarket/internal/signals"
)
// newProspects is how many companies and people wait for review.
@@ -31,11 +32,21 @@ func reviewTab(v string) string {
}
func (s *Server) prospectsPage(w http.ResponseWriter, r *http.Request) {
s.renderProspects(w, r, reviewTab(r.URL.Query().Get("status")), "")
sig, _ := strconv.ParseInt(r.URL.Query().Get("signal"), 10, 64)
s.renderProspects(w, r, reviewTab(r.URL.Query().Get("status")), sig, "")
}
func (s *Server) renderProspects(w http.ResponseWriter, r *http.Request, tab, errMsg string) {
companies, loose, err := prospects.Review(s.DB, tab, 200)
// reviewURL is the review screen for a tab and a signal filter.
func reviewURL(tab string, signalID int64) string {
u := "/prospects?status=" + tab
if signalID != 0 {
u += "&signal=" + strconv.FormatInt(signalID, 10)
}
return u
}
func (s *Server) renderProspects(w http.ResponseWriter, r *http.Request, tab string, signalID int64, errMsg string) {
companies, loose, err := prospects.Review(s.DB, tab, signalID, 200)
if err != nil {
s.serverError(w, err)
return
@@ -72,14 +83,53 @@ func (s *Server) renderProspects(w http.ResponseWriter, r *http.Request, tab, er
s.serverError(w, err)
return
}
list, err := signals.List(s.DB)
if err != nil {
s.serverError(w, err)
return
}
names := map[int64]string{}
for _, sg := range list {
names[sg.ID] = sg.Name
}
// Each prospect's funnel so far.
var subjects []string
for _, c := range companies {
subjects = append(subjects, prospects.Subject("company", c.ID))
for _, p := range c.Contacts {
subjects = append(subjects, prospects.Subject("contact", p.ID))
}
}
for _, p := range loose {
subjects = append(subjects, prospects.Subject("contact", p.ID))
}
evs, err := signals.SubjectEvents(s.DB, subjects...)
if err != nil {
s.serverError(w, err)
return
}
events := map[string][]signals.Event{}
for _, e := range evs {
if e.Stage != signals.StageFound {
events[e.Subject] = append(events[e.Subject], e)
}
}
s.render(w, r, "prospects", page{Title: "Review prospects", Nav: "prospects/review", Error: errMsg, Data: map[string]any{
"Tab": tab,
"Statuses": prospects.Statuses,
"Counts": counts,
"Companies": companies,
"Loose": loose,
"Matches": matches,
"Synced": sync.Last,
"Tab": tab,
"Statuses": prospects.Statuses,
"Counts": counts,
"Companies": companies,
"Loose": loose,
"Matches": matches,
"Synced": sync.Last,
"Signals": list,
"SignalNames": names,
"Signal": signalID,
"Events": events,
"Stages": signals.Stages[1:], // found is recorded on its own
"Channels": signals.Channels,
"Back": reviewURL(tab, signalID),
"Today": time.Now().Format("2006-01-02"),
}})
}
@@ -96,9 +146,15 @@ func (s *Server) prospectAction(w http.ResponseWriter, r *http.Request) {
return
}
tab := reviewTab(r.PostFormValue("tab"))
filter, _ := strconv.ParseInt(r.PostFormValue("filter"), 10, 64)
now := time.Now()
var msg string
switch kind + "/" + action {
case "company/signal", "contact/signal":
sig, _ := strconv.ParseInt(r.PostFormValue("signal"), 10, 64)
err, msg = prospects.SetSignal(s.DB, kind, id, sig), "saved"
case "company/outcome", "contact/outcome":
err, msg = s.prospectOutcome(w, r, kind, id, tab), "outcome"
case "company/accept":
err, msg = ignore(prospects.AcceptCompany(s.DB, id, now)), "accepted"
case "company/accept-all":
@@ -140,10 +196,10 @@ func (s *Server) prospectAction(w http.ResponseWriter, r *http.Request) {
return
}
if err != nil {
s.renderProspects(w, r, tab, "Couldn't do that: "+err.Error())
s.renderProspects(w, r, tab, filter, "Couldn't do that: "+err.Error())
return
}
redirect(w, r, "/prospects?status="+tab, msg)
redirect(w, r, reviewURL(tab, filter), msg)
}
// ignore drops a result and keeps the error.
@@ -152,6 +208,7 @@ func ignore[T any](_ T, err error) error { return err }
// --- Adding by hand ---
type prospectFormData struct {
Signals []signals.Signal
Company prospects.Company
Contact prospects.Contact
CompanyID int64 // adding a person at a company already in review
@@ -161,6 +218,8 @@ type prospectFormData struct {
func (s *Server) prospectForm(w http.ResponseWriter, r *http.Request) {
d := prospectFormData{}
d.Signals, _ = signals.List(s.DB)
d.Company.SignalID, _ = strconv.ParseInt(r.URL.Query().Get("signal"), 10, 64)
if id, err := strconv.ParseInt(r.URL.Query().Get("company"), 10, 64); err == nil {
c, err := prospects.GetCompany(s.DB, id)
if err != nil {
@@ -192,6 +251,9 @@ func (s *Server) prospectAdd(w http.ResponseWriter, r *http.Request) {
},
}
d.CompanyID, _ = strconv.ParseInt(f("company_id"), 10, 64)
d.Signals, _ = signals.List(s.DB)
d.Company.SignalID, _ = strconv.ParseInt(f("signal"), 10, 64)
d.Contact.SignalID = d.Company.SignalID
if d.CompanyID != 0 {
c, err := prospects.GetCompany(s.DB, d.CompanyID)
if err != nil {
+12
View File
@@ -9,6 +9,7 @@ import (
"supermarket/internal/inventory"
"supermarket/internal/profile"
"supermarket/internal/prospects"
"supermarket/internal/signals"
)
// prospectBadge is a prospect's status as search shows it.
@@ -47,6 +48,8 @@ var settingsPages = []struct {
"ai provider model anthropic claude openai ollama lm studio api key hermes effort"},
{hit{"Core & Hermes", "Settings · the Federated Core, its services and the Hermes bridge", "/settings/core", ""},
"core hermes federated mcp hub bridge espocrm nextcloud plausible gitea"},
{hit{"Lead sources", "Settings · origami.chat and explee.com API keys", "/settings/sources", ""},
"lead sources origami explee api key import campaigns prospecting outreach"},
}
func (s *Server) searchPage(w http.ResponseWriter, r *http.Request) {
@@ -175,6 +178,15 @@ func (s *Server) search(q string) ([]hitGroup, error) {
prospectHits = append(prospectHits, hit{Title: p.Name(), Detail: detail, Link: "/prospects?status=" + p.Status, Badge: prospectBadge(p.Status)})
}
sigs, err := signals.Search(s.DB, words, searchLimit)
if err != nil {
return nil, err
}
for _, sg := range sigs {
prospectHits = append([]hit{{Title: sg.Name, Detail: "Buying signal · " + sg.Hypothesis,
Link: "/signals/" + strconv.FormatInt(sg.ID, 10), Badge: sg.Status}}, prospectHits...)
}
var settings []hit
if p, err := profile.Load(s.DB); err == nil && p.IsSet() {
for _, pr := range p.Products {
+39 -1
View File
@@ -10,6 +10,7 @@ import (
"net"
"net/http"
"net/url"
"strconv"
"strings"
"sync"
"time"
@@ -21,6 +22,7 @@ import (
"supermarket/internal/legacy"
"supermarket/internal/oauth"
"supermarket/internal/secrets"
"supermarket/internal/signals"
)
//go:embed templates/*.html
@@ -133,6 +135,18 @@ func (s *Server) Handler() (http.Handler, error) {
mux.HandleFunc("GET /prospects/suppressed", s.suppressedPage)
mux.HandleFunc("POST /prospects/suppressed", s.suppressedAction)
mux.HandleFunc("POST /prospects/{kind}/{id}/{action}", s.prospectAction)
mux.HandleFunc("GET /signals", s.signalsPage)
mux.HandleFunc("GET /signals/new", s.signalPage)
mux.HandleFunc("POST /signals/new", s.signalSave)
mux.HandleFunc("POST /signals/campaigns", s.signalCampaign)
mux.HandleFunc("POST /lead-sources/{source}/import", s.importSource)
mux.HandleFunc("GET /signals/{id}", s.signalPage)
mux.HandleFunc("POST /signals/{id}", s.signalSave)
mux.HandleFunc("POST /signals/{id}/delete", s.signalDelete)
mux.HandleFunc("POST /funnel/{id}/delete", s.funnelDelete)
mux.HandleFunc("GET /settings/sources", s.sourcesPage)
mux.HandleFunc("POST /settings/sources", s.sourcesSave)
mux.HandleFunc("POST /settings/sources/test/{source}", s.sourcesTest)
mux.HandleFunc("GET /crm", s.crmPage)
mux.HandleFunc("GET /crm/reach", s.crmReach)
mux.HandleFunc("POST /crm/{action}", s.crmAction)
@@ -232,6 +246,10 @@ func (s *Server) loadTemplates() error {
return m, nil
},
"xreserve": twitter.URLReserve,
// money shows cents as dollars: $1,234 or $12.50.
"money": money,
"stage": signals.StageLabel,
"channel": signals.ChannelLabel,
"truncate": func(n int, s string) string {
r := []rune(s)
if len(r) <= n {
@@ -298,7 +316,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", "Prospects", "Phase 2", "Test buying signals through the whole funnel, from finding prospects to payment; add the people you approve to EspoCRM through Hermes.", "/signals"},
{"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.", ""},
@@ -355,6 +373,7 @@ var flashes = map[string]string{
"suppressed": "Added to the suppression list.",
"unsuppressed": "Taken off the suppression list.",
"prospect-added": "Added. Review it below.",
"outcome": "Outcome recorded.",
"rules-refreshed": "Rules refreshed.",
"imported": "Imported.",
"oauth-expired": "That sign-in took too long or was already used. Try again.",
@@ -384,6 +403,25 @@ func (s *Server) serverError(w http.ResponseWriter, err error) {
http.Error(w, "Something went wrong: "+err.Error(), http.StatusInternalServerError)
}
func money(cents int64) string {
neg := cents < 0
if neg {
cents = -cents
}
whole := strconv.FormatInt(cents/100, 10)
for i := len(whole) - 3; i > 0; i -= 3 {
whole = whole[:i] + "," + whole[i:]
}
out := "$" + whole
if c := cents % 100; c != 0 {
out += fmt.Sprintf(".%02d", c)
}
if neg {
out = "-" + out
}
return out
}
func ago(t time.Time) string {
if t.IsZero() {
return "never"
+89 -1
View File
@@ -27,6 +27,7 @@ import (
"supermarket/internal/profile"
"supermarket/internal/prospects"
"supermarket/internal/secrets"
"supermarket/internal/signals"
)
const testToken = "0123456789abcdef0123456789abcdef"
@@ -99,7 +100,8 @@ func TestEveryPageRenders(t *testing.T) {
"/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",
"/prospects", "/prospects?status=accepted", "/prospects?status=rejected", "/prospects/new", "/prospects/suppressed"} {
"/prospects", "/prospects?status=accepted", "/prospects?status=rejected", "/prospects/new", "/prospects/suppressed",
"/signals", "/signals?period=30d&channel=email", "/signals/new", "/settings/sources"} {
rec := do(h, http.MethodGet, path, nil, nil)
if rec.Code != http.StatusOK {
t.Errorf("core=%v GET %s: %d %s", c != nil, path, rec.Code, rec.Body.String())
@@ -599,3 +601,89 @@ func TestProspectsReview(t *testing.T) {
t.Errorf("missing prospect: %d", rec.Code)
}
}
// Signals: define one, tag a prospect, record outcomes, and see them on
// the scorecard.
func TestSignalsFunnel(t *testing.T) {
s, h := newTestServer(t, nil)
rec := postForm(h, "/signals/new", url.Values{"name": {"Leaving Microsoft 365"}, "status": {"testing"},
"hypothesis": {"Price rise makes them switch"}, "spot": {"m365 alternative"}})
if rec.Code != http.StatusSeeOther || !strings.HasPrefix(rec.Header().Get("Location"), "/signals/1") {
t.Fatalf("create: %d %s", rec.Code, rec.Body.String())
}
if rec := postForm(h, "/signals/new", url.Values{"name": {""}}); !strings.Contains(rec.Body.String(), "needs a name") {
t.Error("a nameless signal was accepted")
}
postForm(h, "/prospects/new", url.Values{"company_name": {"Acme"}, "website": {"acme.example"}, "first_name": {"Pat"},
"last_name": {"Lee"}, "email": {"pat@acme.example"}, "signal": {"1"}})
body := do(h, http.MethodGet, "/prospects?signal=1", nil, nil).Body.String()
if !strings.Contains(body, "Pat Lee") || !strings.Contains(body, `<option value="1" selected>Leaving Microsoft 365</option>`) {
t.Error("the prospect isn't shown with its signal")
}
if body := do(h, http.MethodGet, "/prospects?signal=99", nil, nil).Body.String(); strings.Contains(body, "Pat Lee") {
t.Error("the signal filter doesn't filter")
}
for _, f := range []url.Values{
{"stage": {"contacted"}, "channel": {"email"}, "date": {"2026-11-20"}},
{"stage": {"replied"}, "channel": {"email"}, "note": {"Interested, call next week"}},
{"stage": {"paid"}, "channel": {"email"}, "amount": {"$1,070.50"}},
} {
f.Set("tab", "new")
f.Set("filter", "1")
if rec := postForm(h, "/prospects/contact/1/outcome", f); rec.Code != http.StatusSeeOther || rec.Header().Get("Location") != "/prospects?status=new&signal=1&msg=outcome" {
t.Fatalf("outcome: %d %s %s", rec.Code, rec.Header().Get("Location"), rec.Body.String())
}
}
if rec := postForm(h, "/prospects/contact/1/outcome", url.Values{"stage": {"paid"}, "channel": {"email"}, "amount": {"lots"}}); !strings.Contains(rec.Body.String(), "an amount") {
t.Errorf("a bad amount was accepted: %d", rec.Code)
}
body = do(h, http.MethodGet, "/signals", nil, nil).Body.String()
for _, want := range []string{"Leaving Microsoft 365", "$1,070.50", `<span class="rate">100%</span>`} {
if !strings.Contains(body, want) {
t.Errorf("scorecard lacks %q", want)
}
}
body = do(h, http.MethodGet, "/signals/1", nil, nil).Body.String()
if !strings.Contains(body, "Interested, call next week") || !strings.Contains(body, "Its prospects (1 new)") {
t.Error("the signal's page")
}
if body := do(h, http.MethodGet, "/prospects", nil, nil).Body.String(); !strings.Contains(body, "Interested, call next week") {
t.Error("the prospect's steps aren't shown")
}
// Moving the company to no signal moves its person and their steps.
postForm(h, "/prospects/company/1/signal", url.Values{"signal": {"0"}})
if rows, _ := signals.Scorecard(s.DB, signals.Filter{}); rows[0].Total() != 0 || rows[1].Signal != nil || rows[1].Counts["paid"] != 1 {
t.Errorf("after untagging: %+v", rows)
}
// An outside campaign, assigned to the signal.
signals.SaveCampaign(s.DB, signals.Campaign{Source: "explee", ID: "7", Name: "M365 movers", SpendCents: 990, SyncedAt: time.Now()})
if body := do(h, http.MethodGet, "/signals", nil, nil).Body.String(); !strings.Contains(body, "M365 movers") {
t.Error("campaign not listed")
}
postForm(h, "/signals/campaigns", url.Values{"source": {"explee"}, "id": {"7"}, "signal": {"1"}})
if cs, _ := signals.Campaigns(s.DB); cs[0].SignalID != 1 {
t.Errorf("assign: %+v", cs)
}
if rec := postForm(h, "/lead-sources/explee/import", nil); !strings.Contains(rec.Body.String(), "API key first") {
t.Errorf("import without a key: %s", rec.Body.String())
}
if body := do(h, http.MethodGet, "/search?q=microsoft", nil, nil).Body.String(); !strings.Contains(body, "/signals/1") {
t.Error("search doesn't find the signal")
}
// Lead source keys.
postForm(h, "/settings/sources", url.Values{secrets.ExpleeAPIKey: {"ex-key"}, "origami_project": {"proj"}})
if s.Secrets.Get(secrets.ExpleeAPIKey) != "ex-key" || s.origamiProject() != "proj" {
t.Error("lead source settings not saved")
}
if rec := postForm(h, "/settings/sources/test/origami", nil); !strings.Contains(rec.Body.String(), "Save the key first") {
t.Errorf("test without a key: %s", rec.Body.String())
}
postForm(h, "/signals/1/delete", nil)
if list, _ := signals.List(s.DB); len(list) != 0 {
t.Error("delete")
}
}
+448
View File
@@ -0,0 +1,448 @@
package web
import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"strconv"
"strings"
"time"
"supermarket/internal/api/explee"
"supermarket/internal/api/origami"
"supermarket/internal/leadsource"
"supermarket/internal/prospects"
"supermarket/internal/secrets"
"supermarket/internal/signals"
)
// --- The scorecard ---
// periods the scorecard can show.
var periods = []struct{ ID, Label string }{
{"", "All time"}, {"90d", "90 days"}, {"30d", "30 days"}, {"7d", "7 days"},
}
func since(period string, now time.Time) time.Time {
switch period {
case "90d":
return now.AddDate(0, 0, -90)
case "30d":
return now.AddDate(0, 0, -30)
case "7d":
return now.AddDate(0, 0, -7)
}
return time.Time{}
}
func (s *Server) signalsPage(w http.ResponseWriter, r *http.Request) {
s.renderSignals(w, r, "")
}
func (s *Server) renderSignals(w http.ResponseWriter, r *http.Request, errMsg string) {
q := r.URL.Query()
period, channel := q.Get("period"), q.Get("channel")
rows, err := signals.Scorecard(s.DB, signals.Filter{Since: since(period, time.Now()), Channel: channel})
if err != nil {
s.serverError(w, err)
return
}
list, err := signals.List(s.DB)
if err != nil {
s.serverError(w, err)
return
}
camps, err := signals.Campaigns(s.DB)
if err != nil {
s.serverError(w, err)
return
}
s.render(w, r, "signals", page{Title: "Signals", Nav: "prospects/signals", Error: errMsg, Data: map[string]any{
"Rows": rows,
"Signals": list,
"Stages": signals.Stages,
"Channels": signals.Channels,
"Periods": periods,
"Period": period,
"Channel": channel,
"Campaigns": camps,
"Sources": s.leadSources(),
}})
}
// --- One signal ---
type signalData struct {
S *signals.Signal
Statuses []string
Stages []signals.Stage
ByChannel []channelRow // its funnel per channel
Total *signals.Row
Campaigns []signals.Campaign
Events []signals.Event
Prospects int // new prospects tagged with it
}
type channelRow struct {
Channel string
Row signals.Row
}
func (s *Server) signalPage(w http.ResponseWriter, r *http.Request) {
sig := &signals.Signal{Status: signals.StatusIdea}
if idStr := r.PathValue("id"); idStr != "" {
id, err := strconv.ParseInt(idStr, 10, 64)
if err != nil {
http.NotFound(w, r)
return
}
if sig, err = signals.Get(s.DB, id); errors.Is(err, signals.ErrNotFound) {
http.NotFound(w, r)
return
} else if err != nil {
s.serverError(w, err)
return
}
}
s.renderSignal(w, r, sig, "")
}
func (s *Server) renderSignal(w http.ResponseWriter, r *http.Request, sig *signals.Signal, errMsg string) {
d := signalData{S: sig, Statuses: signals.Statuses, Stages: signals.Stages}
title := "New signal"
if sig.ID != 0 {
title = sig.Name
all, err := signals.Scorecard(s.DB, signals.Filter{})
if err != nil {
s.serverError(w, err)
return
}
for i := range all {
if all[i].Signal != nil && all[i].Signal.ID == sig.ID {
d.Total = &all[i]
}
}
for _, ch := range signals.Channels {
rows, err := signals.Scorecard(s.DB, signals.Filter{Channel: ch.ID})
if err != nil {
s.serverError(w, err)
return
}
for _, row := range rows {
if row.Signal != nil && row.Signal.ID == sig.ID && (row.Total() > 0 || row.SpendCents > 0) {
d.ByChannel = append(d.ByChannel, channelRow{ch.ID, row})
}
}
}
camps, err := signals.Campaigns(s.DB)
if err != nil {
s.serverError(w, err)
return
}
for _, c := range camps {
if c.SignalID == sig.ID {
d.Campaigns = append(d.Campaigns, c)
}
}
if d.Events, err = signals.RecentEvents(s.DB, sig.ID, 30); err != nil {
s.serverError(w, err)
return
}
cs, ps, err := prospects.Review(s.DB, prospects.StatusNew, sig.ID, 1000)
if err != nil {
s.serverError(w, err)
return
}
d.Prospects = len(cs) + len(ps)
}
s.render(w, r, "signal", page{Title: title, Nav: "prospects/signals", Error: errMsg, Data: d})
}
func (s *Server) signalSave(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
sig := &signals.Signal{}
if idStr := r.PathValue("id"); idStr != "" {
id, err := strconv.ParseInt(idStr, 10, 64)
if err != nil {
http.NotFound(w, r)
return
}
if sig, err = signals.Get(s.DB, id); err != nil {
http.NotFound(w, r)
return
}
}
f := r.PostFormValue
sig.Name, sig.Slug, sig.Hypothesis, sig.Spot, sig.Angle, sig.Status =
f("name"), f("slug"), f("hypothesis"), f("spot"), f("angle"), f("status")
if err := signals.Save(s.DB, sig); err != nil {
s.renderSignal(w, r, sig, err.Error())
return
}
redirect(w, r, "/signals/"+strconv.FormatInt(sig.ID, 10), "saved")
}
func (s *Server) signalDelete(w http.ResponseWriter, r *http.Request) {
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
if err != nil {
http.NotFound(w, r)
return
}
if err := signals.Delete(s.DB, id); err != nil {
s.serverError(w, err)
return
}
redirect(w, r, "/signals", "deleted")
}
// signalCampaign assigns an outside campaign to a signal.
func (s *Server) signalCampaign(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
sig, _ := strconv.ParseInt(r.PostFormValue("signal"), 10, 64)
if err := signals.AssignCampaign(s.DB, r.PostFormValue("source"), r.PostFormValue("id"), sig); err != nil {
s.renderSignals(w, r, err.Error())
return
}
redirect(w, r, "/signals#campaigns", "saved")
}
// --- Outcomes recorded by hand ---
// prospectOutcome records a funnel step for a prospect: until Supermarket
// sends and reads its own outreach, this is how replies, bookings and
// payments get onto the scorecard.
func (s *Server) prospectOutcome(w http.ResponseWriter, r *http.Request, kind string, id int64, tab string) error {
var subject, email string
var sig int64
if kind == "company" {
c, err := prospects.GetCompany(s.DB, id)
if err != nil {
return err
}
subject, sig = prospects.Subject(kind, id), c.SignalID
} else {
c, err := prospects.GetContact(s.DB, id)
if err != nil {
return err
}
subject, sig, email = prospects.Subject(kind, id), c.SignalID, c.Email
}
var value int64
if amount := strings.TrimSpace(strings.TrimPrefix(r.PostFormValue("amount"), "$")); amount != "" {
f, err := strconv.ParseFloat(strings.ReplaceAll(amount, ",", ""), 64)
if err != nil || f < 0 {
return fmt.Errorf("%q isn't an amount", amount)
}
value = int64(f*100 + 0.5)
}
at := time.Now()
if day := r.PostFormValue("date"); day != "" {
t, err := time.ParseInLocation("2006-01-02", day, time.Local)
if err != nil {
return fmt.Errorf("%q isn't a date", day)
}
at = t.Add(12 * time.Hour)
}
_, err := signals.Record(s.DB, signals.Event{
SignalID: sig, Stage: r.PostFormValue("stage"), Channel: r.PostFormValue("channel"), Subject: subject,
Email: email, Source: signals.SourceManual, ValueCents: value, Note: r.PostFormValue("note"), At: at,
})
return err
}
func (s *Server) funnelDelete(w http.ResponseWriter, r *http.Request) {
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
if err != nil {
http.NotFound(w, r)
return
}
if err := signals.DeleteEvent(s.DB, id); err != nil {
s.renderProspects(w, r, reviewTab(r.PostFormValue("tab")), 0, err.Error())
return
}
back := r.PostFormValue("back")
if !strings.HasPrefix(back, "/") || strings.HasPrefix(back, "//") {
back = "/prospects"
}
redirect(w, r, back, "deleted")
}
// --- Lead sources: origami.chat and explee.com ---
const origamiProjectKey = "leadsource:origami-project"
// leadSource is one tool, as the pages show it.
type leadSource struct {
ID, Name, Site string
Key secretField
Set bool
Last *leadsource.Result
}
var leadSourceKeys = []secretField{
{"origami", secrets.OrigamiAPIKey, "API key",
"In origami.chat, Settings → Developers → Create API key, with Full API access. It starts og_live_ and is shown once.", "https://origami.chat"},
{"explee", secrets.ExpleeAPIKey, "API key",
"In explee.com, Organization Settings → API keys.", "https://explee.com/app-auto-gtm/api-keys"},
}
func (s *Server) leadSources() []leadSource {
out := []leadSource{
{ID: signals.SourceOrigami, Name: "origami.chat", Site: "https://origami.chat", Key: leadSourceKeys[0]},
{ID: signals.SourceExplee, Name: "explee.com", Site: "https://explee.com", Key: leadSourceKeys[1]},
}
for i := range out {
out[i].Set = s.Secrets.Has(out[i].Key.Name)
out[i].Last, _ = leadsource.Last(s.DB, out[i].ID)
}
return out
}
func (s *Server) origamiProject() string {
var p string
_, _ = s.DB.GetJSON(origamiProjectKey, &p)
return p
}
func (s *Server) sourcesPage(w http.ResponseWriter, r *http.Request) {
s.render(w, r, "sources", page{Title: "Lead sources", Nav: "settings/sources", Data: map[string]any{
"Sources": s.leadSources(),
"Project": s.origamiProject(),
}})
}
func (s *Server) sourcesSave(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
if err := s.saveSecrets(r, leadSourceKeys); err != nil {
s.serverError(w, err)
return
}
if err := s.DB.PutJSON(origamiProjectKey, strings.TrimSpace(r.PostFormValue("origami_project"))); err != nil {
s.serverError(w, err)
return
}
redirect(w, r, "/settings/sources", "saved")
}
// sourcesTest checks a key, and for origami.chat shows what the API sends,
// since its responses aren't documented.
func (s *Server) sourcesTest(w http.ResponseWriter, r *http.Request) {
ctx, cancel := context.WithTimeout(r.Context(), 60*time.Second)
defer cancel()
data := map[string]any{}
switch r.PathValue("source") {
case signals.SourceExplee:
key := s.Secrets.Get(secrets.ExpleeAPIKey)
if key == "" {
data["Error"] = "Save the key first."
break
}
who, err := explee.New(key).Me(ctx)
if err != nil {
data["Error"] = err.Error()
break
}
data["OK"] = "The key works (" + who + ")."
case signals.SourceOrigami:
key := s.Secrets.Get(secrets.OrigamiAPIKey)
if key == "" {
data["Error"] = "Save the key first."
break
}
c := origami.New(key, s.origamiProject())
who, err := c.Account(ctx)
if err != nil {
data["Error"] = err.Error()
break
}
data["OK"] = "The key works (" + who + ")."
if sample, err := c.Sample(ctx); err == nil {
raw, _ := json.MarshalIndent(sample, "", " ")
data["Sample"] = string(raw)
}
default:
http.NotFound(w, r)
return
}
s.fragment(w, "sources", "test-result", data)
}
// importSource runs one tool's import now.
func (s *Server) importSource(w http.ResponseWriter, r *http.Request) {
source := r.PathValue("source")
if source != signals.SourceExplee && source != signals.SourceOrigami {
http.NotFound(w, r)
return
}
ctx, cancel := context.WithTimeout(r.Context(), 5*time.Minute)
defer cancel()
res, err := s.runImport(ctx, source)
if err != nil && res == nil {
s.renderSignals(w, r, err.Error())
return
}
if err != nil {
s.renderSignals(w, r, "Importing from "+source+": "+err.Error())
return
}
redirect(w, r, "/signals#campaigns", "imported")
}
// runImport imports from one tool, if its key is saved. It returns nil, nil
// without one.
func (s *Server) runImport(ctx context.Context, source string) (*leadsource.Result, error) {
now := time.Now()
switch source {
case signals.SourceExplee:
if key := s.Secrets.Get(secrets.ExpleeAPIKey); key != "" {
return leadsource.ImportExplee(ctx, s.DB, explee.New(key), now)
}
case signals.SourceOrigami:
if key := s.Secrets.Get(secrets.OrigamiAPIKey); key != "" {
return leadsource.ImportOrigami(ctx, s.DB, origami.New(key, s.origamiProject()), now)
}
}
return nil, errors.New("save the tool's API key first, under Settings → Lead sources")
}
// RunImports imports from each tool with a saved key, every
// leadsource.Every.
func (s *Server) RunImports(ctx context.Context) {
tick := time.NewTicker(10 * time.Minute)
defer tick.Stop()
for {
for _, src := range []string{signals.SourceOrigami, signals.SourceExplee} {
last, _ := leadsource.Last(s.DB, src)
if last != nil && time.Since(last.At) < leadsource.Every {
continue
}
ictx, cancel := context.WithTimeout(ctx, 10*time.Minute)
res, err := s.runImport(ictx, src)
cancel()
switch {
case res == nil:
case err != nil:
s.Log.Warn("lead source import failed", "source", src, "err", err)
default:
s.Log.Info("lead source imported", "source", src, "campaigns", res.Campaigns, "events", res.Events,
"prospects", res.Prospects, "suppressed", res.Suppressed)
}
}
select {
case <-ctx.Done():
return
case <-tick.C:
}
}
}
+38
View File
@@ -380,3 +380,41 @@ form.inline { display: inline-block; margin: 0 0 0.75rem; }
.prospect .why { margin: 0.6rem 0 0.3rem; }
.prospect .people { margin: 0.9rem 0 0.5rem; }
.prospect .warnings { margin: 0.5rem 0; }
/* Signals and the funnel */
.filters { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-end; margin: 0 0 1rem; }
.filters label { margin: 0; }
.filters select { width: auto; min-width: 12rem; }
.table-wrap { overflow-x: auto; margin-bottom: 0.75rem; }
table.list th.num, table.list td.num { text-align: right; white-space: nowrap; }
.scorecard td.num { font-variant-numeric: tabular-nums; }
table.scorecard th, table.scorecard td { padding: 0.5rem 0.5rem; }
table.scorecard th { font-size: 0.66rem; letter-spacing: 0.02em; }
table.scorecard td:first-child { min-width: 11rem; }
table.scorecard td:first-child .badge { margin-left: 0.25rem; }
.rate { display: block; font-size: 0.72rem; color: hsl(var(--muted-foreground)); }
.stat { display: inline-block; margin-right: 0.6rem; white-space: nowrap; }
.badge.idea { background: hsl(var(--muted)); color: hsl(var(--muted-foreground)); }
.badge.testing { background: hsl(var(--accent)); color: hsl(var(--accent-foreground)); }
.badge.proven { background: hsl(var(--ok-bg)); color: hsl(var(--ok)); }
.badge.retired { background: hsl(var(--muted)); color: hsl(var(--muted-foreground)); text-decoration: line-through; }
.funnel { display: grid; grid-template-columns: repeat(auto-fit, minmax(88px, 1fr)); gap: 0.4rem; margin: 0.5rem 0 1rem; }
.funnel .step { border: 1px solid hsl(var(--border)); border-radius: var(--radius); padding: 0.55rem 0.7rem; display: flex; flex-direction: column; gap: 0.1rem; }
.funnel .step .label { font-size: 0.75rem; color: hsl(var(--muted-foreground)); text-transform: uppercase; letter-spacing: 0.04em; }
.funnel .step strong { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.signal-tag { margin: 0.35rem 0 0; }
.signal-tag label { display: inline-flex; align-items: center; gap: 0.45rem; margin: 0; font-weight: normal; }
.signal-tag select { width: auto; padding-top: 0.15rem; padding-bottom: 0.15rem; font-size: 0.82rem; }
.steps-done { list-style: none; padding: 0; margin: 0.45rem 0 0; font-size: 0.82rem; color: hsl(var(--muted-foreground)); }
.steps-done li { padding: 0.12rem 0; }
.steps-done form.inline { display: inline; margin: 0; }
.outcome { margin: 0.4rem 0 0; }
.outcome summary { cursor: pointer; color: hsl(var(--primary)); }
.row.wrap { flex-wrap: wrap; align-items: flex-end; margin-top: 0.5rem; }
.row.wrap label { margin: 0; }
.row.wrap select, .row.wrap input { width: auto; }
.row.wrap .grow { flex: 1; min-width: 10rem; }
.row.wrap .grow input { width: 100%; }
button.link { background: none; border: 0; box-shadow: none; padding: 0; color: hsl(var(--primary)); text-decoration: underline; cursor: pointer; font-weight: normal; }
.danger-zone { margin-top: 2rem; }
pre.sample { max-height: 24rem; overflow: auto; font-size: 0.78rem; }
+9
View File
@@ -65,6 +65,15 @@
}
});
// A select with data-autosubmit sends its form when it changes (inline
// handlers aren't allowed by the page's Content-Security-Policy).
document.addEventListener("change", function (e) {
var el = e.target;
if (el.hasAttribute && el.hasAttribute("data-autosubmit") && el.form) {
if (el.form.requestSubmit) el.form.requestSubmit(); else el.form.submit();
}
});
// Ask before submitting a form with data-confirm. A form with data-busy
// shows that text on the button that submitted it, and can't be sent twice,
// while a slow request (fetching, writing, publishing) runs. With
+3 -1
View File
@@ -40,6 +40,7 @@
{{end}}
{{if eq .ID "prospects"}}
<div class="subnav">
<a href="/signals" {{if eq $nav "prospects/signals"}}aria-current="page"{{end}}>Signals</a>
<a href="/prospects" {{if eq $nav "prospects/review"}}aria-current="page"{{end}}>Review{{with $.NewProspects}} <span class="count-badge" title="{{.}} waiting for review">{{.}}</span>{{end}}</a>
<a href="/prospects/suppressed" {{if eq $nav "prospects/suppressed"}}aria-current="page"{{end}}>Suppression list</a>
<a href="/crm" {{if eq $nav "prospects/crm"}}aria-current="page"{{end}}>CRM queue</a>
@@ -81,7 +82,7 @@
{{define "settings-start"}}
<div class="page-head">
<h1>Settings</h1>
<p class="lede">Your company, the accounts Supermarket posts with, the AI it writes with, and your Federated Core.</p>
<p class="lede">Your company, the accounts Supermarket posts with, the prospecting tools it reads, the AI it writes with, and your Federated Core.</p>
</div>
<div class="settings">
<nav class="settings-nav" aria-label="Settings sections">
@@ -90,6 +91,7 @@
<div class="nav-label">Connections</div>
<a href="/settings/accounts" {{if eq .Nav "settings/accounts"}}aria-current="page"{{end}}>{{template "icon" "accounts"}}Social accounts</a>
<a href="/settings/core" {{if eq .Nav "settings/core"}}aria-current="page"{{end}}>{{template "icon" "core"}}Core &amp; Hermes</a>
<a href="/settings/sources" {{if eq .Nav "settings/sources"}}aria-current="page"{{end}}>{{template "icon" "prospects"}}Lead sources</a>
<div class="nav-label">AI</div>
<a href="/settings/ai" {{if eq .Nav "settings/ai"}}aria-current="page"{{end}}>{{template "icon" "ai"}}AI</a>
</nav>
+9
View File
@@ -25,6 +25,15 @@
<label>Phone <input name="phone" value="{{.Contact.Phone}}"></label>
<label>LinkedIn profile <input name="linkedin" value="{{.Contact.LinkedIn}}" placeholder="https://www.linkedin.com/in/…"></label>
</div>
{{if .Signals}}{{$cur := .Company.SignalID}}
<label>Buying signal
<select name="signal">
<option value="0">none</option>
{{range .Signals}}<option value="{{.ID}}" {{if eq .ID $cur}}selected{{end}}>{{.Name}}</option>{{end}}
</select>
<span class="help">The signal you found them through{{if $.Data.For}}. Leave it at none to use the company's{{end}}.</span>
</label>
{{end}}
<label>Where you found them <input name="source_detail" value="{{.Contact.SourceDetail}}" placeholder="A link, an event, a referral…">
<span class="help">Kept with the prospect and written into the CRM record, so you can always say where a contact came from.</span></label>
<div class="actions">
+70 -18
View File
@@ -1,14 +1,27 @@
{{define "content"}}{{with .Data}}{{$tab := .Tab}}{{$matches := .Matches}}
{{define "content"}}{{with .Data}}{{$tab := .Tab}}{{$matches := .Matches}}{{$d := .}}
<div class="heading">
<h1>Review prospects</h1>
<div class="buttons">
<a class="button" href="/prospects/new">Add a prospect</a>
<a class="button" href="/prospects/new{{if .Signal}}?signal={{.Signal}}{{end}}">Add a prospect</a>
</div>
</div>
<p class="lede">Companies and people who may fit your targets. Nothing goes to your CRM until you accept it: accepting a company adds an Account, accepting a person adds a Lead, through <a href="/crm">the CRM queue</a>. Each one keeps where and when it was found.</p>
{{if .Signals}}
<form method="get" action="/prospects" class="filters">
<input type="hidden" name="status" value="{{$tab}}">
<label class="small">Signal
<select name="signal" data-autosubmit>
<option value="0">All signals</option>
{{range .Signals}}<option value="{{.ID}}" {{if eq .ID $d.Signal}}selected{{end}}>{{.Name}}</option>{{end}}
</select>
</label>
<noscript><button type="submit" class="secondary small">Show</button></noscript>
</form>
{{end}}
<nav class="tabs">
{{range .Statuses}}<a href="/prospects?status={{.}}" {{if eq $tab .}}aria-current="page"{{end}}>{{if eq . "new"}}New{{else if eq . "accepted"}}Accepted{{else}}Set aside{{end}}{{with index $.Data.Counts .}} <span class="muted">{{.}}</span>{{end}}</a>{{end}}
{{range .Statuses}}<a href="/prospects?status={{.}}{{if $d.Signal}}&amp;signal={{$d.Signal}}{{end}}" {{if eq $tab .}}aria-current="page"{{end}}>{{if eq . "new"}}New{{else if eq . "accepted"}}Accepted{{else}}Set aside{{end}}{{with index $.Data.Counts .}} <span class="muted">{{.}}</span>{{end}}</a>{{end}}
</nav>
{{if and (eq $tab "new") (or .Companies .Loose)}}
@@ -29,25 +42,26 @@
{{if eq .Status $tab}}
<div class="row-actions">
{{if eq $tab "new"}}
{{if .Contacts}}<form method="post" action="/prospects/company/{{.ID}}/accept-all"><input type="hidden" name="tab" value="{{$tab}}"><button type="submit" class="small">Accept with {{len .Contacts}} {{if eq (len .Contacts) 1}}person{{else}}people{{end}}</button></form>{{end}}
<form method="post" action="/prospects/company/{{.ID}}/accept"><input type="hidden" name="tab" value="{{$tab}}"><button type="submit" class="small {{if .Contacts}}secondary{{end}}">Accept {{if .Contacts}}company only{{else}}company{{end}}</button></form>
<form method="post" action="/prospects/company/{{.ID}}/reject"><input type="hidden" name="tab" value="{{$tab}}"><button type="submit" class="secondary small">Set aside</button></form>
{{if .Domain}}<form method="post" action="/prospects/company/{{.ID}}/suppress" data-confirm="Never add anyone at {{.Domain}}? This puts the domain on your suppression list."><input type="hidden" name="tab" value="{{$tab}}"><button type="submit" class="secondary small">Suppress {{.Domain}}</button></form>{{end}}
{{if .Contacts}}<form method="post" action="/prospects/company/{{.ID}}/accept-all"><input type="hidden" name="tab" value="{{$tab}}"><input type="hidden" name="filter" value="{{$d.Signal}}"><button type="submit" class="small">Accept with {{len .Contacts}} {{if eq (len .Contacts) 1}}person{{else}}people{{end}}</button></form>{{end}}
<form method="post" action="/prospects/company/{{.ID}}/accept"><input type="hidden" name="tab" value="{{$tab}}"><input type="hidden" name="filter" value="{{$d.Signal}}"><button type="submit" class="small {{if .Contacts}}secondary{{end}}">Accept {{if .Contacts}}company only{{else}}company{{end}}</button></form>
<form method="post" action="/prospects/company/{{.ID}}/reject"><input type="hidden" name="tab" value="{{$tab}}"><input type="hidden" name="filter" value="{{$d.Signal}}"><button type="submit" class="secondary small">Set aside</button></form>
{{if .Domain}}<form method="post" action="/prospects/company/{{.ID}}/suppress" data-confirm="Never add anyone at {{.Domain}}? This puts the domain on your suppression list."><input type="hidden" name="tab" value="{{$tab}}"><input type="hidden" name="filter" value="{{$d.Signal}}"><button type="submit" class="secondary small">Suppress {{.Domain}}</button></form>{{end}}
{{else if eq $tab "accepted"}}
{{template "crm-state" dict "CRM" .CRM "Kind" "company" "ID" .ID "Tab" $tab}}
{{template "crm-state" dict "CRM" .CRM "Kind" "company" "ID" .ID "Tab" $tab "Filter" $d.Signal}}
{{else}}
<form method="post" action="/prospects/company/{{.ID}}/reconsider"><input type="hidden" name="tab" value="{{$tab}}"><button type="submit" class="secondary small">Reconsider</button></form>
<form method="post" action="/prospects/company/{{.ID}}/reconsider"><input type="hidden" name="tab" value="{{$tab}}"><input type="hidden" name="filter" value="{{$d.Signal}}"><button type="submit" class="secondary small">Reconsider</button></form>
{{end}}
</div>
{{end}}
</div>
{{with .Why}}<p class="why">{{.}}</p>{{end}}
<p class="meta">{{template "provenance" .}}</p>
{{template "signal-tag" dict "Kind" "company" "ID" .ID "SignalID" .SignalID "D" $d}}
{{with index $matches (printf "company:%d" .ID)}}{{template "crm-matches" .}}{{end}}
{{if .Contacts}}
<ul class="items people">
{{range .Contacts}}{{template "contact" dict "P" . "Tab" $tab "Matches" $matches}}{{end}}
{{range .Contacts}}{{template "contact" dict "P" . "Tab" $tab "Matches" $matches "D" $d}}{{end}}
</ul>
{{end}}
{{if eq $tab "new"}}<p class="small"><a href="/prospects/new?company={{.ID}}">Add a person at {{.Name}}</a></p>{{end}}
@@ -58,7 +72,7 @@
<section class="card prospect">
<h2>People without a company</h2>
<ul class="items people">
{{range .Loose}}{{template "contact" dict "P" . "Tab" $tab "Matches" $matches}}{{end}}
{{range .Loose}}{{template "contact" dict "P" . "Tab" $tab "Matches" $matches "D" $d}}{{end}}
</ul>
</section>
{{end}}
@@ -72,7 +86,7 @@
{{end}}
{{end}}{{end}}
{{define "contact"}}{{$p := .P}}{{$tab := .Tab}}
{{define "contact"}}{{$p := .P}}{{$tab := .Tab}}{{$d := .D}}
<li class="item">
<div class="prospect-head">
<div>
@@ -83,18 +97,20 @@
{{with $p.LinkedIn}} · <a href="{{.}}" target="_blank" rel="noopener noreferrer">LinkedIn</a>{{end}}
</div>
<div class="meta">{{template "provenance" $p}}</div>
{{if not $p.CompanyID}}{{template "signal-tag" dict "Kind" "contact" "ID" $p.ID "SignalID" $p.SignalID "D" $d}}{{end}}
{{with index .Matches (printf "contact:%d" $p.ID)}}{{template "crm-matches" .}}{{end}}
{{template "outcomes" dict "Kind" "contact" "ID" $p.ID "Tab" $tab "D" $d}}
</div>
{{if eq $p.Status $tab}}
<div class="row-actions">
{{if eq $tab "new"}}
<form method="post" action="/prospects/contact/{{$p.ID}}/accept"><input type="hidden" name="tab" value="{{$tab}}"><button type="submit" class="small">Accept</button></form>
<form method="post" action="/prospects/contact/{{$p.ID}}/reject"><input type="hidden" name="tab" value="{{$tab}}"><button type="submit" class="secondary small">Set aside</button></form>
{{if $p.Email}}<form method="post" action="/prospects/contact/{{$p.ID}}/suppress" data-confirm="Never add {{$p.Email}}? This puts the address on your suppression list."><input type="hidden" name="tab" value="{{$tab}}"><button type="submit" class="secondary small">Suppress</button></form>{{end}}
<form method="post" action="/prospects/contact/{{$p.ID}}/accept"><input type="hidden" name="tab" value="{{$tab}}"><input type="hidden" name="filter" value="{{$d.Signal}}"><button type="submit" class="small">Accept</button></form>
<form method="post" action="/prospects/contact/{{$p.ID}}/reject"><input type="hidden" name="tab" value="{{$tab}}"><input type="hidden" name="filter" value="{{$d.Signal}}"><button type="submit" class="secondary small">Set aside</button></form>
{{if $p.Email}}<form method="post" action="/prospects/contact/{{$p.ID}}/suppress" data-confirm="Never add {{$p.Email}}? This puts the address on your suppression list."><input type="hidden" name="tab" value="{{$tab}}"><input type="hidden" name="filter" value="{{$d.Signal}}"><button type="submit" class="secondary small">Suppress</button></form>{{end}}
{{else if eq $tab "accepted"}}
{{template "crm-state" dict "CRM" $p.CRM "Kind" "contact" "ID" $p.ID "Tab" $tab}}
{{template "crm-state" dict "CRM" $p.CRM "Kind" "contact" "ID" $p.ID "Tab" $tab "Filter" $d.Signal}}
{{else}}
<form method="post" action="/prospects/contact/{{$p.ID}}/reconsider"><input type="hidden" name="tab" value="{{$tab}}"><button type="submit" class="secondary small">Reconsider</button></form>
<form method="post" action="/prospects/contact/{{$p.ID}}/reconsider"><input type="hidden" name="tab" value="{{$tab}}"><input type="hidden" name="filter" value="{{$d.Signal}}"><button type="submit" class="secondary small">Reconsider</button></form>
{{end}}
</div>
{{end}}
@@ -114,8 +130,44 @@
{{if eq .CRM.Status "done"}}<span class="badge published">{{if eq .CRM.Outcome "existing"}}already in the CRM{{else}}in the CRM{{end}}</span>
{{else if eq .CRM.Status "failed"}}<span class="badge failed">failed</span> <a class="small" href="/crm">CRM queue</a>
{{else if eq .CRM.Status "cancelled"}}<span class="badge">cancelled</span>
<form method="post" action="/prospects/{{.Kind}}/{{.ID}}/accept"><input type="hidden" name="tab" value="{{.Tab}}"><button type="submit" class="secondary small">Queue again</button></form>
<form method="post" action="/prospects/{{.Kind}}/{{.ID}}/accept"><input type="hidden" name="tab" value="{{.Tab}}"><input type="hidden" name="filter" value="{{.Filter}}"><button type="submit" class="secondary small">Queue again</button></form>
{{else if eq .CRM.Status "claimed"}}<span class="badge scheduled">with Hermes</span>
{{else if .CRM.Status}}<span class="badge draft">waiting for Hermes</span>
{{else}}<span class="badge">accepted</span>{{end}}
{{end}}
{{define "signal-tag"}}{{$d := .D}}{{$cur := .SignalID}}
{{if $d.Signals}}
<form method="post" action="/prospects/{{.Kind}}/{{.ID}}/signal" class="signal-tag">
<input type="hidden" name="tab" value="{{$d.Tab}}"><input type="hidden" name="filter" value="{{$d.Signal}}">
<label class="small">Signal
<select name="signal" data-autosubmit>
<option value="0">none</option>
{{range $d.Signals}}<option value="{{.ID}}" {{if eq .ID $cur}}selected{{end}}>{{.Name}}</option>{{end}}
</select>
</label>
<noscript><button type="submit" class="secondary small">Save</button></noscript>
</form>
{{end}}
{{end}}
{{define "outcomes"}}{{$d := .D}}{{$subject := printf "%s:%d" .Kind .ID}}
{{with index $d.Events $subject}}
<ol class="steps-done">
{{range .}}<li><span class="badge {{if eq .Stage "paid"}}published{{else}}draft{{end}}">{{stage .Stage}}</span> {{channel .Channel}} · {{ago .At}}{{if .ValueCents}} · {{money .ValueCents}}{{end}}{{with .Note}} · {{truncate 100 .}}{{end}}
{{if eq .Source "manual"}}<form method="post" action="/funnel/{{.ID}}/delete" class="inline" data-confirm="Remove this step?"><input type="hidden" name="back" value="{{$d.Back}}"><input type="hidden" name="tab" value="{{$d.Tab}}"><button type="submit" class="link small">remove</button></form>{{end}}</li>{{end}}
</ol>
{{end}}
<details class="outcome">
<summary class="small">Record an outcome</summary>
<form method="post" action="/prospects/{{.Kind}}/{{.ID}}/outcome" class="row wrap">
<input type="hidden" name="tab" value="{{.Tab}}"><input type="hidden" name="filter" value="{{$d.Signal}}">
<label class="small">Step <select name="stage">{{range $d.Stages}}<option value="{{.ID}}">{{.Label}}</option>{{end}}</select></label>
<label class="small">Channel <select name="channel">{{range $d.Channels}}<option value="{{.ID}}">{{.Label}}</option>{{end}}</select></label>
<label class="small">Date <input type="date" name="date" value="{{$d.Today}}"></label>
<label class="small">Amount <input name="amount" inputmode="decimal" placeholder="for Paid, e.g. 70" size="8"></label>
<label class="small grow">Note <input name="note" placeholder="optional"></label>
<button type="submit" class="secondary small">Record</button>
</form>
</details>
{{end}}
+69
View File
@@ -0,0 +1,69 @@
{{define "content"}}{{with .Data}}{{$s := .S}}
<div class="heading">
<h1>{{if $s.ID}}{{$s.Name}} <span class="badge {{$s.Status}}">{{$s.Status}}</span>{{else}}New signal{{end}}</h1>
{{if $s.ID}}<div class="buttons">
<a class="button secondary" href="/prospects?status=new&amp;signal={{$s.ID}}">Its prospects{{if .Prospects}} ({{.Prospects}} new){{end}}</a>
<a class="button secondary" href="/prospects/new?signal={{$s.ID}}">Add a prospect for it</a>
</div>{{end}}
</div>
<p class="lede">A guess about why a company buys now, written so it can be tested: what you'll see, and what you expect them to do.</p>
{{if $s.ID}}
{{with .Total}}
<section class="card">
<h2>Funnel</h2>
<div class="funnel">
{{range .Cells}}<div class="step"><span class="label">{{stage .Stage}}</span><strong>{{.Count}}</strong>{{with .Rate}}<span class="rate">{{.}} of contacted</span>{{end}}</div>{{end}}
</div>
<p class="small">{{if .RevenueCents}}Revenue <strong>{{money .RevenueCents}}</strong>. {{end}}{{if .SpendCents}}Spend in outside tools <strong>{{money .SpendCents}}</strong>.{{end}}</p>
{{if $.Data.ByChannel}}
<table class="list scorecard">
<thead><tr><th>Channel</th>{{range $.Data.Stages}}<th class="num">{{.Label}}</th>{{end}}</tr></thead>
<tbody>{{range $.Data.ByChannel}}<tr><td>{{channel .Channel}}</td>{{range .Row.Cells}}<td class="num">{{if .Count}}{{.Count}}{{with .Rate}}<span class="rate">{{.}}</span>{{end}}{{else}}<span class="muted">·</span>{{end}}</td>{{end}}</tr>{{end}}</tbody>
</table>
{{else}}<p class="help">Nothing recorded for it yet: tag prospects with it, give it an origami.chat or explee.com campaign, or record outcomes in Review.</p>{{end}}
</section>
{{end}}
{{end}}
<form method="post" action="{{if $s.ID}}/signals/{{$s.ID}}{{else}}/signals/new{{end}}" class="card">
<div class="cols">
<label>Name <input name="name" value="{{$s.Name}}" required placeholder="Leaving Microsoft 365"></label>
<label>Status
<select name="status">{{range .Statuses}}<option value="{{.}}" {{if eq . $s.Status}}selected{{end}}>{{.}}</option>{{end}}</select>
<span class="help">Idea, testing, proven or retired. Retired signals stay on the scorecard for comparison.</span>
</label>
</div>
<label>Hypothesis <textarea name="hypothesis" rows="2" placeholder="Teams complaining about the Microsoft 365 price rise switch within a quarter.">{{$s.Hypothesis}}</textarea></label>
<label>How to spot it <textarea name="spot" rows="4" placeholder="One per line: search queries, keywords, origami.chat or explee.com criteria">{{$s.Spot}}</textarea>
<span class="help">Discovery (next) runs these as searches, so write them the way you'd search for the companies.</span></label>
<label>Angle <textarea name="angle" rows="3" placeholder="The pain, and what we promise about it">{{$s.Angle}}</textarea>
<span class="help">What emails, LinkedIn messages and content for this signal should say.</span></label>
<label>Campaign tag <input name="slug" value="{{$s.Slug}}" placeholder="made from the name">
<span class="help">Used as <code>utm_campaign</code> on links for this signal, so visits and sign-ups are counted against it. Change it before using it, not after.</span></label>
<div class="actions">
<button type="submit">Save</button>
<a href="/signals">Back to signals</a>
</div>
</form>
{{if $s.ID}}
{{if .Campaigns}}
<h2>Campaigns testing it</h2>
<ul class="items">{{range .Campaigns}}<li class="item"><strong>{{.Name}}</strong> <span class="muted small">{{if eq .Source "origami"}}origami.chat{{else}}explee.com{{end}}{{with .Status}} · {{.}}{{end}}</span>
<div class="small">{{range $k, $v := .Stats}}{{if $v}}<span class="stat">{{$k}}: <strong>{{$v}}</strong></span> {{end}}{{end}}</div></li>{{end}}</ul>
{{end}}
{{if .Events}}
<h2>Latest steps</h2>
<table class="list">
<thead><tr><th>When</th><th>Step</th><th>Channel</th><th>Who</th><th>Note</th></tr></thead>
<tbody>{{range .Events}}<tr><td>{{ago .At}}</td><td>{{stage .Stage}}{{if .ValueCents}} · {{money .ValueCents}}{{end}}{{if gt .Count 1}} · {{.Count}}{{end}}</td><td>{{channel .Channel}}</td><td class="small">{{or .Email .Subject}}</td><td class="small">{{truncate 120 .Note}}</td></tr>{{end}}</tbody>
</table>
{{end}}
<form method="post" action="/signals/{{$s.ID}}/delete" data-confirm="Delete “{{$s.Name}}”? Its prospects, campaigns and results stay, without a signal." class="danger-zone">
<button type="submit" class="secondary small">Delete this signal</button>
</form>
{{end}}
{{end}}{{end}}
+81
View File
@@ -0,0 +1,81 @@
{{define "content"}}{{with .Data}}{{$d := .}}
<div class="heading">
<h1>Signals</h1>
<div class="buttons"><a class="button" href="/signals/new">New signal</a></div>
</div>
<p class="lede">A buying signal is a guess about why a company buys now. Each one is tested through what's done for it, directly (email, LinkedIn) and indirectly (posts, pages), and in origami.chat and explee.com. Every step anyone takes through the funnel is counted here, so you can see which signals turn into replies, bookings, sign-ups and payments.</p>
<form method="get" action="/signals" class="filters">
<label class="small">Period
<select name="period" data-autosubmit>{{range .Periods}}<option value="{{.ID}}" {{if eq .ID $d.Period}}selected{{end}}>{{.Label}}</option>{{end}}</select>
</label>
<label class="small">Channel
<select name="channel" data-autosubmit><option value="">All channels</option>{{range .Channels}}<option value="{{.ID}}" {{if eq .ID $d.Channel}}selected{{end}}>{{.Label}}</option>{{end}}</select>
</label>
<noscript><button type="submit" class="secondary small">Show</button></noscript>
</form>
{{if .Rows}}
<div class="table-wrap">
<table class="list scorecard">
<thead><tr><th>Signal</th>{{range .Stages}}<th class="num">{{.Label}}</th>{{end}}<th class="num">Revenue</th><th class="num">Spend</th></tr></thead>
<tbody>
{{range .Rows}}
<tr>
<td>{{with .Signal}}<a href="/signals/{{.ID}}">{{.Name}}</a> <span class="badge {{.Status}}">{{.Status}}</span>{{else}}<span class="muted">No signal</span>{{end}}</td>
{{range .Cells}}<td class="num">{{if .Count}}{{.Count}}{{with .Rate}}<span class="rate">{{.}}</span>{{end}}{{else}}<span class="muted">·</span>{{end}}</td>{{end}}
<td class="num">{{if .RevenueCents}}{{money .RevenueCents}}{{else}}<span class="muted">·</span>{{end}}</td>
<td class="num">{{if .SpendCents}}{{money .SpendCents}}{{else}}<span class="muted">·</span>{{end}}</td>
</tr>
{{end}}
</tbody>
</table>
</div>
<p class="help">People count once per stage, however many times they replied. Percentages are of those contacted. Visits are counted in total, not per person. Spend is what origami.chat and explee.com report for each signal's campaigns, all time. A signal moves to <em>proven</em> when you say so.</p>
{{else}}
<section class="card empty"><p>No signals yet. <a href="/signals/new">Write down the first one</a>: for example, “Teams complaining about the Microsoft 365 price rise switch within a quarter.”</p></section>
{{end}}
<h2 id="campaigns">Campaigns in origami.chat and explee.com</h2>
<p class="lede">Supermarket reads your campaigns, who they contacted, who replied, who was interested and who unsubscribed, every 6 hours. Give each campaign the signal it tests; its results count towards that signal. Interested people and people who replied show up in <a href="/prospects">Review</a>, and anyone who unsubscribed goes on the <a href="/prospects/suppressed">suppression list</a>.</p>
<div class="grid">
{{range .Sources}}
<section class="card">
<h3>{{.Name}}</h3>
{{if .Set}}
{{with .Last}}<p class="small">{{if .Error}}<span class="warn-text">Last import failed {{ago .At}}: {{.Error}}</span>{{else}}Imported {{ago .At}}: {{.Campaigns}} campaigns, {{.Events}} new steps, {{.Prospects}} new people to review, {{.Suppressed}} unsubscribed.{{end}}</p>
{{if .Warnings}}<details class="small"><summary>{{len .Warnings}} warnings</summary><ul>{{range .Warnings}}<li>{{.}}</li>{{end}}</ul></details>{{end}}
{{else}}<p class="small">Not imported yet.</p>{{end}}
<form method="post" action="/lead-sources/{{.ID}}/import" data-busy="Importing…"><button type="submit" class="secondary small">Import now</button></form>
{{else}}<p class="small">Not connected. Save its API key under <a href="/settings/sources">Settings → Lead sources</a>.</p>{{end}}
</section>
{{end}}
</div>
{{if .Campaigns}}
<table class="list">
<thead><tr><th>Campaign</th><th>Numbers</th><th class="num">Spend</th><th>Signal</th></tr></thead>
<tbody>
{{range .Campaigns}}
<tr>
<td><strong>{{.Name}}</strong><br><span class="muted small">{{if eq .Source "origami"}}origami.chat{{else}}explee.com{{end}}{{with .Status}} · {{.}}{{end}} · read {{ago .SyncedAt}}</span></td>
<td class="small">{{range $k, $v := .Stats}}{{if $v}}<span class="stat">{{$k}}: <strong>{{$v}}</strong></span> {{end}}{{end}}</td>
<td class="num">{{if .SpendCents}}{{money .SpendCents}}{{end}}</td>
<td>
<form method="post" action="/signals/campaigns" class="row">
<input type="hidden" name="source" value="{{.Source}}"><input type="hidden" name="id" value="{{.ID}}">
{{$cur := .SignalID}}
<select name="signal" data-autosubmit aria-label="Signal for {{.Name}}">
<option value="0">No signal yet</option>
{{range $d.Signals}}<option value="{{.ID}}" {{if eq .ID $cur}}selected{{end}}>{{.Name}}</option>{{end}}
</select>
<noscript><button type="submit" class="secondary small">Save</button></noscript>
</form>
</td>
</tr>
{{end}}
</tbody>
</table>
{{end}}
{{end}}{{end}}
+31
View File
@@ -0,0 +1,31 @@
{{define "content"}}{{template "settings-start" .}}{{with .Data}}
<h2>Lead sources</h2>
<p class="lede">The prospecting tools you test buying signals in. Supermarket only reads from them: campaigns and their numbers, who was contacted, who replied, who was interested and who unsubscribed. It never starts, changes or sends anything there. Results appear on <a href="/signals">Signals</a>.</p>
<form method="post" action="/settings/sources" autocomplete="off">
{{range .Sources}}
<section class="card">
<h3>{{.Name}}</h3>
{{template "key-field" (dict "F" .Key "Set" .Set)}}
{{if eq .ID "origami"}}
<label>Project <span class="muted small">(optional)</span> <input name="origami_project" value="{{$.Data.Project}}" placeholder="a project ID, to read only that project">
<span class="help">If your organization has projects, the ID of the one to read. Leave empty to read the whole organization.</span></label>
{{end}}
{{if .Set}}
<button type="button" class="secondary small" hx-post="/settings/sources/test/{{.ID}}" hx-target="#test-{{.ID}}" hx-indicator="#testing-{{.ID}}">Test</button>
<span id="testing-{{.ID}}" class="htmx-indicator">Checking…</span>
<div id="test-{{.ID}}"></div>
{{end}}
</section>
{{end}}
<div class="actions"><button type="submit">Save</button></div>
</form>
{{end}}{{template "settings-end"}}{{end}}
{{define "test-result"}}
{{with .Error}}<p class="error">{{.}}</p>{{end}}
{{with .OK}}<p class="ok">{{.}}</p>{{end}}
{{with .Sample}}<details><summary>What the API sends</summary>
<p class="help">origami.chat doesn't document its responses, so Supermarket looks fields up by the names its docs use. If an import misses replies or contacts, this shows the real names.</p>
<pre class="sample">{{.}}</pre></details>{{end}}
{{end}}