Approvals

2 entries

Markdown

m.propose

Hold an action until a person decides.

Signature
m.propose(kind, *, title, detail=None)
Example · Inside a job
asked = m.propose("send_quote", title="Email the quote to Ava", detail={"quote": 41})

The owner sees it on Approvals, and a push on their phone. When they say yes, your Ownbox runs what m.on_approve(kind, fn) registered, once, with detail. The same kind and detail while one waits is the same proposal. Never raises.

Needs in machine.yaml
Nothing
Returns
{"status": "waiting" | "repeat" | "refused", "id", "code", "reason", "href"}. Decide on code: "no_such_kind" (register it with m.on_approve first), "bad_kind", "too_large" (detail over 16,000 characters as JSON), "bad_title".

m.on_approve

What runs when a person approves a proposal.

Signature
m.on_approve(kind, fn)
Example · Where the machine is defined
def send_quote(detail):
    pid = m.person("email", "ava@example.com")
    return m.send_email(pid, {"subject": "Your quote", "text": "Here it is."}, key=f"quote:{detail['quote']}")

m.on_approve("send_quote", send_quote)

fn(detail) runs once, after they said yes. kind is lowercase letters, digits and underscores; register it before the machine proposes one.

Needs in machine.yaml
Nothing