Skip to main content

Product · medium — a restaurant

The case. You choose dishes, a drink if you like, then pickup at the counter or delivery. The dishes, the drink and the cutlery leave in one order. Delivery asks for an address, checks that delivery is possible, computes a price. Pickup asks for nothing.

What the example shows. Three skills with kinds, dependencies between them, two kinds recognised by their when, one handled separately (kinds.pickup), a playbook whose last task is a choice (one_of: pickup or delivery), an order declared on the playbook for the lines of two tasks (the playbook's submit, $selection[task=plats,boisson]), lines nobody chooses (the cutlery, extra_lines), a side dish per dish (a line field, whose choices and their prices are read on the restaurant's menu), the kitchen's total compared with the one shown (role: billed), an irreversible write that runs last, idempotency, a confirmation before any submit, a phone number that identifies the room and is then proved with a code, and one of Convoy's sentences rewritten in the restaurant's words (texts), a station-wide policy tried in observe before it bites (policies, station.policies), and a daily budget per room (depense-du-jour).

product-medium.yaml
# Product · medium — a restaurant: dishes and a drink, then pickup OR delivery.
# Three skills, one dependency (no delivery for nothing), one kind that differs (pickup is free and
# asks nothing), one playbook whose last task is a choice — pickup or delivery —, ONE order for the
# lines of two tasks declared on the playbook, with the cutlery no one chooses, a confirmation
# before anything is filed, a station-wide policy tried in `observe` before it bites, and a daily
# budget per customer.
station:
id: teranga
name: Teranga Kitchen
identity:
providers:
sms: {mechanism: otp, verifies: phone, via: tenant, send: sendOtp, check: checkOtp}
policies: # for the whole station: `at` names the phase
- {policy: plat-raisonnable, at: submit}
- {policy: depense-du-jour, at: submit}

global:
language: fr # its default language
languages: [fr, en] # it speaks the visitor's when it is one of these
currency: XOF
locale: fr-SN

texts: # a sentence of Convoy, in the restaurant's words
fr:
submit.needs_method: "{task} : il reste à choisir {methods}."

domain:
domain_type: restaurant
entity_name: plat
entity_name_plural: plats


voice:
tone: friendly
persona: "un hôte chaleureux qui aide à composer le repas"
rules:
- "Ne jamais inventer un plat : uniquement ce que le menu renvoie."
- "Les prix sont en francs CFA (ex : 8 500 F CFA)."
- "Nous livrons à Dakar uniquement ; ailleurs, proposer le retrait au comptoir."

apis:
- name: cuisine
openapi_url: https://api.teranga.example.sn/openapi.json
base_url: https://api.teranga.example.sn
operations:
- {id: getMenu, access: read}
- {id: getDrinks, access: read}
- {id: placeOrder, access: write}
- {id: getDeliveryOptions, access: read}
- {id: checkDeliverable, access: read}
- {id: getDeliveryPrice, access: read}
- {id: createDelivery, access: write, reversible: false}
- {id: sendOtp, access: write}
- {id: checkOtp, access: write}
auth: {type: api_key, key_name: X-API-Key, key_location: header, key_env: TERANGA_KEY}

profiles:
tous:
when: "true"
grants:
- cuisine.getMenu
- cuisine.getDrinks
- cuisine.getDeliveryOptions
- cuisine.checkDeliverable
- cuisine.getDeliveryPrice
- cuisine.createDelivery
- cuisine.placeOrder

policies: # reusable, cited by name; one nobody cites is refused
plat-raisonnable:
require: "$item.price <= 50000"
when: "$item.kind == 'dish'" # the dishes only: a pickup has no price
mode: observe # tried on real traffic: journalled ("would have refused"), not applied
reason: "un plat au-delà de 50 000 F CFA se commande par téléphone"
depense-du-jour: # a budget: the dishes FILED, per room and per day (UTC); `identity` would ask for a sign-in
budget: {sum: "$item.price", per: day, scope: room, max: 60000} # a line: its price × its quantity
when: "$item.kind == 'dish'"

skills:
- name: takeMealSelection
cognitive:
objective: "montrer la carte pour choisir les plats"
diagnose: [l'envie du moment, les restrictions alimentaires]
invoke: {method: getMenu}
kinds:
dish:
fields: # filled by the person, line by line; required to submit, not to add
variante: {type: id, required: true, label: "Accompagnement", choices: "$fields.variantes"}
present:
fields:
name: {from: name, type: text, role: title}
price: {from: price, type: price, role: billed}
image: {from: image_url, type: image}
variantes: {from: variants, type: options, option_label: name} # the dish's own choices; a choice's price is added to the line's
render: {component: carousel} # no submit: the order is the playbook's call
- name: takeDrinkSelection
cognitive:
objective: "proposer une boisson pour accompagner les plats"
invoke: {method: getDrinks}
kinds: {drink: {}}
present:
fields:
name: {from: name, type: text, role: title}
price: {from: price, type: price, role: billed}
select: {max_items: 1} # one drink: another replaces it
depends_on: {takeMealSelection: {on_loss: clear}}
render: {component: carousel} # no submit either: the same order
- name: takeDeliveryOption
cognitive:
objective: "proposer le retrait ou la livraison"
invoke: {method: getDeliveryOptions}
kinds: # told by the row's `type`, a presented field
pickup:
when: "$fields.type == 'pickup'"
select: {quantity: {max: 1}} # no address, no check, no fee; collected once
submit: [{name: collect, mode: self}] # collected at the counter: filed, nothing dispatched
delivery:
when: "$fields.type == 'delivery'"
depends_on: {takeMealSelection: {on_loss: clear}} # no delivery for an empty order, and it leaves with the last dish
present:
fields:
name: {from: name, type: text, role: title}
type: {from: type, type: text}
select:
max_items: 1 # one option: choosing delivery replaces pickup
guards:
- form:
address: {type: text, required: true, label: "Adresse de livraison"}
phone: {type: phone, required: true, label: "Téléphone du livreur", identifies: true}
- check: checkDeliverable
- update: {price: getDeliveryPrice}
submit:
- name: dispatch
mode: request
tool: createDelivery
args:
body.address: "$item.fields.address"
body.phone: "$item.fields.phone"
body.items: "$selection[kind=dish]"
body.fee: "$item.price" # the amount the guard quoted
line: {slug: "$line.ref", quantity: "$line.quantity"}
render: {component: cards}

playbooks:
- name: take-meal-order
goal: "commander un repas : les plats, puis le retrait ou la livraison"
activation: {when: "true"}
tasks:
plats: {skill: takeMealSelection, label: "Vos plats"}
boisson: {skill: takeDrinkSelection, label: "Votre boisson", after: [plats], required: false}
remise:
label: "Retrait ou livraison"
after: [plats]
one_of: # two methods, one skill: each is one of its kinds
choose: customer # the person picks (the default)
methods:
retrait: {skill: takeDeliveryOption, kind: pickup, label: "Retrait sur place"}
livraison: {skill: takeDeliveryOption, kind: delivery, label: "Livraison"}
submit: # ONE order for the lines of two tasks, declared once
- name: order
tool: placeOrder
args:
body.items: "$selection[task=plats,boisson]"
body.idempotency_key: "$action.key" # a retry never orders twice
line: {slug: "$line.ref", quantity: "$line.quantity", variant_id: "$line.fields.variante"} # left out of a drink line: no `variante` there
output: {total: {from: "$output.items_total", type: price, role: billed}} # the kitchen's total, compared with the one shown
extra_lines: # sent with the order, never chosen: the cutlery, two 0 F products; `check` proves each ref at the tenant
- {ref: couverts-avec, check: getMenu, quantity: "$submit.couverts", when: "$submit.couverts > 0"}
- {ref: couverts-sans, check: getMenu, when: "$submit.couverts == 0"}

submit_guard:
form: {couverts: {type: quantity, required: true, label: "Combien de couverts ?"}}
confirm: true

What happens​

stepCoreresult
the agent shows the menua read opens no journeythe menu shows
a yassa addedfirst write with no journey open: take-meal-order, the only playbook with a task of takeMealSelection, declares activation and opens (first_write); task "Your dishes" done; the line field variante stays unanswered"take-meal-order is now open: its steps apply from this choice on"; the journey shows: "Your dishes", "Your drink", "Pickup or delivery"; total 8 500 F CFA; the line says its side dish is still to choose
the side dish chosen on the lineselection_fill, in the conversation (the card does not draw it yet): an id among the dish's variantsthe line keeps the id; the side dish's price is added to the dish's, and to the total
a bissap addedtask "Your drink" (optional), after: [plats] met; max_items: 1one drink only: another replaces it
the agent adds the delivery firstdepends_on: "Vos plats" is emptyrefused: "Rien n'est encore choisi dans « Vos plats », et « Retrait ou livraison » en dépend : choisissez d'abord dans « Vos plats »." (the station speaks French)
"Finalise"task "Pickup or delivery" (remise) required, empty; the sentence is the restaurant's (texts)refused: "Retrait ou livraison : il reste à choisir Retrait sur place ou Livraison."
pickup chosenthe row has type: pickup, so kinds.pickup, the retrait method: no form, no feeready
delivery chosen insteadselect.max_items: 1; step_open checks the selection without the pickup it replacesthe livraison method replaces retrait, and this is announced; address form, checkDeliverable, getDeliveryPrice
"Finalise", "2 cutlery"the submit form (couverts, of type quantity); getMenu read once: it lists couverts-avecthe line couverts-avec × 2 will leave with the order; "0" would send couverts-sans, "-1" is refused
"Finalise" with a dish without a side dishvariante is requiredheld, and so is the button: "… attend une réponse avant de partir : Accompagnement"
"Finalise" + confirmationthe playbook's call order: one placeOrder with the yassa (and its variant_id), the bissap and the cutlery; the kitchen answers its items_total, equal to the total shown; then createDelivery (reversible: false: after the others) with body.fee and the dishesorder placed, receipt in the room
the kitchen answers another items_totalrole: billed: its total is not the total of the lines senttotal_mismatch: the order is not confirmed, the sentence gives both totals; the receipt keeps the kitchen's answer, the dishes stay in the selection
the phone given for deliveryidentifies: true, written +221…the room keeps it; no form asks it again
"send me a code"send_verification_code → sendOtpthe restaurant sends a text; the model sees neither the number nor the code
the code typedcheck_verification_code → checkOtpnumber verified, the room belongs to the customer
the last dish removed (before the submit)depends_on: {takeMealSelection: {on_loss: clear}} on the drink and on the deliverythe drink and the delivery go with it
a dish added after the deliveryon_change not written: keepthe delivery stays, at the same price
"Finalise" with a dish above 50 000 F CFAplat-raisonnable, at: submit, mode: observe: it judges every dish the submit would sendallowed: nothing is refused; the journal keeps observe:plat-raisonnable(require) — what it would have refused
"Finalise" when the dishes already ordered today plus these go beyond 60 000 F CFAdepense-du-jour, at: submit: dishes only (when), price × quantity, per room, since 00:00 UTCheld: nothing is sent, the sentence names the dish that goes beyond
the order goes throughthe room's counter grows in the same transaction as the decisionwhat is left for the day goes down; if the kitchen files nothing, the amount is given back (release)

Key points​

  • kinds.pickup, with its guard-free select ({quantity: {max: 1}}: a pickup happens once — with no form, the line would have quantities) and its mode: self submit, is what prevents charging delivery to someone who comes to collect their meal.
  • The order is the playbook's call. order sends the lines of two tasks in one request: $selection[task=plats,boisson]. The dishes' and the drink's skills have no submit: inside the journey, their lines leave by that call only; chosen outside the journey, they are held (An order is declared on the playbook).
  • Nobody chooses the cutlery. It is two of the restaurant's products at 0 F. extra_lines adds them to the order from the answer to the submit form. Each ref is proved by check: getMenu: the provisioner looks for it in the restaurant's answer, and so does every submit. Absent, the station does not go live; gone later, the order is held, never sent without its cutlery (Lines sent without being chosen).
  • The side dish belongs to the dish, not to the order: it is a line field of the dish kind (kinds.dish.fields.variante), whose choices are the variants the menu gives for that dish (type: options, option_label: name). required holds the submit, never the add. The side dish's price is added to the dish's (Line fields).
  • The order is confirmed only at the total shown. output.total (role: billed) reads the kitchen's items_total; if it is not the total of the lines sent, the order is not announced as placed, and the kitchen's reference is kept (The tenant's total).
  • placeOrder sends each line in the shape line: {slug: "$line.ref", quantity: "$line.quantity", variant_id: "$line.fields.variante"}: the drink has no side dish, its variant_id key is left out. createDelivery sends the dishes as {slug, quantity}, in its own request. Without line:, Convoy would send qty, which the restaurant ignores: it would deliver one dish instead of two (The shape of a line).
  • createDelivery is declared reversible: false: it runs after placeOrder. A dish line is filed once both have sent it; if the delivery fails, a retry sends only createDelivery, never a second order.
  • body.fee: "$item.price" passes on the computed price. Without it, Core refuses the station: the customer would have seen an amount the restaurant does not receive.
  • remise is a one_of of two methods on one skill, each one of its kinds: only one does the task, and a selection that kept both could not be submitted. Each method's label ("Retrait sur place", "Livraison") is the word the person reads when the submit is locked or a line refused.
  • after: [plats] opens "Pickup or delivery" once the dishes are chosen, within the journey; depends_on on the skill holds the same dependency, even outside the journey.
  • The budget counts what is filed. depense-du-jour is cited in station.policies at submit: it adds up the dishes each submit would send, for this room and this day (UTC), and refuses beyond 60 000 F CFA. Pickup and cutlery do not count (when). scope: room counts each room on its own. scope: identity would count each signed-in person, and so would ask every customer to sign in before ordering (Budgets).
  • texts.fr.submit.needs_method replaces a single Convoy sentence, keeping its placeholders {task} and {methods}; the others stay Convoy's (The station's sentences).