Read direct messages

Get P2P conversation messages.

To read accounts conversation you should know unique ChatID that contain 2 addresses separated by "|" symbol.

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/{__ADDRESSES__}

Get conversation messages

To read latest messages based on ChatID, send request to The Graph node URL:

{
  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 for more details.

Last updated