Skip to content

[inbox] add refresh options#224

Open
capcom6 wants to merge 1 commit intomasterfrom
inbox/refresh-options
Open

[inbox] add refresh options#224
capcom6 wants to merge 1 commit intomasterfrom
inbox/refresh-options

Conversation

@capcom6
Copy link
Copy Markdown
Member

@capcom6 capcom6 commented Apr 21, 2026

Summary by CodeRabbit

  • New Features

    • Inbox refresh endpoint is now operational: accepts device, since/until, optional message-type filtering and explicit webhook-trigger control; validates input and returns 202 Accepted on success.
  • Deprecations

    • Legacy messages export endpoint marked deprecated and now returns an explicit Deprecation response header.
  • Documentation

    • OpenAPI/docs updated to reflect the new request shape, removed legacy export operation, and document webhook-trigger behavior.
  • Chores

    • Updated a client dependency version.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 21, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

Implements a working inbox refresh endpoint that parses smsgateway.InboxRefreshRequest, validates input, calls the inbox service with optional message-type filters and a webhook-trigger flag, updates event payload construction, deprecates the old inbox export endpoint, updates OpenAPI, and bumps the client-go dependency.

Changes

Inbox Refresh Flow

Layer / File(s) Summary
OpenAPI definitions & path contract
internal/sms-gateway/openapi/docs.go
Replace MessagesExportRequest with InboxRefreshRequest (adds optional messageTypes, triggerWebhooks); update POST /3rdparty/v1/inbox/refresh parameter/description/202 response and remove POST /3rdparty/v1/messages/inbox/export.
Handler (docs/import)
internal/sms-gateway/handlers/inbox/3rdparty.go
Add smsgateway import; update Swagger annotations for POST /3rdparty/v1/inbox/refresh to reference InboxRefreshRequest, describe triggerWebhooks, and add 202 response.
Handler (implementation)
internal/sms-gateway/handlers/inbox/3rdparty.go
refresh(userID string, c *fiber.Ctx) parses and validates smsgateway.InboxRefreshRequest, calls h.inboxSvc.Refresh(..., messageTypes, &triggerWebhooks), and returns 400/500/202 accordingly.
Deprecated handler change
internal/sms-gateway/handlers/messages/3rdparty.go
postInboxExport marked deprecated, adds Deprecation: true header, and invokes inboxSvc.Refresh constrained to IncomingMessageTypeSMS with lo.ToPtr(true); error return handling simplified.
Service API & wiring
internal/sms-gateway/inbox/service.go
Refresh signature extended to accept types []smsgateway.IncomingMessageType and triggerWebhooks *bool; forwards these into events.NewMessagesExportRequestedEvent and notifies events service.
Event construction
internal/sms-gateway/modules/events/events.go
NewMessagesExportRequestedEvent signature extended; builds a map[string]string payload with RFC3339 since/until, optional messageTypes list, and optional triggerWebhooks, then calls NewEvent.

Dependency

Layer / File(s) Summary
Go module
go.mod
Bumped github.com/android-sms-gateway/client-go from v1.12.5 to v1.12.7-0.20260508050135-17a184bc31e9.

Sequence Diagram

sequenceDiagram
    participant Client as HTTP Client
    participant Handler as Inbox Handler
    participant Service as Inbox Service
    participant Events as Events Service

    Client->>Handler: POST /3rdparty/v1/inbox/refresh (InboxRefreshRequest)
    Handler->>Handler: Parse & validate request
    alt invalid
        Handler-->>Client: 400 Bad Request
    else valid
        Handler->>Service: Refresh(userID, deviceID, since, until, types, triggerWebhooks)
        Service->>Events: NewMessagesExportRequestedEvent(...) / Notify(event)
        alt event/service error
            Handler-->>Client: 500 Internal Server Error
        else success
            Handler-->>Client: 202 Accepted
        end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 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 '[inbox] add refresh options' clearly and concisely summarizes the main change across the pull request files—adding optional parameters (messageTypes and triggerWebhooks) to the inbox refresh functionality.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 21, 2026

🤖 Pull request artifacts

Platform File
🐳 Docker GitHub Container Registry
🍎 Darwin arm64 server_Darwin_arm64.tar.gz
🍎 Darwin x86_64 server_Darwin_x86_64.tar.gz
🐧 Linux arm64 server_Linux_arm64.tar.gz
🐧 Linux i386 server_Linux_i386.tar.gz
🐧 Linux x86_64 server_Linux_x86_64.tar.gz
🪟 Windows arm64 server_Windows_arm64.zip
🪟 Windows i386 server_Windows_i386.zip
🪟 Windows x86_64 server_Windows_x86_64.zip

@capcom6
Copy link
Copy Markdown
Member Author

capcom6 commented Apr 22, 2026

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 22, 2026

✅ Actions performed

Full review triggered.

@capcom6 capcom6 force-pushed the inbox/refresh-options branch from 7b40c8e to ce152da Compare April 22, 2026 11:58
@coderabbitai coderabbitai Bot added the codex label Apr 22, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

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

⚠️ Outside diff range comments (1)
internal/sms-gateway/handlers/inbox/3rdparty.go (1)

66-79: ⚠️ Potential issue | 🟡 Minor

Sync the refresh docs with the implemented behavior.

The handler now honors triggerWebhooks and returns 202 from SendStatus, but the docs still say webhooks are never triggered, advertise an object response, and include a 501 that this handler no longer returns.

Suggested annotation cleanup
-//	`@Description`	Refreshes inbox messages. Webhooks will not be triggered.
+//	`@Description`	Refreshes inbox messages. Webhooks are triggered when triggerWebhooks is true.
...
-//	`@Success`		202		{object}	object							"Inbox refresh request accepted"
+//	`@Success`		202												"Inbox refresh request accepted"
...
-//	`@Failure`		501		{object}	smsgateway.ErrorResponse		"Not implemented"

Also applies to: 89-100

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/sms-gateway/handlers/inbox/3rdparty.go` around lines 66 - 79, Update
the Swagger annotations for the inbox refresh handler to match current behavior:
remove the note "Webhooks will not be triggered" and instead document that the
request honors the triggerWebhooks flag; change the `@Success` 202 response to
reflect the actual returned type (no object if SendStatus returns an empty body)
and remove the obsolete `@Failure` 501 entry; apply the same annotation edits to
the other duplicate block (lines ~89-100) so both Swagger comment blocks for
this handler match the implemented SendStatus and triggerWebhooks behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@internal/sms-gateway/handlers/messages/3rdparty.go`:
- Around line 245-247: The postInboxExport handler is documented as deprecated
but lacks a Swagger `@Router` annotation so the OpenAPI spec omits
/3rdparty/v1/messages/inbox/export; update the comment block for the
postInboxExport function to include a Swagger `@Router` line for the endpoint
(e.g. `@Router` /3rdparty/v1/messages/inbox/export [post]) and mark it deprecated
(add `@Deprecated` or include the deprecation note in the doc block consistent
with other handlers) so the generated spec includes the path; alternatively, if
you prefer removal, unregister the route where postInboxExport is registered
instead of adding the annotation.

In `@internal/sms-gateway/modules/events/events.go`:
- Around line 28-40: The current manual string-building of messageTypes using
strings.Builder with values from types can produce invalid JSON if any value
contains quotes or backslashes; update the code that constructs
data["messageTypes"] (the block using strings.Builder and the variable types) to
safely quote values—for example, replace the manual quoting with strconv.Quote
on each t or marshal the []string to JSON (using encoding/json) and assign the
resulting safe string to data["messageTypes"]; ensure you import strconv or
encoding/json and handle any marshal/quote errors appropriately.

---

Outside diff comments:
In `@internal/sms-gateway/handlers/inbox/3rdparty.go`:
- Around line 66-79: Update the Swagger annotations for the inbox refresh
handler to match current behavior: remove the note "Webhooks will not be
triggered" and instead document that the request honors the triggerWebhooks
flag; change the `@Success` 202 response to reflect the actual returned type (no
object if SendStatus returns an empty body) and remove the obsolete `@Failure` 501
entry; apply the same annotation edits to the other duplicate block (lines
~89-100) so both Swagger comment blocks for this handler match the implemented
SendStatus and triggerWebhooks behavior.
🪄 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: e5381ade-ebc5-4ae0-9e2d-606c961a6662

📥 Commits

Reviewing files that changed from the base of the PR and between 3146a92 and ce152da.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (6)
  • go.mod
  • internal/sms-gateway/handlers/inbox/3rdparty.go
  • internal/sms-gateway/handlers/messages/3rdparty.go
  • internal/sms-gateway/inbox/service.go
  • internal/sms-gateway/modules/events/events.go
  • internal/sms-gateway/openapi/docs.go

Comment thread internal/sms-gateway/handlers/messages/3rdparty.go
Comment thread internal/sms-gateway/modules/events/events.go
@coderabbitai coderabbitai Bot added the ready label Apr 23, 2026
@capcom6 capcom6 force-pushed the inbox/refresh-options branch from c221995 to 8c2c92c Compare April 24, 2026 02:16
@github-actions github-actions Bot removed the ready label Apr 24, 2026
@capcom6 capcom6 added the ready label Apr 24, 2026
@capcom6 capcom6 force-pushed the inbox/refresh-options branch from 8c2c92c to 7c684c3 Compare April 28, 2026 01:04
@github-actions github-actions Bot removed the ready label Apr 28, 2026
@capcom6 capcom6 added the ready label Apr 28, 2026
@capcom6 capcom6 force-pushed the inbox/refresh-options branch from 7c684c3 to ac8cf49 Compare April 30, 2026 01:05
@github-actions github-actions Bot removed the ready label Apr 30, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
internal/sms-gateway/handlers/messages/3rdparty.go (1)

246-249: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Deprecated endpoint is still live but undocumented in Swagger/OpenAPI.

postInboxExport remains reachable (see Line 317 route registration), but this block no longer contributes a documented route, so generated clients lose visibility while the server still accepts calls.

#!/bin/bash
# Verify route is registered but no swagger router annotation exists for it.
rg -n 'router\.Post\("inbox/export"' internal/sms-gateway/handlers/messages/3rdparty.go
rg -n '@Router\s+/3rdparty/v1/messages/inbox/export' internal/sms-gateway/handlers/messages/3rdparty.go internal/sms-gateway/openapi/docs.go

Expected result: first command returns a match; second returns none. If confirmed, either re-document as deprecated or remove the route in the same release.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/sms-gateway/handlers/messages/3rdparty.go` around lines 246 - 249,
postInboxExport is a deprecated but still-registered endpoint that isn't present
in the OpenAPI docs; either document it as deprecated or remove its
registration. Fix by locating the route registration that wires postInboxExport
(the router.Post("inbox/export", ...) call) and either (A) add proper
Swagger/OpenAPI annotations for the handler function postInboxExport (include
`@Summary`, `@Description` noting deprecated, `@Tags`, and `@Router` + method/path and
mark as deprecated) so generated clients see it, or (B) remove the
router.Post("inbox/export", ...) registration and any references to
postInboxExport so the endpoint is no longer reachable; ensure corresponding
tests and usages are updated accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@internal/sms-gateway/handlers/inbox/3rdparty.go`:
- Around line 88-95: The handler forwards req.MessageTypes directly to
h.inboxSvc.Refresh which means missing/empty messageTypes from clients causes no
filtering; change the handler to default messageTypes to SMS at the boundary:
before calling h.inboxSvc.Refresh, create a local variable (e.g., messageTypes)
= req.MessageTypes and if nil/len==0 set it to the SMS default, then pass that
variable into h.inboxSvc.Refresh instead of req.MessageTypes so downstream
services and event constructors always receive the API-defaulted value.

---

Duplicate comments:
In `@internal/sms-gateway/handlers/messages/3rdparty.go`:
- Around line 246-249: postInboxExport is a deprecated but still-registered
endpoint that isn't present in the OpenAPI docs; either document it as
deprecated or remove its registration. Fix by locating the route registration
that wires postInboxExport (the router.Post("inbox/export", ...) call) and
either (A) add proper Swagger/OpenAPI annotations for the handler function
postInboxExport (include `@Summary`, `@Description` noting deprecated, `@Tags`, and
`@Router` + method/path and mark as deprecated) so generated clients see it, or
(B) remove the router.Post("inbox/export", ...) registration and any references
to postInboxExport so the endpoint is no longer reachable; ensure corresponding
tests and usages are updated accordingly.
🪄 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: 05590014-bc06-48a4-9d31-4487eac7e04b

📥 Commits

Reviewing files that changed from the base of the PR and between c221995 and ac8cf49.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (6)
  • go.mod
  • internal/sms-gateway/handlers/inbox/3rdparty.go
  • internal/sms-gateway/handlers/messages/3rdparty.go
  • internal/sms-gateway/inbox/service.go
  • internal/sms-gateway/modules/events/events.go
  • internal/sms-gateway/openapi/docs.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • go.mod
  • internal/sms-gateway/modules/events/events.go

Comment thread internal/sms-gateway/handlers/inbox/3rdparty.go
@capcom6 capcom6 added the ready label Apr 30, 2026
@github-actions github-actions Bot removed the ready label May 6, 2026
@capcom6 capcom6 force-pushed the inbox/refresh-options branch 2 times, most recently from 5bacef9 to b9f9cd4 Compare May 7, 2026 06:26
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 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 `@internal/sms-gateway/openapi/docs.go`:
- Around line 1609-1633: The field descriptions for the auto-generated docs
still use "export" wording from MessagesExportRequest; update the source Go
struct comment/tags for smsgateway.InboxRefreshRequest (the struct and its
fields DeviceID, MessageTypes, Since, TriggerWebhooks, Until) to replace
"export"/"exported" with "refresh"/"refreshed" and adjust phrases (e.g., "to
refresh messages for", "message types to refresh", "time range to refresh", "for
the refreshed messages"), then re-run swaggo generation to regenerate
internal/sms-gateway/openapi/docs.go so the docs reflect the corrected "refresh"
wording.
- Around line 1622-1635: The generated OpenAPI is missing "format":"date-time"
for the time-range fields; update the swag annotations on the
InboxRefreshRequest struct fields InboxRefreshRequest.Since and
InboxRefreshRequest.Until to include the date-time format tag (e.g. add
format:"date-time" to their swagger/swag struct tags or the equivalent swag
annotation) so the generator emits "format":"date-time" for both fields.
🪄 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: 0e6e9bc5-037a-466c-ba9c-38b3f380de75

📥 Commits

Reviewing files that changed from the base of the PR and between edb5177 and b9f9cd4.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (6)
  • go.mod
  • internal/sms-gateway/handlers/inbox/3rdparty.go
  • internal/sms-gateway/handlers/messages/3rdparty.go
  • internal/sms-gateway/inbox/service.go
  • internal/sms-gateway/modules/events/events.go
  • internal/sms-gateway/openapi/docs.go
✅ Files skipped from review due to trivial changes (1)
  • go.mod
🚧 Files skipped from review as they are similar to previous changes (4)
  • internal/sms-gateway/modules/events/events.go
  • internal/sms-gateway/handlers/messages/3rdparty.go
  • internal/sms-gateway/handlers/inbox/3rdparty.go
  • internal/sms-gateway/inbox/service.go

Comment thread internal/sms-gateway/openapi/docs.go Outdated
Comment thread internal/sms-gateway/openapi/docs.go
@capcom6 capcom6 force-pushed the inbox/refresh-options branch from 767dfa3 to 88251d6 Compare May 9, 2026 02:09
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
go.mod (1)

7-7: ⚡ Quick win

Consider using the stable v1.12.6 release instead of a pseudo-version.

The dependency uses a pseudo-version (v1.12.7-0.20260508050135-17a184bc31e9) rather than an official tagged release. The latest stable release available is v1.12.6 (published May 6, 2026), which is only 2 days older than this pseudo-version. If the specific commit isn't required for a critical fix, using the tagged release would improve stability and align with standard Go dependency practices.

🤖 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 `@go.mod` at line 7, Replace the pseudo-version dependency entry for
github.com/android-sms-gateway/client-go (currently
"v1.12.7-0.20260508050135-17a184bc31e9") in go.mod with the official tagged
release "v1.12.6"; update the module line to use
github.com/android-sms-gateway/client-go v1.12.6 and run "go mod tidy" (or "go
get github.com/android-sms-gateway/client-go@v1.12.6") to ensure the lockfile
and go.sum are updated.
🤖 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.

Nitpick comments:
In `@go.mod`:
- Line 7: Replace the pseudo-version dependency entry for
github.com/android-sms-gateway/client-go (currently
"v1.12.7-0.20260508050135-17a184bc31e9") in go.mod with the official tagged
release "v1.12.6"; update the module line to use
github.com/android-sms-gateway/client-go v1.12.6 and run "go mod tidy" (or "go
get github.com/android-sms-gateway/client-go@v1.12.6") to ensure the lockfile
and go.sum are updated.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 075ba42a-bb05-4294-a6c8-fdd656e03216

📥 Commits

Reviewing files that changed from the base of the PR and between b9f9cd4 and 88251d6.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (6)
  • go.mod
  • internal/sms-gateway/handlers/inbox/3rdparty.go
  • internal/sms-gateway/handlers/messages/3rdparty.go
  • internal/sms-gateway/inbox/service.go
  • internal/sms-gateway/modules/events/events.go
  • internal/sms-gateway/openapi/docs.go
🚧 Files skipped from review as they are similar to previous changes (5)
  • internal/sms-gateway/modules/events/events.go
  • internal/sms-gateway/inbox/service.go
  • internal/sms-gateway/handlers/inbox/3rdparty.go
  • internal/sms-gateway/handlers/messages/3rdparty.go
  • internal/sms-gateway/openapi/docs.go

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