---
description: Get P2P conversation messages.
---

# 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](../../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.
