Repository navigation
feat(modules): add the AhaSend email provider - #345
jeroenrinzema wants to merge 8 commits into
Conversation
923f9cd to
f501fd7
Compare
There was a problem hiding this comment.
🟡 Changes recommended
AhaSend events lack InboxMessageID, causing even correctly signed callbacks to be acknowledged with HTTP 200 but silently skipped instead of published.
1 open issue
What changed in this PR
Adds AhaSend as a WASM email provider, extending Lunogram’s integrations with transactional email sending and webhook handling. Signature verification depends on the raw-body preservation change in #344.
Changes:
- Implements email request mapping, idempotent sends, retry classification, and signed webhook parsing.
- Adds provider tests, build configuration, setup documentation, and discovery links.
- Removes the root Makefile’s forced
GOGC=offsetting.
| File | Description |
|---|---|
| modules/README.md | Lists AhaSend among available providers. |
| modules/ahasend/README.md | Documents configuration and development. |
| modules/ahasend/Makefile | Adds the WASM build target. |
| modules/ahasend/main.go | Exports provider configuration, sending, validation, and webhook handling. |
| modules/ahasend/main_test.go | Tests request mapping, responses, validation, events, and signatures. |
| modules/ahasend/go.sum | Records dependency checksums. |
| modules/ahasend/go.mod | Defines module dependencies and the local SDK reference. |
| modules/ahasend/ahasend.go | Implements request mapping and response classification. |
| modules/ahasend/ahasend_webhook.go | Maps webhook events and verifies signatures. |
| Makefile | Stops disabling garbage collection for Go commands. |
| docs/content/docs/integrations/smtp.mdx | Adds AhaSend as an HTTP-provider alternative. |
| docs/content/docs/integrations/meta.json | Adds AhaSend to documentation navigation. |
| docs/content/docs/integrations/index.mdx | Adds the AhaSend integration card. |
| docs/content/docs/integrations/ahasend.mdx | Documents setup, webhooks, and troubleshooting. |
Review effort: Balanced
There was a problem hiding this comment.
🟡 Changes recommended
Webhook events can be permanently lost because callbacks arriving before correlation records exist are acknowledged and discarded, and transient failures to persist those records have no durable retry.
2 open issues
1 resolved since last review
Review effort: Balanced
There was a problem hiding this comment.
🟡 Changes recommended
Storage failures bypass configured retry backoff, risking exhaustion of all 20 mapping deliveries during a brief database outage and leaving accepted sends without automatically recoverable correlation rows.
1 open issue
3 resolved since last review
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
Human assessment is needed to evaluate redelivery risks that can duplicate event counts and journey triggers, as well as the loss of original occurrence timestamps.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
- Sends through AhaSend's Create Conversation Message endpoint, which carries cc and bcc and runs no substitutions over rendered content. - Passes the inbox message ID as the Idempotency-Key so a redelivered send replays the stored result. - Maps AhaSend message webhooks to provider events and verifies their Standard Webhooks signatures. - Exports use //go:wasmexport: under //go:export, crypto/sha256 panics in TinyGo for lack of a current goroutine. - Documents setup in docs/content/docs/integrations/ahasend.mdx.
- AhaSend webhooks carry neither tags nor custom headers and AhaSend regenerates Message-ID, so they cannot echo the inbox message ID back; every event was acknowledged and then dropped for lacking one. - Sends through modules that accept webhooks now record the provider's message ID against the user or organization inbox message in provider_messages. Mappings cascade with the message. - The webhook handler resolves an event's MessageID through that mapping when the module returned no InboxMessageID. - Recording failures are logged, not returned: the message has already been sent and redelivering the dispatch would send it again.
- No stream covered providers.webhooks.*, so every correlated webhook event failed to publish ('no response from stream') and the endpoint answered 500.
- A providers stream and a providers-webhooks consumer now take those events. The consumer resolves MessageID through provider_messages when the module returned no inbox message ID, loads the inbox message, and publishes the provider event (provider.delivered, provider.bounced, ...) as an event of its user or organization.
- A webhook can arrive before the send recorded its message ID, so the webhook handler publishes unresolved events too and the consumer redelivers them along DefaultBackOff (about 13 minutes) before dropping them.
- A failure to record the provider message ID now fails the dispatch so it is redelivered, as a failure to mark the message sent does. AhaSend replays the original send for the repeated idempotency key.
… webhooks - Dispatch no longer records the provider message ID inline. It publishes a ProviderMessageSent onto the providers stream, and the providers-messages consumer records it with JetStream retries. A failed record no longer redelivers the dispatch, which for a message without external_id created a new inbox row and with it a new idempotency key. - Handlers can return RetryAfter to have the router NAK with a delay. The providers-webhooks consumer uses it to wait for an unresolved provider message ID along DefaultBackOff, independent of how the server treats a plain NAK. - Provider webhook data is forwarded under provider_data, as the WebhookEvent contract promises, without overwriting the inbox message fields.
- WithDelayedRetry redelivers a transient failure after the DefaultBackOff delay for its delivery count, instead of the router's immediate NAK. Both provider consumers use it, so a short database outage cannot use up their deliveries. Permanent and rate-limited errors keep their own handling.
3407839 to
289c1bb
Compare
- The webhook endpoint gives each event a content-derived ID and publishes it with that Msg-Id; the providers stream keeps a 1h duplicates window, covering AhaSend's ~16 minute retry schedule. A provider retrying a webhook is recorded once. - The providers-webhooks consumer publishes the user or organization event with a Msg-Id derived from the same ID, so a redelivery after the publish is not recorded twice. - UserEvent and OrganizationEvent take an optional OccurredAt, stored as created_at. Provider events use the provider's timestamp; a missing, unparsable or future one records the event as now.
…he AhaSend webhook URL - The Twilio module stamped each event with its receipt time, so a retried callback hashed to a new ID and was recorded again. It now leaves Timestamp empty and the host records the event at receipt; the WebhookEvent contract says so. - The console shows no provider webhook URL, so the AhaSend docs give its format and where to find the project and provider IDs.
There was a problem hiding this comment.
🔵 Needs a closer look
Human assessment is needed to judge whether omitted provider event flows and retry/drop behavior in the architecture documentation materially hinder webhook troubleshooting.
No open issues 🎉
2 resolved since last review
Review effort: Balanced



Why: Lunogram has no AhaSend integration. AhaSend is a transactional email service that keeps message data in the EU.
How: A new
modules/ahasendWASM provider, built the same way as Mailgun.POST /v2/accounts/{account_id}/messages/conversationwith a Bearer API key. The conversation endpoint is used instead of Create Message because it supports cc and bcc and runs no substitutions over content Lunogram has already rendered. The inbox message ID is sent asIdempotency-Key, so a redelivered send replays AhaSend's stored result instead of sending again. 409, 429 and 5xx responses are retried; other 4xx responses fail permanently.message.*events map to provider events: reception → sent, transient_error → deferred, bounced and failed → bounced, suppressed → dropped, plus delivered, opened, clicked, complained and unsubscribed. WhenwebhookSecretis set, the Standard Webhooks HMAC is checked with the secret's literal bytes, as AhaSend requires. The user registers the webhook in the AhaSend dashboard, so the API key only needsmessages:send:{domain}.//go:wasmexport. Under//go:export, TinyGo runs exports without a current goroutine, andcrypto/sha256nil-panics on its FIPS indicator. Because of that,main.gois//go:build tinygo, and the rest of the module tests under plaingo test.Scope:
modules/ahasend, a new integration docs page, and the provider lists. It also includes the platform changes AhaSend webhooks need (below). Non-goal: registering the webhook through AhaSend's API, which would need thewebhooks:writescope.Verification
go test ./...inmodules/ahasendcovers request mapping, cc copies in the response, config validation, status classification, every event mapping, and signature acceptance and rejection for wrong secret, tampered body, stale timestamp and missing headers.status=401 {"message":"invalid API key"}and was classified as permanent. No send was made with a real account.Provider webhook pipeline
AhaSend webhooks can't echo the inbox message ID back: they have no tags or custom headers, and AhaSend regenerates
Message-ID. On top of that, no JetStream stream coveredproviders.webhooks.*, so on main every correlated provider webhook event, Resend's and Twilio's included, failed to publish (nats: no response from stream) and the endpoint answered 500.sequenceDiagram participant D as inbox dispatch participant S as providers stream participant M as providers-messages participant W as webhook endpoint participant H as providers-webhooks participant E as user/org events D->>S: ProviderMessageSent (provider msg ID to inbox msg) S->>M: record in provider_messages W->>S: ProviderWebhookEvent (inbox ID or provider msg ID) S->>H: resolve via provider_messages H-->>S: not recorded yet: NakWithDelay (DefaultBackOff, 6 deliveries) H->>E: provider.delivered, provider.bounced, ... with provider_dataprovider_messages(subjects DB) maps (project, provider, provider message ID) to a user or organization inbox message. Rows cascade with the message.WithDelayedRetry/RetryAfter: the two provider consumers back off between retries instead of getting the router's immediate NAK.Nats-Msg-Id(1h duplicates window on the providers stream), so a webhook the provider retries is recorded once. The user/org event reuses that ID as its Msg-Id, which covers JetStream redeliveries.UserEvent/OrganizationEventtake an optionalOccurredAt, stored ascreated_at. Provider events use the provider's timestamp; a missing, unparsable or future timestamp falls back to now.Evidence
TestProviderMessages(store): resolves user/org mappings, a replayed ID keeps its first mapping, lookups are scoped by project and provider, and mappings cascade on user delete.TestProviderWebhooks(consumer): resolves a recorded ID, uses an echoed inbox ID, delays unresolved events byDefaultBackOff[n-1]and drops them on the last delivery, rejects cross-project IDs, and keepsprovider_datafrom overwritingmessage_id.TestProviderWebhookEventID(retries keep their ID, distinct events don't share one) andTestInsertUserEventOccurredAt;TestProviderWebhooksalso checks that the provider timestamp is kept and that unusable timestamps fall back to now.TestWithDelayedRetry, plusTestBootstrapCreatesAllConsumersfor the new consumers.Merge Danger
Door: two-way, apart from the new
provider_messagestable (migration1784800000, with a down migration).Blast Radius: provider webhooks. Correlated Resend/Twilio events now get published and become
provider.*user/org events (they used to 500), so rules and journeys can start seeing them.