Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@
- Webhook URLs, Twilio status callbacks, signed file links and the webhook raw-body capture follow `api.rest.prefix`. With a custom prefix every webhook used to fail the signature check.
- Outgoing texts are never cut inside an emoji.
- `Retry-After` given as an HTTP date is honoured (capped at 24 hours).
- WhatsApp template messages send `language.policy: "deterministic"`, which Meta's official OpenAPI requires.

### Documentation

- `docs/audits/2026-11-20-provider-apis.md`: audit of all four provider APIs against their official specs and docs.
- `docs/contract-tests.md` and `docs/live-tests.md`: what the contract and live suites prove, the pinned sources, the defects found in the official specs, and the credential keys per provider.

### Tests

- Contract tests (`tests/contract-*.test.js`, part of `npm test`, offline): every adapter request validated against the provider's pinned official spec (Meta `facebook/openapi`, Twilio `twilio-oai`, seven.io `api-schemes`, Telegram Bot API tables), the specs' examples fed back through adapters and webhook handlers, and Twilio's own signature test vector. `npm run contract:specs` rebuilds the pinned specs; `-- --check` reports upstream changes.
- Opt-in live suites (`npm run test:live`, never in CI): Telegram, Twilio (test credentials and magic numbers), Meta (test number) and seven.io, with credentials only from `~/.config/magic-messagegate-live/.env` (mode 600); paid sends, webhook changes and interactive steps each need their own switch, and webhook end-to-end runs use a cloudflared tunnel and restore what they change.

## [1.1.2](https://github.com/Schero94/Magic-MessageGate/compare/messagegate-v1.1.1...messagegate-v1.1.2) (2026-11-18)

Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -484,12 +484,17 @@ Details are in the [changelog](https://github.com/Schero94/Magic-MessageGate/blo
```bash
npm ci
npm run lint && npm run format:check
npm test # unit tests, provider contract tests with local fakes, 8 processes on SQLite
npm test # unit tests, contract tests against the providers' official specs, 8 processes on SQLite
npm run test:pg # 8 processes on PostgreSQL (set MG_TEST_PG_URL)
npm run test:admin # admin entry points in React StrictMode
npm run test:live # opt-in: real Meta, Twilio, seven.io and Telegram APIs (your own credentials)
npm run build && npm run verify
```

**Provider contracts.** Every adapter request is checked offline against the provider's own pinned specification: Meta's official WhatsApp OpenAPI, Twilio's `twilio-oai`, seven.io's `api-schemes`, and the Telegram Bot API tables (Telegram publishes no OpenAPI). The specs' examples are fed back through the adapters and webhook handlers. Sources, pins and the defects found in the official specs: [docs/contract-tests.md](https://github.com/Schero94/Magic-MessageGate/blob/main/docs/contract-tests.md). The provider audit behind them: [docs/audits/2026-11-20-provider-apis.md](https://github.com/Schero94/Magic-MessageGate/blob/main/docs/audits/2026-11-20-provider-apis.md).

**Live tests.** `npm run test:live` uses safe modes where providers offer them (Twilio test credentials and magic numbers, the Meta test number, your own Telegram chat) and only spends money or changes webhooks with explicit switches. Keys, switches and the webhook end-to-end runs through a cloudflared tunnel: [docs/live-tests.md](https://github.com/Schero94/Magic-MessageGate/blob/main/docs/live-tests.md).

`npm run test:admin` renders every admin entry point (the seven sections of the plugin page, the template editor, the homepage widget, and the message, send, contact, number check and account dialogs) inside `React.StrictMode` with the providers of the Strapi admin, in jsdom with a fake network. It fails on a mutation sent twice, a read repeated without aborting the first one, an interval, listener, connection or observer left after unmount, and any console error or warning. A separate CI job runs the same tests against React 19 for information only: the plugin's peer range is React 18, like the Strapi 5 admin.

Issues and pull requests are welcome at [github.com/Schero94/Magic-MessageGate](https://github.com/Schero94/Magic-MessageGate/issues). See [CONTRIBUTING.md](https://github.com/Schero94/Magic-MessageGate/blob/main/CONTRIBUTING.md) for the checks, the 8-process acceptance run and releases; the design decisions are in [CONCEPT.md](https://github.com/Schero94/Magic-MessageGate/blob/main/CONCEPT.md).
Expand Down
43 changes: 43 additions & 0 deletions docs/contract-tests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Contract tests against the providers' official specs

`npm test` runs `tests/contract-meta.test.js`, `tests/contract-twilio.test.js`, `tests/contract-seven.test.js` and `tests/contract-telegram.test.js`. They need no network and no credentials: every adapter request is captured in memory and checked against the provider's own specification, and the specs' own examples are fed back through the adapters and webhook handlers.

## What is pinned

`tests/contract/specs/` holds the parts of the official specifications that MessageGate uses (the operations it calls and every component they reference). `npm run contract:specs` rebuilds them; `npm run contract:specs -- --check` exits with 1 when an upstream source changed. Both need network and are run by a maintainer, not by CI.

| File | Source | Machine-readable | Pinned by |
| --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------- | --------------------------------- |
| `meta.json` | [facebook/openapi](https://github.com/facebook/openapi) `business-messaging-api_v23.0.yaml` | yes (OpenAPI 3.1) | commit + sha256 |
| `twilio_api.json`, `twilio_lookups.json`, `twilio_content.json` | [twilio/twilio-oai](https://github.com/twilio/twilio-oai) `spec/json/` | yes (OpenAPI 3.0) | tag 2.11.1 commit + sha256 |
| `seven.json` | [seven-io/api-schemes](https://github.com/seven-io/api-schemes) `json/openapi.json` ("Official API Schemes for seven.io") | yes (OpenAPI 3.0) | commit + sha256 |
| `seven-webhooks.json` | JSON examples on [docs.seven.io/en/rest-api/webhooks](https://docs.seven.io/en/rest-api/webhooks) | no, extracted from the page | snapshot |
| `telegram.json` | method and type tables of [core.telegram.org/bots/api](https://core.telegram.org/bots/api), converted to JSON Schema | no: Telegram publishes no OpenAPI | snapshot (Bot API version inside) |
| `twilio-webhooks.json` | parameter lists on Twilio's [webhook request](https://www.twilio.com/docs/messaging/guides/webhook-request) and [status callback](https://www.twilio.com/docs/messaging/guides/track-outbound-message-status) pages | no, copied by hand (sources and date inside) | not machine-checked |

`tests/contract/validator.js` is a small JSON Schema validator without dependencies. It reads `allOf` the way OpenAPI generators do (members merged before validation); strict JSON Schema would reject every Meta message, see below.

## What each suite proves

| Provider | Requests | Responses | Webhooks |
| -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| Meta | every body MessageGate builds (template, text, image, document, video, reply buttons) and templates rendered by the template engine (text/document headers, named and positional parameters, URL, quick reply and copy-code buttons) are valid `Message`s; template submit body; documented query fields | the spec's send examples, phone number info, error examples (`META_<code>`), template list examples, media download flow | spec-valid payloads (text, button reply, status) pass the signature check and are stored; a changed byte gives 401; every documented status is mapped |
| Twilio | SMS (number or Messaging Service), RCS text with media, RCS Content template: only documented form fields, typed per spec; Lookup `Fields` value; Content API rich card | 201 example → Message SID; account example; Lookup examples → line type; Content create example | every parameter the handler reads is on Twilio's lists; the signature matches Twilio's own test vector from twilio-node |
| seven.io | SMS form fields, the documented 1520-character limit, `foreign_id` pattern; HLR query | SmsResponse, balance, HLR (with the `roaming` object) | the official `dlr` and `sms_mo` examples, signed as the signing page describes, are processed; a forged signature gives 401 |
| Telegram | `sendMessage` (plain and with inline keyboard), `sendPhoto`, `sendDocument`, `getFile`, `answerCallbackQuery`, `setWebhook`: only documented parameters; the secret token follows the documented rules | `Message`, `File`, `ResponseParameters` (429 `retry_after`) | `Update`s with `/start` linking, text, photo, location and `callback_query` are processed; a wrong secret gives 401 |

Contract tests prove that MessageGate speaks the documented protocol. They do not prove that a provider behaves as documented; that is what the [live tests](./live-tests.md) are for.

## Known defects in the official specs

The tests ignore these errors (and only these). Each one contradicts the provider's own reference pages.

| Spec | Defect | Evidence |
| -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| Meta | `TemplateComponent.index` has the pattern `^[2-6, 11-14]$` (a character class), while its description says "Position index of the button (0-9)" and its example is `"0"`. | spec text |
| Meta | `TemplateComponent.sub_type` lists `quick_reply`, `url`, `catalog`, but copy-code buttons are sent with `sub_type: "copy_code"`. | [copy code button templates](https://developers.facebook.com/docs/whatsapp/business-management-api/message-templates/copy-code-button-templates) |
| Meta | Incoming webhook messages (`IncomingMessage` → `TextMessage`, `InteractiveMessageReply`, …) extend the outgoing `BaseMessageProperties` (required `messaging_product`, `recipient_type`, `to`; no `from`, `id`, `timestamp`), so no real webhook message validates. The tests validate the envelope and each message's type part (`text`, `interactive`, …) separately. | [webhook messages reference](https://developers.facebook.com/documentation/business-messaging/whatsapp/webhooks/reference/messages) |
| Meta | The spec requires `template.language.policy`. MessageGate now sends `"deterministic"` (its only value) to match. | spec text |
| Twilio | `twilio/card` has `additionalProperties: false` without `body`, which Twilio documents for RCS (up to 1600 characters). | [twilio/card](https://www.twilio.com/docs/content/twiliocard) |
| Twilio | Lookup v2 response fields are declared without `nullable`, but the spec's own examples (and the API, for every data package not requested) return `null`. | spec examples |
| seven.io | The official `sms_mo` example's sender `49176123456789` has one digit too many for a German mobile number; the test uses a valid synthetic number. | libphonenumber |
Loading