Skip to content

[inbox] ordered batch webhooks#395

Open
capcom6 wants to merge 1 commit into
masterfrom
receiver/batch-webhooks
Open

[inbox] ordered batch webhooks#395
capcom6 wants to merge 1 commit into
masterfrom
receiver/batch-webhooks

Conversation

@capcom6

@capcom6 capcom6 commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features
    • Added webhook delivery modes: Disabled, Individual, and Batch.
    • Export requests and webhook events now use the new delivery mode configuration (legacy triggerWebhooks is deprecated).
    • Implemented batch webhook support with new SMS/MMS batch event types and corresponding payloads.
  • Bug Fixes
    • Prevent webhook payloads from being emitted for messages already marked as processed.
    • Updated webhook delivery-mode selection and emission behavior to follow the new precedence rules.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f28f2bd9-c378-4fd9-ba59-04dc8ab418cb

📥 Commits

Reviewing files that changed from the base of the PR and between 85dccf5 and 3f5aac4.

📒 Files selected for processing (13)
  • app/src/main/java/me/capcom/smsgateway/domain/WebhookDelivery.kt
  • app/src/main/java/me/capcom/smsgateway/modules/localserver/domain/InboxRefreshRequest.kt
  • app/src/main/java/me/capcom/smsgateway/modules/localserver/routes/InboxRoutes.kt
  • app/src/main/java/me/capcom/smsgateway/modules/localserver/routes/MessagesRoutes.kt
  • app/src/main/java/me/capcom/smsgateway/modules/receiver/EventsReceiver.kt
  • app/src/main/java/me/capcom/smsgateway/modules/receiver/ReceiverService.kt
  • app/src/main/java/me/capcom/smsgateway/modules/receiver/events/MessagesExportRequestedEvent.kt
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/domain/WebHookEvent.kt
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/payload/BatchEventPayload.kt
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/payload/MmsBatchDownloadedPayload.kt
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/payload/MmsBatchReceivedPayload.kt
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/payload/SmsBatchReceivedPayload.kt
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/payload/SmsDataBatchReceivedPayload.kt
🚧 Files skipped from review as they are similar to previous changes (13)
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/payload/BatchEventPayload.kt
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/payload/SmsBatchReceivedPayload.kt
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/payload/MmsBatchDownloadedPayload.kt
  • app/src/main/java/me/capcom/smsgateway/modules/localserver/routes/MessagesRoutes.kt
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/payload/SmsDataBatchReceivedPayload.kt
  • app/src/main/java/me/capcom/smsgateway/modules/receiver/events/MessagesExportRequestedEvent.kt
  • app/src/main/java/me/capcom/smsgateway/modules/receiver/EventsReceiver.kt
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/payload/MmsBatchReceivedPayload.kt
  • app/src/main/java/me/capcom/smsgateway/domain/WebhookDelivery.kt
  • app/src/main/java/me/capcom/smsgateway/modules/localserver/domain/InboxRefreshRequest.kt
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/domain/WebHookEvent.kt
  • app/src/main/java/me/capcom/smsgateway/modules/localserver/routes/InboxRoutes.kt
  • app/src/main/java/me/capcom/smsgateway/modules/receiver/ReceiverService.kt

Walkthrough

Introduces WebhookDelivery modes, updates export request/event models and route wiring to pass them through, and adds batch webhook event/payload types plus batch emission logic in ReceiverService.

Changes

Webhook delivery migration and batch emission

Layer / File(s) Summary
WebhookDelivery enum
app/src/main/java/me/capcom/smsgateway/domain/WebhookDelivery.kt
Defines Disabled, Individual, and Batch delivery modes with Gson names.
Batch webhook events and payloads
app/src/main/java/me/capcom/smsgateway/modules/webhooks/domain/WebHookEvent.kt, app/src/main/java/me/capcom/smsgateway/modules/webhooks/payload/BatchEventPayload.kt, app/src/main/java/me/capcom/smsgateway/modules/webhooks/payload/MmsBatchDownloadedPayload.kt, app/src/main/java/me/capcom/smsgateway/modules/webhooks/payload/MmsBatchReceivedPayload.kt, app/src/main/java/me/capcom/smsgateway/modules/webhooks/payload/SmsBatchReceivedPayload.kt, app/src/main/java/me/capcom/smsgateway/modules/webhooks/payload/SmsDataBatchReceivedPayload.kt
Adds batch webhook event constants and batch payload wrapper classes for SMS and MMS messages.
Models and callers adopt webhookDelivery
app/src/main/java/me/capcom/smsgateway/modules/localserver/domain/InboxRefreshRequest.kt, app/src/main/java/me/capcom/smsgateway/modules/receiver/events/MessagesExportRequestedEvent.kt, app/src/main/java/me/capcom/smsgateway/modules/localserver/routes/InboxRoutes.kt, app/src/main/java/me/capcom/smsgateway/modules/localserver/routes/MessagesRoutes.kt, app/src/main/java/me/capcom/smsgateway/modules/receiver/EventsReceiver.kt
Adds webhookDelivery fields, deprecates triggerWebhooks, and rewires callers to pass the new delivery mode with fallback mapping.
ReceiverService batch flow
app/src/main/java/me/capcom/smsgateway/modules/receiver/ReceiverService.kt
Changes export(...) to branch on delivery mode, moves payload construction into a helper, and adds batch webhook grouping and chunked emission.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and clearly points to the main change: inbox batch webhooks.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch receiver/batch-webhooks

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
app/src/main/java/me/capcom/smsgateway/modules/receiver/ReceiverService.kt (1)

100-119: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

"message processed" log now fires even for skipped duplicates.

process() no longer early-returns when saveAndBuildPayload returns null (duplicate message); the trailing "ReceiverService::process - message processed" DEBUG log is now always logged, even though the message was actually skipped as a duplicate a few lines earlier (with its own "duplicate message, skipping" log). This makes debug logs misleading when diagnosing duplicate-detection behavior.

🩹 Proposed fix
         val payload = saveAndBuildPayload(context, message)
 
         if (payload != null && triggerWebhooks) {
             webHooksService.emit(context, payload.first, payload.second)
         }
 
-        logsService.insert(
-            LogEntry.Priority.DEBUG,
-            MODULE_NAME,
-            "ReceiverService::process - message processed",
-        )
+        if (payload != null) {
+            logsService.insert(
+                LogEntry.Priority.DEBUG,
+                MODULE_NAME,
+                "ReceiverService::process - message processed",
+            )
+        }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/src/main/java/me/capcom/smsgateway/modules/receiver/ReceiverService.kt`
around lines 100 - 119, In ReceiverService::process, the trailing "message
processed" DEBUG log is being emitted even when saveAndBuildPayload returns null
for a duplicate and the message is skipped. Update the control flow so the
method returns immediately after the duplicate/null case (or otherwise guards
the final log) and only logs "ReceiverService::process - message processed"
after a payload has actually been built and any webhook emission path has
completed.
🧹 Nitpick comments (3)
app/src/main/java/me/capcom/smsgateway/modules/receiver/events/MessagesExportRequestedEvent.kt (1)

49-51: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicate fallback-resolution logic across files.

The exact same webhookDelivery ?: (triggerWebhooks==false → Disabled) ?: Individual chain is duplicated in MessagesRoutes.kt's inboxRoutes() handler (per the provided cross-file snippet). Per the PR stack, this same pattern is likely also needed in EventsReceiver.kt and InboxRoutes.kt. Consider extracting this into a shared helper (e.g., a companion function on WebhookDelivery or an extension) to avoid the two implementations drifting apart during future changes.

♻️ Example extraction
// in WebhookDelivery.kt
companion object {
    fun resolve(webhookDelivery: WebhookDelivery?, triggerWebhooks: Boolean?): WebhookDelivery =
        webhookDelivery
            ?: (if (triggerWebhooks == false) Disabled else null)
            ?: Individual
}
-                webhookDelivery = obj.webhookDelivery
-                    ?: (if (obj.triggerWebhooks == false) WebhookDelivery.Disabled else null)
-                    ?: WebhookDelivery.Individual,
+                webhookDelivery = WebhookDelivery.resolve(obj.webhookDelivery, obj.triggerWebhooks),
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@app/src/main/java/me/capcom/smsgateway/modules/receiver/events/MessagesExportRequestedEvent.kt`
around lines 49 - 51, The webhook delivery fallback chain is duplicated across
MessagesExportRequestedEvent and the matching handlers in
MessagesRoutes/inboxRoutes, with likely copies in EventsReceiver and
InboxRoutes, so extract the resolution logic into a shared helper on
WebhookDelivery (for example a companion resolver or extension) and update all
call sites to use it. Keep the behavior identical to the current chain: prefer
the explicit webhookDelivery, otherwise map triggerWebhooks == false to
Disabled, otherwise default to Individual, so future changes stay in sync.
app/src/main/java/me/capcom/smsgateway/modules/webhooks/domain/WebHookEvent.kt (1)

27-29: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Minor naming/ordering inconsistency for SmsDataBatchReceived.

For the other pairs, the enum member name mirrors the serialized value's word order (SmsBatchReceived"sms:batch:received", MmsBatchReceived"mms:batch:received", MmsBatchDownloaded"mms:batch:downloaded"). Here the member is SmsDataBatchReceived (Data before Batch) but the value is "sms:batch:data-received" (Batch before Data). Purely cosmetic since Gson matches on @SerializedName, but worth aligning for readability/consistency.

✏️ Optional rename for consistency
-    `@SerializedName`("sms:batch:data-received")
-    SmsDataBatchReceived("sms:batch:data-received"),
+    `@SerializedName`("sms:batch:data-received")
+    SmsBatchDataReceived("sms:batch:data-received"),

Note: this requires updating all references (e.g., ReceiverService.emitBatchWebhooks, SmsDataBatchReceivedPayload) if renamed.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@app/src/main/java/me/capcom/smsgateway/modules/webhooks/domain/WebHookEvent.kt`
around lines 27 - 29, The `SmsDataBatchReceived` enum entry in `WebHookEvent`
has a naming/ordering mismatch with the other webhook event constants. Rename
the enum member to match the serialized word order used by the other entries,
and update any references such as `ReceiverService.emitBatchWebhooks` and
`SmsDataBatchReceivedPayload` if you choose to rename it. Keep the
`@SerializedName("sms:batch:data-received")` mapping unchanged so Gson behavior
stays the same.
app/src/main/java/me/capcom/smsgateway/modules/receiver/ReceiverService.kt (1)

197-246: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Two parallel when mappings must stay in sync; second one silently drops on mismatch.

eventType -> batchEvent logs a WARN for unsupported types, but the second when (batchEvent) that builds the actual payload has an unreachable else -> return@forEachIndexed with no logging. If a new batchable event is ever added to the first mapping without a matching branch in the second, its payloads will be silently dropped instead of surfacing a WARN like the first mapping does. Consider consolidating into a single mapping (e.g., a function/map keyed by WebHookEvent returning both the batch event and a (List<Any>) -> Any constructor) or at least add the same WARN logging to the second else branch for symmetry.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/src/main/java/me/capcom/smsgateway/modules/receiver/ReceiverService.kt`
around lines 197 - 246, The batching logic in ReceiverService::emitBatchWebhooks
has two separate when mappings that can drift apart, and the second one
currently drops unmatched batch events silently. Update the payload construction
path so it stays in sync with the eventType -> batchEvent mapping, either by
consolidating both into one mapping/helper or by adding WARN logging in the
batchEvent when else branch before returning. Keep the same unique symbols
(emitBatchWebhooks, WebHookEvent, webHooksService.emit, logsService.insert) to
ensure any future new batchable event surfaces an explicit warning instead of
disappearing.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/src/main/java/me/capcom/smsgateway/modules/receiver/ReceiverService.kt`:
- Around line 76-90: In ReceiverService.process, Batch mode currently saves the
entire messages window before any webhook job is emitted, which can permanently
skip remaining webhooks if the process stops mid-flight. Refactor the Batch
branch to process smaller chunks sequentially so each chunk is saved and emitted
before moving to the next, using the existing saveAndBuildPayload and
emitBatchWebhooks flow to limit the blast radius.

---

Outside diff comments:
In `@app/src/main/java/me/capcom/smsgateway/modules/receiver/ReceiverService.kt`:
- Around line 100-119: In ReceiverService::process, the trailing "message
processed" DEBUG log is being emitted even when saveAndBuildPayload returns null
for a duplicate and the message is skipped. Update the control flow so the
method returns immediately after the duplicate/null case (or otherwise guards
the final log) and only logs "ReceiverService::process - message processed"
after a payload has actually been built and any webhook emission path has
completed.

---

Nitpick comments:
In
`@app/src/main/java/me/capcom/smsgateway/modules/receiver/events/MessagesExportRequestedEvent.kt`:
- Around line 49-51: The webhook delivery fallback chain is duplicated across
MessagesExportRequestedEvent and the matching handlers in
MessagesRoutes/inboxRoutes, with likely copies in EventsReceiver and
InboxRoutes, so extract the resolution logic into a shared helper on
WebhookDelivery (for example a companion resolver or extension) and update all
call sites to use it. Keep the behavior identical to the current chain: prefer
the explicit webhookDelivery, otherwise map triggerWebhooks == false to
Disabled, otherwise default to Individual, so future changes stay in sync.

In `@app/src/main/java/me/capcom/smsgateway/modules/receiver/ReceiverService.kt`:
- Around line 197-246: The batching logic in ReceiverService::emitBatchWebhooks
has two separate when mappings that can drift apart, and the second one
currently drops unmatched batch events silently. Update the payload construction
path so it stays in sync with the eventType -> batchEvent mapping, either by
consolidating both into one mapping/helper or by adding WARN logging in the
batchEvent when else branch before returning. Keep the same unique symbols
(emitBatchWebhooks, WebHookEvent, webHooksService.emit, logsService.insert) to
ensure any future new batchable event surfaces an explicit warning instead of
disappearing.

In
`@app/src/main/java/me/capcom/smsgateway/modules/webhooks/domain/WebHookEvent.kt`:
- Around line 27-29: The `SmsDataBatchReceived` enum entry in `WebHookEvent` has
a naming/ordering mismatch with the other webhook event constants. Rename the
enum member to match the serialized word order used by the other entries, and
update any references such as `ReceiverService.emitBatchWebhooks` and
`SmsDataBatchReceivedPayload` if you choose to rename it. Keep the
`@SerializedName("sms:batch:data-received")` mapping unchanged so Gson behavior
stays the same.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8e95f3d5-5da1-4b06-a406-0d830f3c4325

📥 Commits

Reviewing files that changed from the base of the PR and between abe8f76 and c04ae09.

📒 Files selected for processing (13)
  • app/src/main/java/me/capcom/smsgateway/domain/WebhookDelivery.kt
  • app/src/main/java/me/capcom/smsgateway/modules/localserver/domain/InboxRefreshRequest.kt
  • app/src/main/java/me/capcom/smsgateway/modules/localserver/routes/InboxRoutes.kt
  • app/src/main/java/me/capcom/smsgateway/modules/localserver/routes/MessagesRoutes.kt
  • app/src/main/java/me/capcom/smsgateway/modules/receiver/EventsReceiver.kt
  • app/src/main/java/me/capcom/smsgateway/modules/receiver/ReceiverService.kt
  • app/src/main/java/me/capcom/smsgateway/modules/receiver/events/MessagesExportRequestedEvent.kt
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/domain/WebHookEvent.kt
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/payload/BatchEventPayload.kt
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/payload/MmsBatchDownloadedPayload.kt
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/payload/MmsBatchReceivedPayload.kt
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/payload/SmsBatchReceivedPayload.kt
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/payload/SmsDataBatchReceivedPayload.kt

@capcom6 capcom6 force-pushed the receiver/batch-webhooks branch from bdef998 to 85dccf5 Compare July 1, 2026 05:20
@capcom6 capcom6 marked this pull request as ready for review July 2, 2026 03:15
@capcom6 capcom6 added the ready label Jul 2, 2026
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

🤖 Pull request artifacts

file commit
app-release.apk 3f5aac4
app-release.aab 3f5aac4
app-insecure.apk 3f5aac4
app-insecure.aab 3f5aac4

@capcom6 capcom6 force-pushed the receiver/batch-webhooks branch from 85dccf5 to 3f5aac4 Compare July 8, 2026 01:22
@github-actions github-actions Bot removed the ready label Jul 8, 2026
@capcom6 capcom6 added the ready label Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant