---
source_url: https://www.pubnub.com/docs/chat/kotlin-chat-sdk/build/features/messages/restore
title: Restore messages
updated_at: 2026-06-15T11:02:32.351Z
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Restore messages

`restore()` recovers soft-deleted messages and their attached files. Hard-deleted messages cannot be restored.

:::note Requires Message Persistence
Enable [Message Persistence](https://youtu.be/qLMtbINWGig) and **Enable Delete-From-History** in the [Admin Portal](https://admin.pubnub.com/).
:::

### Method signature

This method has the following signature:

```kotlin
message.restore(): PNFuture<Message>
```

#### Input

This method doesn't take any parameters.

#### Output

| Type | Description |
| --- | --- |
| `PNFuture<Message>` | Object returning the restored [Message object](https://www.pubnub.com/docs/chat/kotlin-chat-sdk/learn/chat-entities/message). |

### Sample code

Restore a previously soft deleted message with the `16200000000000001` timetoken.

```kotlin
val timetoken: Long = 16200000000000001

// fetch the target message from history
channel.getMessage(timetoken).async { result ->
    result.onSuccess { messageToTarget: Message? ->
        when (messageToTarget?.deleted) {
            true -> {
                println("Message is deleted")
                // restore the deleted message
                messageToTarget.restore().async { restoreResult ->
                    restoreResult.onSuccess { restoredMessage ->
                        println("Message with timetoken $timetoken restored successfully: $restoredMessage")
                    }.onFailure { error ->
                        println("Failed to restore message with timetoken $timetoken: ${error.message}")
                    }
                }
            }

            false -> println("Message is not deleted")
            null -> println("Message does not exist")
        }
    }.onFailure { exception ->
        println("Failed to retrieve message status: ${exception.message}")
    }
}
```