Skip to content

feat: add order-notifier example app (Telegram alerts and webhooks) - #6

Merged
pronob1010 merged 3 commits into
mainfrom
feat/order-notifier-example
Oct 10, 2026
Merged

pronob1010 merged 3 commits into
mainfrom
feat/order-notifier-example

Conversation

@pronob1010

@pronob1010 pronob1010 commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

Adds order-notifier, a second example app: it subscribes to the order.created webhook on install and sends a Telegram alert for each new order.

What it shows

  • Subscribing to a webhook on install and verifying deliveries with readWebhook() (HMAC-SHA256 of the raw body, X-Webhook-Signature).
  • Reading the full order from the Store API (/api/v1/orders/{id}?include=orderGroup) instead of trusting the delivery body.
  • Secrets at rest: the Telegram bot token and the webhook secret are sealed with AES-256-GCM; the token can be written from the settings page but is never sent back (botTokenSet instead).
  • A settings page built with @flycommerce/ui, authenticated with the session token, per store.
  • Escaping store values (customer name, email) in the Telegram HTML message.

Running it

.env.example lists the variables (APP_ID, APP_SECRET, HUB_API_URL, APP_URL, ENCRYPTION_KEY). npm run dev runs it in the emulator; pressing Enter places an order and delivers order.created to the app.

Tests

15 tests (npm test), offline: install subscribes to order.created, a delivery reads the order and sends an escaped alert, the bot token is kept sealed and never returned, saving settings re-subscribes a store with no secret, Telegram refusals report delivered: false.

Not covered

  • No retries: a failed alert is not sent again.
  • On a multi-vendor checkout, one alert per vendor order.
  • Webhooks to apps reach real stores only once the app platform ships to production.

The repo's CI checks the PR title only; tests were run locally.

…der API

The app subscribed to `orders.create`, which the store and the emulator
refuse with a 422, and built the endpoint from an unset APP_URL. The
failure was caught and logged, so no store was ever subscribed; the tests
passed because they injected a webhook secret and hand-signed deliveries.

- Subscribe to `order.created` (APP_URL now required) and re-subscribe on
  save when a store has no secret.
- A delivery carries the stored record with no customer or currency, so
  read the order from /api/v1/orders/{id}?include=orderGroup as the app.
- Escape store values for Telegram's HTML mode; a name with & or < made
  Telegram refuse the whole alert.
- Never return the bot token to the page: GET answers botTokenSet, and a
  blank token on save keeps the saved one. Seal the webhook secret too.
- Report a Telegram refusal as delivered: false instead of true; pass the
  Telegram URL through createApp instead of process.env; time out at 10 s.
- Settings page: @flycommerce/ui Switch, Checkbox and FieldError.
- dev: grant webhooks.manage, set APP_URL, press Enter to place an order.
- Tests drive install and delivery through the emulator.
.env.example named FLYCOMMERCE_APP_ID and FLYCOMMERCE_APP_SECRET, which
the SDK doesn't read, and shipped a usable ENCRYPTION_KEY. Use the SDK's
variable names with an empty key and how to generate one, and rewrite the
README and AGENTS.md in order-export's form, with what the app doesn't do.
@pronob1010
pronob1010 merged commit bd43587 into main Oct 10, 2026
2 checks passed
@pronob1010
pronob1010 deleted the feat/order-notifier-example branch October 10, 2026 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant