---
name: ringhi-app-development
description: Build, test, upload and submit RingHi apps (hosted scripts with bundled pages, Webhook services, or external web pages) with an expiring developer upload key. Use when creating or updating an app for the RingHi workspace, SMS, call or call-event platform.
---

# RingHi application development

This skill is served by the target RingHi platform. Use that same origin for every `/developer/` resource and API call, and never send the developer key to another origin.

Human-readable docs: `/developer/docs`. The Markdown sources below are the same content.

## 1. Pick the runtime

| Need | Runtime | Start from |
| --- | --- | --- |
| Small tool, no server: forward/react to SMS or calls, scheduled jobs, team records, a settings page | `runtime: "hosted"` + `ui.type: "bundled"` | [hello-hosted template](../examples/hello-hosted/README.md), [notify-forward](../examples/notify-forward/README.md) |
| Existing business system; call transcripts, call audio, or data that must stay on the developer's server | `runtime: "webhook"` | [Webhook guide](../guide.md), [guestbook](../examples/guestbook/README.md) |
| Existing mobile website opened inside RingHi, no platform actions | `runtime: "web"` | [web starter](../web-starter/README.md) |

Default to hosted unless the user's requirements need a server. Read [the platform guide](../app-platform.md) (permissions, runtimes, hosted SDK, Webhook tokens, identities, errors), [the Manifest reference](../manifest.md) and [pages](../pages.md) before writing code. Structural schema: [manifest.schema.json](../plugin-docs-v3/manifest.schema.json); the server enforces the cross-field rules listed in the Manifest reference.

## 2. Build

**Hosted script** (`main.js`, classic script, not an ES module). Top-level `onEvent(event)`, `onSchedule(schedule)` and an `actions` object; each action returns `{ text, data? }`. The only global is `ringhi` ([types](../hosted-sdk.d.ts)): `capability`, `sms`, `calls`, `fetch` (declared and allow-listed origins, or any public HTTPS with `network.custom`), `kv` (per installation, 1 MB), `log`. No `require`, `process`, timers or native `fetch`. Limits per run: 5 s, 32 MB, 10 fetches, 20 capability calls.

**Bundled page** (`pages/` folder): static files with `index.html` as entry, plus a copy of [app-ui-sdk.mjs](../app-ui-sdk.mjs). The page cannot use the network; it calls the script with `createAppUiClient().invoke(action, params)`. Declare `"confirm": false` only on actions that read or write the app's own data; the platform refuses device-changing capabilities inside them.

**Webhook service**: generate the app-level Webhook signing secret in **登录与凭据** (`POST /api/v1/developer/apps/:id/webhook-secret`), verify `X-SimHelper-Signature` over the raw body with [call-app-sdk.mjs](../call-app-sdk.mjs) `verifyEvent`, de-duplicate by `event.id`, isolate data by the signed `workspaceId` + `installationId`, answer within 8 s. Call platform capabilities through `POST /api/open/v1/apps/token` (signed with the app-level Webhook signing secret or OAuth client Basic auth; accepts `{installationId}` or `{appId, workspaceId}`) and `POST /api/open/v1/apps/actions/:capability` with an `idempotencyKey`.

Ask only for permissions the app uses. Put non-essential ones in `optionalPermissions` and degrade gracefully without them. Never log message text, phone numbers or secrets.

## 3. Test locally

- Hosted: run the script in Node's `vm` against a fake `ringhi`, as [hello-hosted/check.mjs](../examples/hello-hosted/check.mjs) does. Assert every declared action exists and returns `{ text, data }`.
- Webhook: test signature verification, duplicate events, workspace isolation, filtered outputs and timeouts with synthetic inputs.
- Pages: a plain browser has no Bridge; `ready()` times out by design. Real behaviour needs the RingHi App.

## 4. Upload

Prepare `app.json` next to the files:

```json
{ "name": "…", "description": "…", "iconPath": "icon.png", "manifestPath": "manifest.json",
  "scriptPath": "main.js", "pagesPath": "pages" }
```

`pagesPath` may be the page folder (the CLI zips it, skipping hidden files) or a `.zip`. For a new version of an existing app use `{ "appId": "developer.…", "manifestPath": …, "scriptPath": …, "pagesPath": … }` only: name, description and icon cannot change through a version upload (for an unpublished draft app, update metadata via `PATCH /api/v1/developer/apps/:id`).

```sh
node upload-app.mjs prepare app.json      # offline check, no key needed
node upload-app.mjs upload app.json       # needs RINGHI_DEVELOPER_KEY in the environment
```

Read the key from `RINGHI_DEVELOPER_KEY`. Never print it, put it in a URL, commit it, or copy it into a Manifest; it is different from a Webhook signing secret. The CLI derives a stable `requestId` from the payload: on a timeout, retry the same payload unchanged. The response gives the real app ID and integer version; never guess them. See [the developer API](references/api.md).

## 5. Hand over for real testing

An upload key cannot install apps, read user data or touch devices. Tell the developer to open `/developer`, choose the app and click **安装自用版本** (any workspace they own; no review, no allowlist, consent still required). Hosted apps, pure-page apps, and Webhook apps with an app-level signing secret start enabled unless a required setting has no default; the app appears in the RingHi App under **工作台**. A hosted self-use install switches versions in place and keeps its data.

For Webhook apps with `apps:test`, `POST …/versions/:v/test` sends a synthetic signed event using the app-level Webhook signing secret (returns `409 APP_WEBHOOK_SECRET_REQUIRED` if not generated yet).

## 6. Submit

Only when the user authorized it and the key has `apps:submit`: `node upload-app.mjs submit developer.<id> <version> --note "..."`. Pass `submissionNote` stating each sensitive permission's purpose, data destination, and hosted `network.origins`; for Webhook apps, the developer must first generate the app-level Webhook signing secret in **登录与凭据** (`409 APP_WEBHOOK_SECRET_REQUIRED` otherwise). Review stays blocked until the platform allow-lists every sensitive permission and hosted network origin. A key cannot approve or publish.

Report back: app ID, version, local test results, upload result, submission state, and what the developer still has to do on the phone.

## Failure handling

- `400`: Manifest or input invalid. The message names the rule; fix it and upload again (new content gets a new version).
- `401`: key invalid, expired or revoked. Do not fall back to a browser session or ask for passwords.
- `403`: missing scope, app outside the key's scope, or developer not approved.
- `409`: changed state, conflicting `requestId`, review blocked, or an installation conflict. Read the current state first; do not repeat a mutation with a new ID.
- `413`: script, page bundle or body too large. `429`: slow down.
- Network timeout: retry with the original `requestId` before creating anything new.
- Stop at unsupported capability boundaries; never claim an upload, test or publication that did not happen.

## Platform resource selection

Model and voice choices are controlled per application version by administrators. Render the filtered options the application catalog returns; do not reconstruct choices from the global model catalog. System configuration cannot be overridden by user configuration. See `references/api.md` → Application model and voice selection policy.
