// PART 11
Adding a new app or API
“Adding an app or API” in this codebase means one of three concrete things: a new feature crate with routes, a new REST endpoint on an existing surface, or a new suite app entry. This page walks through all three with the real mechanics — migrations, registration, catalog, tests.
Path A: a new feature crate
-
Create the crate under
botserver/crates/(e.g.botmyfeature/), with adescriptionin itsCargo.toml— that line is what the crate map documents. -
Add the feature to
botserver/Cargo.toml:myfeature = ["dep:botmyfeature", "botcore/myfeature"]and include it in a bundle (
all-apps,full, …) if it should compile into the default build. -
Schema — if the feature needs tables:
cd botserver # migrations/<next-version>-myfeature/up.sql diesel migration run && diesel print-schema # update botschema (feature-gated module), commit migration + botschema together -
Business logic —
pub async fn create_feature(state: &AppState, …) -> Result<NewFeature, Error>in the crate; nounwrap/expect/panic. -
Routes — expose a router (
routes*) and mount it from the host when the feature is enabled (main_module/routes/feature_routers/); handlers takeExtension<Arc<AppState>>+Jsonpayloads, sanitize errors, and check auth/authorization. -
Expose to the LLM — register the endpoint(s) in the API command catalog (method, path, params, returned JSON;
admin_only: truewhere appropriate). This is the only way chat/WhatsApp can reach the feature. UI-only features must appear inui_automation_instructions()(the app registry) for__ui_plan__. -
Seed demo data via
botsampledatawhen a fresh drive should work end-to-end.
Path B: a new endpoint on an existing surface
- Add the handler next to its siblings in the owning route module.
- Security checklist: input validation (
sanitize_identifier), auth required?, authorization checks?, rate limiting, sanitized errors, no panics. - Register in the command catalog if chat should answer with it; raw REST is not chat-reachable.
- Add to
bottest(or the owning crate’s tests).
Path C: a new suite app
- Registry entry —
AppSpecinbotserver/src/apps/registry/(entries.rsorentries_extra.rs):id,title,category,url,description,keywords, inline SVGicon. - UI — app directory
botui/ui/suite/<app>/:<app>.html+modules/01_state.js … 99_init.js(plain scripts,"use strict";, under 450 lines each), absolute asset paths, i18n keys in all catalogs,--id-*tokens only. - Visibility — list it in the relevant
.productprofile (apps=), or mark it always-visible in the registry when it must ignore profiles. - Commands — chat-callable operations become
AppCommandentries with verb-to-route bindings and consent classes (destructive verbs prompt).
BASIC keyword (optional step for any path)
If the feature is a chat-native primitive, add a keyword:
- implement in the matching
botbasic_*keyword crate (orbotserver/src/basic/keywords/for host-local glue); - bridge async → sync with an mpsc channel +
std::thread::spawn+tokio::runtime::Builder::new_current_thread().enable_all()+rt.block_on(...); - register with
engine.register_custom_syntax(...); log registration errors — never.expect(); - update the generated reference (
python3 scripts/gen_basic_reference.py) and note the keyword in the book.
Tests and delivery
cargo test -p botmyfeature # crate tests
cargo test -p bottest # integration
./restart.sh # restart with the new binary
# UAT in the browser: dialog, screenshots, per-criterion evidence
Commit split by area, push to ALM (CI builds and deploys), and update
botbook/ if user-facing behavior changed.