# チャット履歴

> Retrieve and manage chat message history.

## チャンネルテキストメッセージの履歴

Vivox では、[`VivoxService.Instance.GetChannelTextMessageHistoryAsync(string channelName, int requestSize = 10, ChatHistoryQueryOptions chatHistoryQueryOptions = null)`](https://docs.unity3d.com/Packages/com.unity.services.vivox@latest/index.html?subfolder=/api/Unity.Services.Vivox.IVivoxService.html#Unity_Services_Vivox_IVivoxService_GetChannelTextMessageHistoryAsync_System_String_System_Int32_Unity_Services_Vivox_ChatHistoryQueryOptions_) を使用して、ユーザーがチャンネルのテキストアクティビティの履歴にアクセスできるようにします。`channelName` は履歴をリクエストするチャンネルの名前、`requestSize` は返すメッセージの最大数 (デフォルトは 10) で、`chatHistoryQueryOptions` はメッセージに含まれる単語やフレーズ、特定の PlayerId のメッセージ送信者、クエリの対象とする時刻 (その時刻の前または後) の指定などができる任意のパラメーターです。`ChatHistoryQueryOption` のより具体的な情報については、[チャット履歴のクエリオプション](/vivox-unity/text-chat-guide/chat-history-query-options.md.md) を参照してください。

`IReadOnlyCollection` で返されるメッセージは、最新のメッセージから最も古いメッセージへの順でリスト表示されます。

> **Note:**
>
> チャット履歴は 7 日間保存されます。[テキストエビデンス管理](/safe-text/text-evidence/text-evidence-management.md.md) が使用される場合、チャット履歴の保存期間が 30 日間に延長されます。

以下のコードスニペットは、設定された LobbyChannelName から最新の 25 件のメッセージをプルし、任意の ChatHistoryQueryOptions は使用せずに、送信者の表示名とメッセージを古いものから新しいものへの順でログ記録する例です。

```cs
public async void FetchHistoryAsync()
{
    var historyMessages = await VivoxService.Instance.GetChannelTextMessageHistoryAsync(LobbyChannelName, 10);
    //Reversing the messages so they display from oldest to newest
    var reversedMessages = historyMessages.Reverse();
    foreach(VivoxMessage message in reversedMessages)
    {
        Debug.Log($"{message.SenderDisplayName}: {message.MessageText}");
    }
}
```
