# Read direct messages

To read accounts conversation you should know unique **ChatID** that contain 2 addresses separated by "|" symbol.&#x20;

To build correct ChatID you can use next function (or develop another by follow this logic):

```
const getPrivateChatId = (user1, user2) => {
  if (user1 > user2) {
    return user1.concat("|").concat(user2);
  }
  return user2.concat("|").concat(user1);
}
```

Note: To create the link to private conversation with another user, use function above to concat both user wallet addresses and replace {\_\_ADDRESSES\_\_} string in this URL:

[https://chatme.page/my/account/](https://chatme.page/my/account/zavodil.near|vlodkow.near){\_\_ADDRESSES\_\_}&#x20;

### Get conversation messages

To read latest messages based on **ChatID**, send request to [The Graph node URL](https://chatme.gitbook.io/chatme/network-info):

```
{
  privateMessages(
    last: 100, 
    skip: 0,
    orderBy: created_at, 
    orderDirection: desc,
    where: {
      chat_id: "${chatId}",
  }) {
      id
      inner_id
      text
      image
      from_address
      to_address
      deposit
      created_at
      encrypt_key
      reply_message {id, from_address, text, image, encrypt_key}
   }
}
```

You can modify this query for filter, sort or paginate results. \
Read [GraphQL API documentation](https://thegraph.com/docs/en/querying/graphql-api/) for more details.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://chatme.gitbook.io/chatme/dev-documentation/direct-messages/read-direct-messages.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
