Submit the selection
When. The person chose items and confirms: the station files them with the tenant (an order, a booking, a request), or sends them to finish on its site.
Steps
- Write
submiton the skill (or on a kind): a list of named calls, run in order. - Choose the
mode:request(Convoy callstool, anaccess: writeoperation),handover(the person finishes on the tenant's site, throughurl) orself(nothing is sent). - Write the
args:$selection[kind=<kind>](the lines),$item.fields.<field>,$item.price,$item.ref,$params.<name>,$submit.<field>,$action.key. - Give the shape of a line with
line:, in the tenant's keys:{product_id: "$line.ref", quantity: "$line.quantity"}. - Keep what another call reads in
output({from: "$output.<path>", type: …}); the tenant's total withrole: billed, which Core compares with the lines. - Write the
submit_guard:confirm: true(the person confirms), aformread through$submit.<field>, andsubmitted_by: [{who: owner}]to keep it to the signed-in owner.
The example
submit-the-selection.yaml
# Submit the selection: the person chooses plants on cards, then confirms; one call files them
# with the tenant's write operation, one line per plant in the tenant's own shape, under an
# idempotency key a retry sends again. The tenant's total is compared with what the person saw.
# Replace api.example.com by the API.
station:
id: plant-nursery
name: Plant Nursery
global:
language: en
currency: EUR
locale: en-GB
domain:
domain_type: retail
entity_name: plant
entity_name_plural: plants
voice:
tone: friendly
persona: "a gardener who knows every plant of the nursery"
rules:
- "Never say an order is placed before the submit returned it."
apis:
- name: nursery
openapi_url: https://api.example.com/openapi.json
base_url: https://api.example.com
operations:
- {id: listPlants, access: read}
- {id: placeOrder, access: write} # a write: only a confirmed submit calls it
auth: {type: none}
profiles:
everyone:
when: "true"
grants: [nursery.listPlants, nursery.placeOrder]
skills:
- name: plants
cognitive:
objective: show the plants, for the person to choose theirs
invoke: {method: listPlants}
kinds: {plant: {}}
present:
fields:
name: {from: name, type: text, role: title}
price: {from: price, type: price, role: billed}
submit:
- name: order
mode: request # Convoy calls the tenant's operation
tool: placeOrder
args:
body.items: "$selection[kind=plant]" # the lines, in the shape of `line`
body.customer.phone: "$submit.phone" # what the submit's form asked
body.idempotency_key: "$action.key" # never $item.id
line: {product_id: "$line.ref", quantity: "$line.quantity"} # the tenant's own keys
output:
total: {from: "$output.total", type: price, role: billed} # compared with the lines
render: {component: cards}
submit_guard:
form:
phone: {type: phone, required: true, label: "Phone"}
confirm: true # the person confirms what is filed
The pitfalls
- Idempotency is
$action.key, never$item.id.$item.idis the same for every customer who chooses that item: a tenant that deduplicates on it would give the second customer the first one's order, withok: true. Core does not refuse it. - A
role: billedoutput requires$action.key: without it, the retry after a total mismatch would file a second order (refused). line:reads only$line.ref,$line.quantity,$line.priceand$line.fields.<field>;$item.refis refused there. Its short form is onlyline: "$line.ref"(a list of ids).- Without
line:, each line leaves as{slug, qty}. A tenant that expectsquantityignoresqtyand orders 1 for a person who wanted 2, with no error. Writeline:from the tenant's schema. - Keep only what a call reads. An output nothing reads gives a note;
outputexists only on arequest. $submit.<field>must be in thesubmit_guard'sform: otherwise it isnull, and the tenant receives nothing, withok: true(refused).- A submit goes through a write. Through a
readoperation it is refused: it would file nothing, and the receipt would say otherwise. The write must also be granted to a profile. $intake.<field>is not a source: refused, it would leave as that text.- A
handoverknows only{tenant_url},{items}and{room}in itsurl. - The agent never submits. The person confirms; the agent says "filed" only once the receipt came back.
Reference: The submit, Outputs, The tenant's total.