Skip to content

[CSM] add GET /conversations/{id}/messages endpoint - #1034

Merged
cloby99 merged 6 commits into
wso2-open-operations:v2from
Rashmika998:feat/entity-service-conversation-messages
Jul 3, 2026
Merged

cloby99 merged 6 commits into
wso2-open-operations:v2from
Rashmika998:feat/entity-service-conversation-messages

Conversation

@Rashmika998

@Rashmika998 Rashmika998 commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Entity-service: Adds GET /conversations/{id}/messages backed by ServiceNow. The service calls POST /comments/search on the Choreo integration API with referenceType=conversation, maps snComment responses to ConversationMessage domain types (with sysid ↔ UUID conversion), and returns a paginated result. Optional limit and offset query parameters are parsed and validated in the handler layer.
  • CSM portal BFF: Adds GET /conversations/{id}/messages that validates the UUID path param and forwards the raw query string directly to the entity service. The entity client appends the query string to the path. Route registered in main.go, documented in openapi.yaml and README.md.

Test plan

  • go test ./... passes in both entity-service/ and apps/csm-portal/backend/
  • TestGetConversationMessages covers: unauthenticated, empty ID, non-UUID ID, query forwarding, 200 response shape, and full upstream error table
  • GET /conversations/{id}/messages?limit=10&offset=0 returns messages from the SN integration service for a valid conversation ID

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added a new conversation messages endpoint to view paginated message histories.
    • Supports limit and offset paging, with clearer response data including totals and “has more” state.
    • Available only when connected to the ServiceNow data source.
  • Bug Fixes

    • Added request validation for conversation IDs and pagination values.
    • Improved error handling for unauthorized and invalid requests.

Rashmika998 and others added 2 commits July 3, 2026 19:31
Implement conversation messages retrieval via ServiceNow integration:
- domain: ConversationMessage, GetConversationMessagesRequest/Response types
- service: ConversationService interface; snConversationService calls
  POST /comments/search with referenceType=conversation on the Choreo API
- handler: ConversationHandler reads limit/offset from query params
- routes: register GET /conversations/{id}/messages (SN data source only)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Wire the new entity-service conversation messages endpoint into the CSM
portal BFF:
- entity client: GetConversationMessages forwards conversationID + raw
  query string to GET /conversations/{id}/messages on the entity service
- handler: ConversationHandler validates UUID path param, passes query
  string through, maps upstream errors
- route: GET /conversations/{id}/messages registered in main.go
- openapi.yaml: document path with ConversationMessage schema
- README: add Conversations section

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@Rashmika998, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 31 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7df79066-3cc0-4d2a-b51b-fccbb51a0da2

📥 Commits

Reviewing files that changed from the base of the PR and between 2bed79f and cab5790.

📒 Files selected for processing (12)
  • apps/csm-portal/backend/internal/entity/entity.go
  • apps/csm-portal/backend/internal/handler/cases.go
  • apps/csm-portal/backend/internal/handler/cases_test.go
  • apps/csm-portal/backend/internal/handler/conversations.go
  • apps/csm-portal/backend/internal/handler/conversations_test.go
  • apps/csm-portal/backend/internal/handler/helpers_test.go
  • entity-service/internal/domain/entity.go
  • entity-service/internal/handler/comment_handler.go
  • entity-service/internal/server/routes.go
  • entity-service/internal/service/interfaces.go
  • entity-service/internal/service/sn_comment_service.go
  • entity-service/openapi.yaml
📝 Walkthrough

Walkthrough

Adds a new GET /conversations/{id}/messages endpoint. entity-service implements a ServiceNow-backed ConversationService fetching and mapping comments with pagination, conditionally routed for ServiceNow data source. csm-portal backend adds an entity client method and a proxying handler validating UUID/auth, plus tests and documentation updates.

Changes

Conversation Messages Feature

Layer / File(s) Summary
Domain types and ServiceNow service
entity-service/internal/domain/entity.go, entity-service/internal/service/sn_conversation_service.go, entity-service/internal/service/interfaces.go
New ConversationMessage, request/response domain types, ConversationService interface, and snConversationService implementation calling ServiceNow /comments/search with pagination and UUID mapping.
entity-service handler and routing
entity-service/internal/handler/conversation_handler.go, entity-service/internal/server/routes.go
New ConversationHandler validates pagination query params and delegates to the service; route registered conditionally only for ServiceNow data source.
csm-portal entity client and proxy handler
apps/csm-portal/backend/internal/entity/entity.go, apps/csm-portal/backend/internal/handler/conversations.go, apps/csm-portal/backend/cmd/server/main.go
New Client.GetConversationMessages calls the entity service; new ConversationHandler validates auth and UUID, forwards raw query, maps upstream errors; route wired in main.go.
Tests and documentation
apps/csm-portal/backend/internal/handler/conversations_test.go, .../helpers_test.go, apps/csm-portal/backend/README.md, apps/csm-portal/backend/openapi.yaml
New mock client and handler tests covering auth, UUID validation, forwarding, and error mapping; README and OpenAPI document the new endpoint and schemas.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Suggested labels: Type/Improvement

Suggested reviewers: cloby99, shayanmalinda

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description only includes Summary and Test plan; most required template sections like Purpose, Goals, Approach, and Release note are missing. Fill in the required template sections: Purpose, Goals, Approach, User stories, Release note, Documentation, Security checks, and other applicable fields.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and accurately summarizes the main change: adding the GET /conversations/{id}/messages endpoint.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 unit tests (beta)
  • Create PR with unit tests

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
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
entity-service/internal/service/sn_conversation_service.go (1)

50-54: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Misleading shared-type name: snProjectPagination used for comments search.

The pagination struct name suggests it's project-specific, but it's reused here for the /comments/search payload. If this type is genuinely a shared, generic pagination shape, consider renaming it to something scope-neutral (e.g. snPagination) to avoid confusion at call sites like this one.

🤖 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 `@entity-service/internal/service/sn_conversation_service.go` around lines 50 -
54, The pagination type name is misleading because snProjectPagination is being
used for comments search in snConversationService; rename this shared pagination
shape to a scope-neutral name like snPagination and update the
snSearchCommentsPayload construction and any other call sites or references so
the type reflects its generic use.
🤖 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 `@entity-service/internal/handler/conversation_handler.go`:
- Around line 42-47: GetConversationMessages currently forwards
r.PathValue("id") directly into domain.GetConversationMessagesRequest without
validating it, so malformed IDs can reach ServiceNow. Update
ConversationHandler.GetConversationMessages to validate the conversation ID
first using the existing uuidToSysid path or equivalent UUID/canonical ID check,
and return a 400 Bad Request when the value is invalid instead of calling the
downstream service.

In `@entity-service/internal/service/sn_conversation_service.go`:
- Around line 67-71: The loop in sn_conversation_service.go currently aborts
GetConversationMessagesResponse construction when a single snResp.Comments item
has an invalid CreatedOn value. Update the parsing path inside the comments
iteration to log the malformed record and continue processing the remaining
comments, or apply a safe default for createdAt, so one bad ServiceNow timestamp
does not fail the whole response. Keep the change localized to the
comment-processing logic that calls time.Parse and returns the response.

---

Nitpick comments:
In `@entity-service/internal/service/sn_conversation_service.go`:
- Around line 50-54: The pagination type name is misleading because
snProjectPagination is being used for comments search in snConversationService;
rename this shared pagination shape to a scope-neutral name like snPagination
and update the snSearchCommentsPayload construction and any other call sites or
references so the type reflects its generic use.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: fa83536e-b71b-4a0d-bd7e-b35eeb6cdb51

📥 Commits

Reviewing files that changed from the base of the PR and between d574f8c and 2bed79f.

📒 Files selected for processing (12)
  • apps/csm-portal/backend/README.md
  • apps/csm-portal/backend/cmd/server/main.go
  • apps/csm-portal/backend/internal/entity/entity.go
  • apps/csm-portal/backend/internal/handler/conversations.go
  • apps/csm-portal/backend/internal/handler/conversations_test.go
  • apps/csm-portal/backend/internal/handler/helpers_test.go
  • apps/csm-portal/backend/openapi.yaml
  • entity-service/internal/domain/entity.go
  • entity-service/internal/handler/conversation_handler.go
  • entity-service/internal/server/routes.go
  • entity-service/internal/service/interfaces.go
  • entity-service/internal/service/sn_conversation_service.go

Comment thread entity-service/internal/handler/conversation_handler.go Outdated
Comment thread entity-service/internal/service/sn_comment_service.go
Rashmika998 and others added 4 commits July 3, 2026 19:45
Replace the conversation-specific GET endpoint design with a generic
POST /comments/search endpoint on the entity-service, mirroring the
Ballerina entity-service pattern:

Entity-service:
- domain: add Comment, SearchCommentsRequest, SearchCommentsResponse
  types (replacing the removed ConversationMessage types)
- service: add CommentService interface; snCommentSearchService calls
  POST /comments/search on the Choreo API with referenceType forwarded
- handler: CommentHandler.SearchComments decodes the request and
  delegates to the service
- routes: register POST /comments/search (SN data source only)
- openapi.yaml: document POST /comments/search with Comment schema

CSM portal BFF:
- entity client: SearchComments calls POST /comments/search
- handler: GetConversationMessages builds the referenceType=conversation
  payload, validates limit/offset query params, and calls SearchComments

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ce for SN

For the ServiceNow data source, POST /cases/{id}/comments/search now delegates
to the generic CommentService.SearchComments (with referenceType=case injected
from the path), eliminating the duplicate Choreo integration in snCaseService.
The postgres path is unchanged. CSM portal backend similarly injects referenceId
and referenceType and calls POST /comments/search on the entity service directly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…onse

A single malformed timestamp from ServiceNow no longer fails the whole
page; the offending record is logged at WARN and skipped.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Callers (CSM portal cases and conversations endpoints) now call the generic
POST /comments/search directly with the appropriate referenceId and
referenceType, so the case-specific route is no longer needed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@cloby99
cloby99 merged commit e6bf0c4 into wso2-open-operations:v2 Jul 3, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants