# Conversation History

This API returns the **Conversation History** for a given session. Conversation History contains a list of all Messages (both user and Assistant-generated) as well as Tool and Knowledge calls from the provided session.

The API returns Tool and Knowledge calls as Messages, where the `role` property is either `tool` or `knowledge`, respectively.

## Message Properties

<OperationTable type="properties" data={{"type":"object","refName":"assistants.v1.service.message","modelName":"assistants_v1_service_message","properties":{"id":{"type":"string","pattern":"^aia_msg_.+$","description":"The message ID."},"account_sid":{"type":"string","minLength":34,"maxLength":34,"pattern":"^AC[0-9a-fA-F]{32}$","description":"The SID of the [Account](/docs/iam/api/account) that created the Message resource."},"assistant_id":{"type":"string","pattern":"^aia_asst_.+$","description":"The Assistant ID."},"session_id":{"description":"The Session ID.","type":"string"},"identity":{"description":"The identity of the user.","type":"string"},"role":{"description":"The role of the user associated with the message.","type":"string"},"content":{"description":"The content of the message.","type":"object"},"meta":{"description":"The metadata of the message.","type":"object"},"date_created":{"description":"The date and time in GMT when the Message was created specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.","format":"date-time","type":"string"},"date_updated":{"description":"The date and time in GMT when the Message was last updated specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.","format":"date-time","type":"string"}}}} />

## Get Conversation History

`GET https://assistants.twilio.com/v1/Sessions/{sessionId}/Messages`

### Path parameters

```json
[{"name":"sessionId","in":"path","required":true,"description":"Session id or name","schema":{"type":"string"}}]
```

### Query parameters

```json
[{"name":"Page","in":"query","description":"The page index. This value is simply for client state.","schema":{"type":"integer","minimum":0}},{"name":"PageSize","in":"query","description":"How many resources to return in each list page. The default is 50, and the maximum is 1000.","schema":{"type":"integer","minimum":1,"maximum":1000}},{"name":"PageToken","in":"query","description":"The page token. This is provided by the API.","schema":{"type":"string"}}]
```

Get Conversation History

```js
// Download the helper library from https://www.twilio.com/docs/node/install
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = twilio(accountSid, authToken);

async function listMessages() {
  const messages = await client.assistants.v1
    .sessions("your-session-id")
    .messages.list({ limit: 20 });

  messages.forEach((m) => console.log(m.id));
}

listMessages();
```

```python
# Download the helper library from https://www.twilio.com/docs/python/install
import os
from twilio.rest import Client

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
auth_token = os.environ["TWILIO_AUTH_TOKEN"]
client = Client(account_sid, auth_token)

messages = client.assistants.v1.sessions("your-session-id").messages.list(
    limit=20
)

for record in messages:
    print(record.id)
```

```csharp
// Install the C# / .NET helper library from twilio.com/docs/csharp/install

using System;
using Twilio;
using Twilio.Rest.Assistants.V1.Session;
using System.Threading.Tasks;

class Program {
    public static async Task Main(string[] args) {
        // Find your Account SID and Auth Token at twilio.com/console
        // and set the environment variables. See http://twil.io/secure
        string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");

        TwilioClient.Init(accountSid, authToken);

        var messages = await MessageResource.ReadAsync(pathSessionId: "your-session-id", limit: 20);

        foreach (var record in messages) {
            Console.WriteLine(record.Id);
        }
    }
}
```

```java
// Install the Java helper library from twilio.com/docs/java/install

import com.twilio.Twilio;
import com.twilio.rest.assistants.v1.session.Message;
import com.twilio.base.ResourceSet;

public class Example {
    // Find your Account SID and Auth Token at twilio.com/console
    // and set the environment variables. See http://twil.io/secure
    public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
    public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");

    public static void main(String[] args) {
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
        ResourceSet<Message> messages = Message.reader("your-session-id").limit(20).read();

        for (Message record : messages) {
            System.out.println(record.getId());
        }
    }
}
```

```go
// Download the helper library from https://www.twilio.com/docs/go/install
package main

import (
	"fmt"
	"github.com/twilio/twilio-go"
	assistants "github.com/twilio/twilio-go/rest/assistants/v1"
	"os"
)

func main() {
	// Find your Account SID and Auth Token at twilio.com/console
	// and set the environment variables. See http://twil.io/secure
	// Make sure TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN exists in your environment
	client := twilio.NewRestClient()

	params := &assistants.ListMessagesParams{}
	params.SetLimit(20)

	resp, err := client.AssistantsV1.ListMessages("your-session-id",
		params)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	} else {
		for record := range resp {
			fmt.Println(resp[record].Id)
		}
	}
}
```

```php
<?php

// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once "/path/to/vendor/autoload.php";

use Twilio\Rest\Client;

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
$sid = getenv("TWILIO_ACCOUNT_SID");
$token = getenv("TWILIO_AUTH_TOKEN");
$twilio = new Client($sid, $token);

$messages = $twilio->assistants->v1
    ->sessions("your-session-id")
    ->messages->read(20);

foreach ($messages as $record) {
    print $record->id;
}
```

```ruby
# Download the helper library from https://www.twilio.com/docs/ruby/install
require 'twilio-ruby'

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = ENV['TWILIO_ACCOUNT_SID']
auth_token = ENV['TWILIO_AUTH_TOKEN']
@client = Twilio::REST::Client.new(account_sid, auth_token)

messages = @client
           .assistants
           .v1
           .sessions('your-session-id')
           .messages
           .list(limit: 20)

messages.each do |record|
   puts record.id
end
```

```bash
# Install the twilio-cli from https://twil.io/cli

twilio api:assistants:v1:sessions:messages:list \
   --session-id your-session-id
```

```bash
curl -X GET "https://assistants.twilio.com/v1/Sessions/your-session-id/Messages?PageSize=20" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
```

```json
{
  "messages": [
    {
      "id": "aia_msg_#",
      "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
      "assistant_id": "aia_asst_#",
      "session_id": "session_id",
      "identity": "identity",
      "role": "role",
      "content": {},
      "meta": {},
      "date_created": "2009-07-06T20:30:00Z",
      "date_updated": "2009-07-06T20:30:00Z"
    }
  ],
  "meta": {
    "first_page_url": "https://www.example.com",
    "key": "key",
    "next_page_url": "https://www.example.com",
    "page": 42,
    "page_size": 42,
    "previous_page_url": "https://www.example.com",
    "url": "https://www.example.com"
  }
}
```
