Skip to main content

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​

  1. Write submit on the skill (or on a kind): a list of named calls, run in order.
  2. Choose the mode: request (Convoy calls tool, an access: write operation), handover (the person finishes on the tenant's site, through url) or self (nothing is sent).
  3. Write the args: $selection[kind=<kind>] (the lines), $item.fields.<field>, $item.price, $item.ref, $params.<name>, $submit.<field>, $action.key.
  4. Give the shape of a line with line:, in the tenant's keys: {product_id: "$line.ref", quantity: "$line.quantity"}.
  5. Keep what another call reads in output ({from: "$output.<path>", type: …}); the tenant's total with role: billed, which Core compares with the lines.
  6. Write the submit_guard: confirm: true (the person confirms), a form read through $submit.<field>, and submitted_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.id is 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, with ok: true. Core does not refuse it.
  • A role: billed output 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.price and $line.fields.<field>; $item.ref is refused there. Its short form is only line: "$line.ref" (a list of ids).
  • Without line:, each line leaves as {slug, qty}. A tenant that expects quantity ignores qty and orders 1 for a person who wanted 2, with no error. Write line: from the tenant's schema.
  • Keep only what a call reads. An output nothing reads gives a note; output exists only on a request.
  • $submit.<field> must be in the submit_guard's form: otherwise it is null, and the tenant receives nothing, with ok: true (refused).
  • A submit goes through a write. Through a read operation 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 handover knows only {tenant_url}, {items} and {room} in its url.
  • 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.