Skip to content

Add endpoint to retrieve chat data by remoteJid #1743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 21, 2025

Conversation

foqc
Copy link
Contributor

@foqc foqc commented Jul 21, 2025

This PR introduces a new API endpoint called findChatByRemoteJid, which allows retrieving chat information using a phone number (identified internally as remoteJid).

What's included:

  • New controller method: findChatByRemoteJid
  • Input validation for remoteJid
  • Integration into the existing chat service
  • Basic error handling for not found or invalid inputs

This functionality will be useful for querying specific chats directly by their associated phone number.

Summary by Sourcery

Add a new API endpoint to retrieve chat records by remoteJid, including route, controller, and service implementations with input validation and error handling.

New Features:

  • Introduce GET /findChatByRemoteJid endpoint in chat router with query parameter validation
  • Add ChatController.findChatByRemoteJid to delegate fetching logic
  • Implement ChannelStartupService.findChatByRemoteJid using Prisma to query chat by remoteJid

Copy link
Contributor

sourcery-ai bot commented Jul 21, 2025

Reviewer's Guide

Introduces a findChatByRemoteJid endpoint by adding a route, controller method, and service query to fetch chat records by phone number with validation and error handling.

Sequence diagram for the new findChatByRemoteJid API endpoint

sequenceDiagram
    actor User
    participant API as ChatRouter
    participant Controller as ChatController
    participant Service as ChannelStartupService
    participant DB as PrismaRepository

    User->>API: GET /findChatByRemoteJid?remoteJid=...
    API->>API: Validate remoteJid
    API->>Controller: findChatByRemoteJid(instance, remoteJid)
    Controller->>Service: findChatByRemoteJid(remoteJid)
    Service->>DB: chat.findFirst({ instanceId, remoteJid })
    DB-->>Service: Chat record or null
    Service-->>Controller: Chat record or null
    Controller-->>API: Chat record or null
    API-->>User: 200 OK (chat data) or error
Loading

Class diagram for new and updated methods in chat retrieval

classDiagram
    class ChatRouter {
        +get('findChatByRemoteJid', ...)
    }
    class ChatController {
        +findChatByRemoteJid(instance: InstanceDto, remoteJid: string)
    }
    class ChannelStartupService {
        +findChatByRemoteJid(remoteJid: string)
    }
    ChatRouter --> ChatController : calls
    ChatController --> ChannelStartupService : calls
Loading

File-Level Changes

Change Details Files
Expose new GET endpoint for chat lookup by remoteJid
  • Added route handler for findChatByRemoteJid
  • Extracted and validated remoteJid query parameter
  • Returned 400 on missing remoteJid and 200 with response
  • Invoked controller method to retrieve chat data
src/api/routes/chat.router.ts
Implement service method to fetch chat by remoteJid
  • Added findChatByRemoteJid that checks for missing remoteJid
  • Queried prismaRepository.chat.findFirst with instanceId and remoteJid
  • Returned null if no remoteJid provided
src/api/services/channel.service.ts
Add controller method delegating to service
  • Implemented findChatByRemoteJid in ChatController
  • Forwarded instanceName and remoteJid to waInstances service method
src/api/controllers/chat.controller.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@DavidsonGomes DavidsonGomes merged commit 9b7ca4b into EvolutionAPI:develop Jul 21, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants