Skip to content

Historical draft — adapter developer guide

Historical unmerged draft. This guide is from the older refactor/core-boundaries branch at commit 258f50c; it is not the current Core contract and may omit later work. Use the current Core reference first.

Status: developer guide and design work in progress, not a production adapter SDK. Core is currently internal Ruby code in a Rails monolith, not a gem, a separate service or a public HTTP API. There is no stable transport interface, adapter registration API, production dispatch API or production worker. You cannot currently build an independent adapter against Core and have NotiFi safely deliver real messages through it. This guide distinguishes the existing read-only integration point from a proposed transport boundary and records the missing decisions.

This document assumes the refactor/core-boundaries changes are included: experimental delivery code lives in DeliveryTesting, outside Core. Until that change is merged, the corresponding experiment is under Core instead. No external service is contacted by the examples below.

  • Product (for example Visitor, or a future unrelated product): authenticates and authorizes the operation, selects relevant resources, chooses channel and product policies, and communicates the result to the user. An adapter must not depend on Visitor’s incident or visit concepts.
  • Core: owns reusable recipient selection and, once implemented, durable dispatch, selection snapshots, logical deliveries, attempt scheduling, idempotency and outcome history. It should depend on a channel-neutral contract, not concrete adapter classes, HTTP status codes or SMS vendors.
  • Channel/adapter: owns destination validation/normalization where applicable, transport-specific request construction, network timeouts, provider authentication, interpretation of responses, and provider-specific callback verification and reconciliation. How a production adapter is configured and injected remains undecided.
  • Composition and operations: a trusted composition root supplies the implementation to Core. Production isolation, secrets, worker configuration and availability remain deployment concerns; a request’s tenant ID alone is not authority to configure or operate an adapter.

DeliveryTesting is an experiment, not the production Core contract. It currently references specific SMS test adapters, accepts phone-shaped addresses, and enforces a test database mode. Do not copy its class checks or its internal table names as a production plugin interface.

The only current Core boundary suitable for a channel collaborator is the read-only recipient preview. Given a selection already authorized by the product, Core::RecipientPreview.call accepts a callable normalizer and a policy. For each Core::RecipientSelection::Entry, the callable returns a Core::RecipientPreview::Assessment with:

Field Current expectation
status :valid, :invalid or :needs_review.
destination A nonempty string for a valid result; otherwise absent.
reason A symbol for an invalid/review result; otherwise absent.
version Normalization metadata supplied by the normalizer.

Example using a synthetic normalizer; this runs no HTTP or SMS transport:

# The product has authenticated, authorized tenant/resources and obtained
# `selection` through Core::RecipientSelection inside TenantContext.
assessment = ->(entry) do
Core::RecipientPreview::Assessment.new(
status: :valid,
destination: "synthetic-destination-#{entry.recipient_id}",
reason: nil,
version: "example-v1"
)
end
preview = Core::RecipientPreview.call(
selection: selection,
policy: :per_destination,
normalizer: assessment
)

This demonstrates dependency injection only; it is not webhook validation and does not authorize or send a message. The other implemented policy is :per_recipient. The result retains one entry per selected resource link and exposes potential groups and issues; it is a point-in-time read, not a frozen snapshot, delivery or promise that a recipient can be reached. See recipient preview for precise invariants and security for tenant and transaction requirements.

The current selection entry contains telephone-specific phone and phone_input_region fields. It is not a general webhook endpoint or multi-channel contact model. The injected normalizer therefore proves only the boundary of the preview calculation, not that any new channel can be integrated end-to-end. Existing SMS-specific behavior is in Channels::Sms::PreviewNormalizer and Channels::Sms::PhoneNumber.

Proposed transport boundary — not implemented

Section titled “Proposed transport boundary — not implemented”

A future adapter should receive an immutable, authorized delivery input and return a channel-neutral observation. Exact names, serialization, versioning, registration, capabilities, credentials and timeout configuration are not agreed or implemented. This sketch is conceptual, not executable Ruby or an API promise:

Core worker -> adapter.submit(delivery input) -> transport observation

The boundary needs to specify at least:

  • channel and destination identity; immutable content, encoding and limits;
  • a stable logical-delivery ID and idempotency key, plus a distinct attempt ID;
  • credential/configuration references, tenant authorization and secret handling;
  • timeout/deadline and cancellation behavior;
  • accepted, definitely rejected, known-safe temporary failure and ambiguous outcomes, including optional provider reference and retry guidance;
  • mapping of receipts/callbacks to a delivery, including authenticity, replay/deduplication and out-of-order observations;
  • a versioned test suite for adapter implementations and contract evolution.

Do not treat an HTTP 2xx as delivery to a person: it confirms only whatever the destination’s documented response contract establishes. Likewise, an adapter result is not committed history until Core persists it. The precise state machine and mapping from provider observations into Core state remain open.

The adapter implements connection and response deadlines and interprets what it can actually know from its transport. The future Core worker is expected to own attempt state and retry scheduling using that observation and explicit policy; this responsibility split is an intended design, not an implemented production contract. An adapter must not quietly create independent retry loops that Core cannot observe.

If a request may have reached the remote service but its response is lost, record an indeterminate observation rather than claiming success or a safe failure. Do not blindly retry it. A known pre-acceptance temporary failure may be retryable, subject to the eventual policy. A stable idempotency key only prevents duplicates when the receiver actually supports and honors it. See the proposed uncertainty ADR and dispatch design; neither constitutes a production API.

Webhook adapter: questions before implementation

Section titled “Webhook adapter: questions before implementation”

A real webhook adapter would make an actual HTTP request to an endpoint; it is not the existing local SMS simulation. Before treating one as production-ready, define and test:

  1. Whether the endpoint represents a recipient, an organization integration, or a destination for an event; this determines grouping and what a delivery means. Define payload, event types, versioning and privacy explicitly.
  2. Who may configure or activate an endpoint; tenant-scoped configuration, credential storage/rotation, authentication or signing, and auditability.
  3. URL and network policy, including DNS resolution and redirects, so an endpoint cannot reach unintended internal services. Resolve how policy is enforced at connection time and rechecked for redirects/rebinding.
  4. Request/response size limits, connection and read deadlines, TLS, accepted status codes, idempotency headers and semantics for ambiguous outcomes.
  5. Isolation of sensitive payloads from application logs and test fixtures, retention, monitoring and operational recovery.

These are unresolved engineering requirements, not a claim that the current app enforces them. An externally hosted endpoint must only receive data under an explicitly authorized integration configuration. Use synthetic data when exercising a development endpoint.

An adapter implementation should be exercised using a controlled local service or transport double, not a real provider or third-party endpoint in automated tests. At minimum test successful response and provider reference, permanent rejection, safe pre-send failure, ambiguous timeout after a receiver accepts a request, malformed responses, configured deadlines, size limits and idempotency. For webhook transports also test authentication/signatures and the URL/network policy, including redirects and DNS changes. Verify sensitive values do not appear in logs.

Integration tests must cover tenant authorization and isolation, transaction commit/rollback, concurrent workers, crash/restart between submission and outcome recording, safe retries versus uncertain outcomes, and no duplicate logical dispatch on a repeated command. Callback processing needs independent verification for authenticity, repeated and out-of-order events. A passed transport unit test does not establish a durable or secure dispatch pipeline.

The existing development SMS adapter persists local simulated results and intentionally makes no network request. It is useful for experiments, not a webhook adapter and not a template for accessing Core’s test database tables from a future provider adapter.

Work still needed before an independent integration

Section titled “Work still needed before an independent integration”
  • A channel-neutral destination/contact model and product authorization for it.
  • Versioned production adapter input/output, registration and configuration.
  • Durable atomic dispatch creation, snapshot and delivery associations, with a channel-neutral idempotency scope and documented concurrency semantics.
  • A production worker with tenant-safe discovery, leases/recovery and bounded retry behavior; the current pollers are test infrastructure.
  • Provider observations, reconciliation, callback authentication and a durable audit/retention model. A provider acceptance is not end-user delivery.
  • Operational security, secret management, network policy and observability.
  • A separate distribution boundary and/or authenticated external API if an independent developer is expected to integrate without this Rails codebase.

Until these are designed, implemented and verified, this guide supports review and experimentation, not a promise that real incident messages can be sent.