Handle read status

Learn how to handle read statuses on Telegram using Unipile API.

When integrating a messaging platform, you need to handle read and unread status at two distinct levels:

  • Message read status — tracking when the account owner has read someone else’s message, so indicators like the double blue check appear at the correct time for the recipient(s).
  • Chat read status — keeping the overall chat state (read/unread) synchronized across devices to ensure consistent organization.

Read messages

To mark messages from other users as read by the account owner, use Read a Message method and provide the ID of the message.

👍

Recommendations

For your integration to conform to a natural behavior, we recommend to mark messages as read before you reply to them.

const { data, error } = await messagingApi.readMessage({
  path: {
    account_id: "acc_123456789",
    chat_id: "chat_id",
    message_id: "message_id",
  },
});
messaging_api.read_message(
    "chat_id",
    "message_id",
    "acc_123456789",
)
curl --request POST \
     --url https://api.unipile.com/v2/account_id/chats/chat_id/messages/message_id/read \
     --header 'accept: application/json'

Read a chat

When you receive messages in a chat, the unread_count (green badge in native apps) is increased automatically and is_unread is true if there is at least one unread message.

To mark a chat as read (reset the unread_count and is_unread), use Update a Chat and define read_status to true.

const { data, error } = await messagingApi.updateChat({
  path: {
    account_id: "acc_123456789",
    chat_id: "chat_id",
  },
  body: {
    read_status: true,
  },
});
messaging_api.update_chat(
    "chat_id",
    "acc_123456789",
    {"read_status": True},
)
curl --request PATCH \
     --url https://api.unipile.com/v2/account_id/chats/chat_id \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --data '{"read_status":true}'
👍

Recommendation

When marking a chat as read, also mark all unread messages within it as read to maintain consistent, expected behavior in your integration. It's not automatically done.

You can determine which messages are unread by using the unread_count property or by tracking a “last read” timestamp.

For details on marking messages as read, see the Read messages section of this guide.


Mark a chat as unread

If a chat is already read, you can manually mark it as unread by defining read_status to false using Update a Chat. It will appear with a green dot on native apps.

messaging_api.update_chat(
    "chat_id",
    "acc_123456789",
    {"read_status": False},
)