Phase 2 part 7: the end of the funnel
Posts can be written for a buying signal: the prompt gets its hypothesis and angle, and links carry its campaign tag. Plausible (Stats API v2) is read once a day for visitors on tagged links, recorded per signal as Visited. Stripe (restricted key) is read every hour: $0 checkouts are Signed up, paid invoices and one-time payments are Paid with their value, tied to a signal by the checkout's utm_campaign metadata or the payer's email. The Core's Cal.com has no API, so booking emails from Cal.com in the outreach mailbox count as Booked. New Settings → Website & sales; the signal page lists its posts and tagged links. Schema 11. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -78,6 +78,8 @@ type Draft struct {
|
||||
UpdatedAt time.Time
|
||||
PublishedAt time.Time
|
||||
PublishAt time.Time // when a scheduled draft goes out
|
||||
SignalID int64 // the buying signal it was written for; 0: none
|
||||
SignalSlug string // that signal's campaign tag
|
||||
}
|
||||
|
||||
// Length is the draft's length as its channel counts it, including the
|
||||
@@ -167,9 +169,13 @@ func CreateDrafts(d *db.DB, drafts []Draft) (string, error) {
|
||||
return "", fmt.Errorf("unknown channel %q", dr.Channel)
|
||||
}
|
||||
ids, _ := json.Marshal(nonNil(dr.ItemIDs))
|
||||
if _, err := tx.Exec(`INSERT INTO drafts (batch, inventory_name, kind, channel, title, target, content, source_url, item_ids)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`, batch, dr.InventoryName, dr.Kind, dr.Channel,
|
||||
strings.TrimSpace(dr.Title), dr.Target, strings.TrimSpace(dr.Content), dr.SourceURL, string(ids)); err != nil {
|
||||
var sig any
|
||||
if dr.SignalID != 0 {
|
||||
sig = dr.SignalID
|
||||
}
|
||||
if _, err := tx.Exec(`INSERT INTO drafts (batch, inventory_name, kind, channel, title, target, content, source_url, item_ids, signal_id)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, batch, dr.InventoryName, dr.Kind, dr.Channel,
|
||||
strings.TrimSpace(dr.Title), dr.Target, strings.TrimSpace(dr.Content), dr.SourceURL, string(ids), sig); err != nil {
|
||||
return "", err
|
||||
}
|
||||
for _, id := range dr.ItemIDs {
|
||||
@@ -193,7 +199,8 @@ func nonNil(s []string) []string {
|
||||
}
|
||||
|
||||
const draftColumns = `id, batch, inventory_name, kind, channel, content, source_url, item_ids, status, error,
|
||||
post_url, created_at, updated_at, COALESCE(published_at, ''), COALESCE(publish_at, ''), title, target`
|
||||
post_url, created_at, updated_at, COALESCE(published_at, ''), COALESCE(publish_at, ''), title, target,
|
||||
COALESCE(signal_id, 0), COALESCE((SELECT slug FROM signals WHERE signals.id = drafts.signal_id), '')`
|
||||
|
||||
func scanDrafts(rows *sql.Rows) ([]Draft, error) {
|
||||
defer rows.Close()
|
||||
@@ -202,7 +209,8 @@ func scanDrafts(rows *sql.Rows) ([]Draft, error) {
|
||||
var dr Draft
|
||||
var ids, created, updated, published, publishAt string
|
||||
if err := rows.Scan(&dr.ID, &dr.Batch, &dr.InventoryName, &dr.Kind, &dr.Channel, &dr.Content,
|
||||
&dr.SourceURL, &ids, &dr.Status, &dr.Error, &dr.PostURL, &created, &updated, &published, &publishAt, &dr.Title, &dr.Target); err != nil {
|
||||
&dr.SourceURL, &ids, &dr.Status, &dr.Error, &dr.PostURL, &created, &updated, &published, &publishAt, &dr.Title, &dr.Target,
|
||||
&dr.SignalID, &dr.SignalSlug); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_ = json.Unmarshal([]byte(ids), &dr.ItemIDs)
|
||||
@@ -301,6 +309,17 @@ func RecoverInterrupted(d *db.DB) (int, error) {
|
||||
return int(n), nil
|
||||
}
|
||||
|
||||
// ForSignal lists the posts written for a signal, newest first: the
|
||||
// published ones, then the rest that aren't discarded.
|
||||
func ForSignal(d *db.DB, signalID int64, limit int) ([]Draft, error) {
|
||||
rows, err := d.Query(`SELECT `+draftColumns+` FROM drafts WHERE signal_id = ? AND status != ?
|
||||
ORDER BY published_at IS NULL, published_at DESC, id DESC LIMIT ?`, signalID, StatusDiscarded, limit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return scanDrafts(rows)
|
||||
}
|
||||
|
||||
// CountDrafts is how many drafts wait for review.
|
||||
func CountDrafts(d *db.DB) (int, error) {
|
||||
var n int
|
||||
|
||||
Reference in New Issue
Block a user