// CONTENTS Part 11 · Extending and contributing

// PART 11

Adding a new app or API

Chapter 47 / 56 3 min read English Part 11 of 14

“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

  1. Create the crate under botserver/crates/ (e.g. botmyfeature/), with a description in its Cargo.toml — that line is what the crate map documents.

  2. 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.

  3. 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
    
  4. Business logic — pub async fn create_feature(state: &AppState, …) -> Result<NewFeature, Error> in the crate; no unwrap/expect/panic.

  5. Routes — expose a router (routes*) and mount it from the host when the feature is enabled (main_module/routes/feature_routers/); handlers take Extension<Arc<AppState>> + Json payloads, sanitize errors, and check auth/authorization.

  6. Expose to the LLM — register the endpoint(s) in the API command catalog (method, path, params, returned JSON; admin_only: true where appropriate). This is the only way chat/WhatsApp can reach the feature. UI-only features must appear in ui_automation_instructions() (the app registry) for __ui_plan__.

  7. Seed demo data via botsampledata when 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

  1. Registry entry — AppSpec in botserver/src/apps/registry/ (entries.rs or entries_extra.rs): id, title, category, url, description, keywords, inline SVG icon.
  2. 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.
  3. Visibility — list it in the relevant .product profile (apps=), or mark it always-visible in the registry when it must ignore profiles.
  4. Commands — chat-callable operations become AppCommand entries 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 (or botserver/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.

Found a mistake? Open an issue · All books

// SEARCH ESC
Pagefind · 236 pages · 4 books Enter to open ↑ ↓ to move