evolution-api icon indicating copy to clipboard operation
evolution-api copied to clipboard

GET Messages Endpoint for Users and Groups

Open heslanx opened this issue 1 year ago • 0 comments

Welcome!

  • [X] Yes, I have searched for similar requests on GitHub and found none.

What type of feature?

Integration

What is the motivation for the request?

I would like to suggest the implementation of a new endpoint to retrieve messages for both individual users and groups. This would allow clients to fetch message history for a specific group or user by specifying either the groupJid or the user's phone number, alongside optional parameters like start and end timestamps to limit the date range of retrieved messages.

Usage Examples

Proposed Endpoint:

  1. For retrieving messages from a group:
curl GET 'https://sub.domain.com/messages/{instance_name}' \
--header 'Content-Type: application/json' \
--header 'apikey: [[apikey-masked-secret]]' \
--data '{
    "groupJid": "{{groupJid}}",
    "startTime": "{{start_timestamp}}",  // optional
    "endTime": "{{end_timestamp}}"       // optional
}'
  1. For retrieving messages from a user:
curl GET 'https://sub.domain.com/messages/{instance_name}' \
--header 'Content-Type: application/json' \
--header 'apikey: [[apikey-masked-secret]]' \
--data '{
    "number": "559999999999 (Recipient number with Country Code)",
    "startTime": "{{start_timestamp}}",  // optional
    "endTime": "{{end_timestamp}}"       // optional
}'

Request Parameters:

  • groupJid: The group identifier for which messages should be retrieved.
  • number: The phone number (including country code) of the individual user whose messages should be retrieved.
  • startTime: (Optional) A Unix timestamp indicating the start of the date range for fetching messages.
  • endTime: (Optional) A Unix timestamp indicating the end of the date range for fetching messages.

Use Case:

This feature would be useful in several scenarios, such as:

  • Fetching recent conversations within a group.
  • Retrieving historical messages for audit or reporting purposes.
  • Extracting conversations for an individual user.
  • Filtering messages within a specific date range.

Expected Output:

The endpoint would return a JSON object with the following structure (example):

{
    "messages": [
        {
            "id": "message-id-1",
            "sender": "559999999999",
            "content": "Message content",
            "timestamp": "message-timestamp",
            "groupJid": "{{groupJid}}", // if it's a group message
            "type": "text"
        },
        {
            "id": "message-id-2",
            "sender": "559999999998",
            "content": "Another message content",
            "timestamp": "message-timestamp",
            "number": "559999999998" // if it's a user message
        }
    ]
}

How should the feature be developed?

Implementing this endpoint would significantly enhance the ability of clients to access user and group conversations programmatically. The ability to specify a date range using startTime and endTime would also provide greater flexibility in fetching only the relevant data, improving the efficiency of data retrieval processes.

Thank you for considering this suggestion! Looking forward to your feedback.

Additional Notes

No response

heslanx avatar Sep 26 '24 23:09 heslanx