The Skript book · Appendix B

Cookbook

Eight complete programs, each solving one recognisable business problem, each runnable exactly as printed (the outputs below are their real runs). Adapt by editing the quoted strings — names, messages, thresholds — and re-running.

1 · The classic: score-and-route triage

The poster program, grown up: three-way routing with a guard for unreachable leads.

when a new lead arrives
  score it with ai
  if phone is "" then
    create task "Find contact info for {name}" and stop
  if score is hot then
    assign to "Maya" and reply on whatsapp
      "Thanks {name}! We'll call you in 10 minutes."
  otherwise
    if score is warm then
      assign to "Sam" and add tag "follow-up-today"
    otherwise
      add tag "nurture"
output — real, executed at build time
▶ example.skript — Skode Skript · local simulation

  ● event: lead.created                → name: Ada · phone: +1 555 0100 · email: [email protected]
  ⚡ score it with ai                   → score 84 · HOT
  ✗ if phone is ""                     → no
  ✓ if score is hot                    → yes
  → assign to "Maya"                   → lead assigned
  ✉ reply on whatsapp                  → "Thanks Ada! We'll call you in 10 minutes."

  ✔ done in 2.1ms — 1 message · assigned to Maya

2 · Form follow-up with a task trail

when a form is submitted
  score it with ai
  add tag "form: {form}"
  if score is hot then
    assign to "Maya"
    send email to "[email protected]" "Hot form lead: {name} — {message}"
    create task "Reply personally within the hour" for "Maya"
  otherwise
    reply on email "Thanks {name} — we'll be in touch this week."
output — real, executed at build time
▶ example.skript — Skode Skript · local simulation

  ● event: form.submitted              → form: Contact us · name: Grace Hopper · email: [email protected]
  ⚡ score it with ai                   → score 88 · HOT
  ⚑ add tag "form: Contact us"         → tagged
  ✓ if score is hot                    → yes
  → assign to "Maya"                   → submission assigned
  ✉ send email to "[email protected]"      → "Hot form lead: Grace Hopper — Interested in the Pro plan"
  ☑ create task "Reply personally within the hour" → created

  ✔ done in 2.1ms — 1 message · assigned to Maya · tags: form: Contact us · 1 task

3 · A drip sequence

wait makes time a step. Locally the waits are instant and labelled; in production this is a real three-touch sequence.

when a new lead arrives
  reply on email "Welcome, {name}! Here's what Skode can do."
  wait 2 days
  reply on email "A quick case study you might like, {name}."
  wait 3 days
  reply on email "Any questions? Just hit reply."
  add tag "drip-complete"
output — real, executed at build time
▶ example.skript — Skode Skript · local simulation

  ● event: lead.created                → name: Priya · phone: +1 555 0100 · email: [email protected]
  ✉ reply on email                     → "Welcome, Priya! Here's what Skode can do."
  ◌ wait 2 days                        → (simulated — instant here, real delay in Skode)
  ✉ reply on email                     → "A quick case study you might like, Priya."
  ◌ wait 3 days                        → (simulated — instant here, real delay in Skode)
  ✉ reply on email                     → "Any questions? Just hit reply."
  ⚑ add tag "drip-complete"            → tagged

  ✔ done in 2.1ms — 3 messages · tags: drip-complete

4 · Invoice receipts, with a VIP touch

when an invoice is paid
  reply on email "Receipt for invoice {number} — thank you!"
  add tag "paid"
  if amount is above 5000 then
    create task "Send a handwritten thank-you to {name}" for "Maya"
    add tag "vip"
output — real, executed at build time
▶ example.skript — Skode Skript · local simulation

  ● event: invoice.paid                → number: INV-0461 · amount: 9500 · name: Margaret H
  ✉ reply on email                     → "Receipt for invoice INV-0461 — thank you!"
  ⚑ add tag "paid"                     → tagged
  ✓ if amount above 5000               → yes
  ☑ create task "Send a handwritten thank-you to {name}" → created
  ⚑ add tag "vip"                      → tagged

  ✔ done in 2.1ms — 1 message · tags: paid, vip · 1 task

5 · Message keyword router

Sequential ifs make a tidy keyword switchboard; functions keep each route readable.

when a message arrives
  if text contains "pricing" then
    route to sales
  if text contains "refund" then
    route to support
  if text contains "partner" then
    create task "Partnership inquiry from {name}" for "Ops"

to route to sales
  assign to "Maya" and add tag "sales-inquiry"
  reply on whatsapp "Great question, {name} — connecting you with Maya now."

to route to support
  assign to "Sam" and add tag "support"
  reply on whatsapp "Sorry to hear that, {name} — Sam is on it."
output — real, executed at build time
▶ example.skript — Skode Skript · local simulation

  ● event: message.received            → from: +1 555 0101 · name: Lin · channel: whatsapp
  ✓ if text contains "pricing"         → yes
  ƒ route to sales                     → run your function
  → assign to "Maya"                   → message assigned
  ⚑ add tag "sales-inquiry"            → tagged
  ✉ reply on whatsapp                  → "Great question, Lin — connecting you with Maya now."
  ✗ if text contains "refund"          → no
  ✗ if text contains "partner"         → no

  ✔ done in 2.1ms — 1 message · assigned to Maya · tags: sales-inquiry

6 · Deal-won celebration and handover

when a deal is won
  send slack "{owner} closed {name} for {amount}!"
  create task "Kick off onboarding for {name}" for "Success Team"
  add tag "customer"
  set commission to amount / 20
  log "commission earned: {commission}"
output — real, executed at build time
▶ example.skript — Skode Skript · local simulation

  ● event: deal.won                    → name: Skylark Corp · amount: 14000 · owner: Maya
  ✉ send slack                         → "Maya closed Skylark Corp for 14000!"
  ☑ create task "Kick off onboarding for {name}" → created
  ⚑ add tag "customer"                 → tagged
  ✎ set commission                     → = 700
  • log                                → commission earned: 700

  ✔ done in 2.1ms — 1 message · tags: customer · 1 task

7 · Multi-channel escalation sweep

The pattern for "make sure someone sees this": alert on every channel, then log an audit line. Note that a channel is part of the sentence, not a value — send slack … — so each channel gets its own explicit send (a feature, for auditability: the reader sees exactly where alerts go). A function keeps the sweep tidy, and a small loop assembles the audit trail:

when a new lead arrives
  score it with ai
  if score is above 95 then
    sound the alarm
    create task "Drop everything and call {name}" for "Maya"
    set alerted to ""
    for each ch in "slack", "email", "sms"
      add "{ch} " to alerted
    log "alerted via: {alerted}"

to sound the alarm
  send slack "URGENT: {name}, budget {budget} — score {score}"
  send email to "[email protected]" "URGENT: {name}, budget {budget}"
  send sms "URGENT lead: {name}"
output — real, executed at build time
▶ example.skript — Skode Skript · local simulation

  ● event: lead.created                → name: Whale Corp · phone: +1 555 0100 · email: [email protected]
  ⚡ score it with ai                   → score 97 · HOT
  ✓ if score above 95                  → yes
  ƒ sound the alarm                    → run your function
  ✉ send slack                         → "URGENT: Whale Corp, budget 80000 — score 97"
  ✉ send email to "[email protected]"      → "URGENT: Whale Corp, budget 80000"
  ✉ send sms                           → "URGENT lead: Whale Corp"
  ☑ create task "Drop everything and call {name}" → created
  ✎ set alerted                        → = ""
  ↻ for each ch in ["slack", "email", "sms"] → 3 items
  ✎ add to alerted                     → = "slack "
  ✎ add to alerted                     → = "slack email "
  ✎ add to alerted                     → = "slack email sms "
  • log                                → alerted via: slack email sms 

  ✔ done in 2.1ms — 3 messages · 1 task

8 · The self-auditing rule

The pattern that makes on-call life bearable: narrate decisions as you make them, and end with a summary a human can read in the run log.

when a new lead arrives
  score it with ai
  set verdict to "undecided"
  if score is hot then
    set verdict to "routed to Maya" and assign to "Maya"
  if score is warm then
    if budget is above 500 then
      set verdict to "warm but funded - Sam" and assign to "Sam"
    otherwise
      set verdict to "nurture list" and add tag "nurture"
  if score is cold then
    set verdict to "archived" and add tag "cold"
  log "AUDIT {name} from {source}: score {score} ({heat}) -> {verdict}"
output — real, executed at build time
▶ example.skript — Skode Skript · local simulation

  ● event: lead.created                → name: Kiran · phone: +1 555 0100 · email: [email protected]
  ⚡ score it with ai                   → score 55 · WARM
  ✎ set verdict                        → = "undecided"
  ✗ if score is hot                    → no
  ✓ if score is warm                   → yes
  ✓ if budget above 500                → yes
  ✎ set verdict                        → = "warm but funded - Sam"
  → assign to "Sam"                    → lead assigned
  ✗ if score is cold                   → no
  • log                                → AUDIT Kiran from webinar: score 55 (warm) -> warm but funded - Sam

  ✔ done in 2.1ms — assigned to Sam

9 · Budget-band pricing assistant

Thresholds as data: one list, one loop, one decision — change the bands without touching the logic.

when a new lead arrives
  set band to "starter"
  for each threshold in 1000, 2500, 10000
    if budget is at least threshold then
      set band to "band-{threshold}"
  add tag "{band}"
  log "{name} with budget {budget} lands in {band}"
output — real, executed at build time
▶ example.skript — Skode Skript · local simulation

  ● event: lead.created                → name: Kiran · phone: +1 555 0100 · email: [email protected]
  ✎ set band                           → = "starter"
  ↻ for each threshold in [1000, 2500, 10000] → 3 items
  ✗ if budget is "at least threshold"  → no
  ✗ if budget is "at least threshold"  → no
  ✗ if budget is "at least threshold"  → no
  ⚑ add tag "starter"                  → tagged
  • log                                → Kiran with budget 2600 lands in starter

  ✔ done in 2.1ms — tags: starter

(A subtlety worth stealing: the loop runs low-to-high and simply overwrites band at each threshold the budget clears, so the final value is the highest band cleared — no nested ifs required. Note add tag "{band}" interpolating a variable into the label.)

10 · Weekly-source hygiene check

Not every skript talks to customers. This one polices data quality and files the paperwork for a human — automation as janitor.

when a new lead arrives
  set problems to ""
  if source is "" then
    add "no-source " to problems
  if email is "" then
    add "no-email " to problems
  if problems is not "" then
    add tag "needs-cleanup"
    create task "Fix lead data for {name}: {problems}" for "Ops"
    log "flagged: {problems}"
  otherwise
    log "clean record"
output — real, executed at build time
▶ example.skript — Skode Skript · local simulation

  ● event: lead.created                → name: Ghost Lead · phone: +1 555 0100 · email: 
  ✎ set problems                       → = ""
  ✓ if source is ""                    → yes
  ✎ add to problems                    → = "no-source "
  ✓ if email is ""                     → yes
  ✎ add to problems                    → = "no-source no-email "
  ✓ if problems is not ""              → yes
  ⚑ add tag "needs-cleanup"            → tagged
  ☑ create task "Fix lead data for {name}: {problems}" → created
  • log                                → flagged: no-source no-email 

  ✔ done in 2.1ms — tags: needs-cleanup · 1 task

11 · The polite decliner

Saying no is an automation too. Small budgets get a kind message and a future-proof tag instead of silence:

when a new lead arrives
  score it with ai
  if budget is below 100 then
    reply on email
      "Thanks for your interest, {name}!"
      "We're likely overkill for your current needs - but keep us in mind as you grow."
    add tag "future-fit" and stop
  add tag "qualified"
output — real, executed at build time
▶ example.skript — Skode Skript · local simulation

  ● event: lead.created                → name: Tiny Co · phone: +1 555 0100 · email: [email protected]
  ⚡ score it with ai                   → score 30 · COLD
  ✓ if budget below 100                → yes
  ✉ reply on email                     → "Thanks for your interest, Tiny Co!\nWe're likely overkill for your current needs - but keep us in mind as you grow."
  ⚑ add tag "future-fit"               → tagged
  ■ stop                               → skript halted

  ✔ done in 2.1ms — 1 message · tags: future-fit

Every recipe here is four ideas deep at most — an event, a decision, a handful of actions, and a note for the humans. That is not because the examples are simplified; it is because that is the honest shape of good automation. When yours grows past it, reach for a function and give the complexity a name.