Skip to main content

Read Receipt Content Type

Status Status

A read receipt is a timestamp that indicates when a message was read. It is sent as a message and can be used to calculate the time since the last message was read.

Open for feedback

You are welcome to provide feedback by commenting on the Read Receipts Content Type XIP Proposal.

Install the package

npm i @xmtp/content-type-read-receipt

Import and register

import {
ContentTypeReadReceipt,
ReadReceiptCodec,
} from "@xmtp/content-type-read-receipt";
// Create the XMTP client
const xmtp = await Client.create(signer, { env: "dev" });
xmtp.registerCodec(new ReadReceiptCodec());

Create a Read Receipt

  • timestamp: The timestamp the read receipt was sent, in ISO 8601 format
const readReceipt: ReadReceipt = {
/**
* The timestamp the read receipt was sent, in ISO 8601 format
*/
timestamp: dateString,
};

Sending a Read Receipt

Once you've created a read receipt, you can send it:

await conversation.send(readReceipt, {
contentType: ContentTypeReadReceipt,
});

Receiving a Read Receipt

Here's how you can receive a reply:

if (message.contentType.sameAs(ContentTypeReadReceipt)) {
// We've got a reply.
const timestamp = message.content.timestamp;
}

Displaying the Read Receipt

A read receipt timestamp should be not display but instead used to calculate the time since the last message was read. While iterating through messages you can be sure that the last message was read at the timestamp of the read receipt if the string if the date is lower.

function checkReadMessages(messages, readReceipt) {
return messages.map((message) => {
return {
...message,
isRead: message.timestamp <= readTimestamp,
};
});
}

Was the information on this page helpful?
powered by XMTP