# Understand conversation data 2/2

## Contact vs conversation definition

\- A **contact** is an exchange between a visitor and an operator (agent, expert or bot). It can be a chat, call or video contact.

\- A **conversation** can include several contacts, especially if they have been transferred or snoozed.

A conversation can therefore include several contacts when it is ended.

<figure><img src="/files/f07mPlaXz4qU1fqAeelN" alt=""><figcaption></figcaption></figure>

## Fields to be used

The fields/properties mentioned are available in the [**`Conversation`**](https://graphql.iadvize.dev/types/Conversation) type/object. This [**`Conversation`**](https://graphql.iadvize.dev/types/Conversation) object is available through (depending on your needs) two queries:

* **`closedConversations`**: which returns a paginated list of `Conversation` objects that are closed only.
* **`conversation`**: which returns a `Conversation` object based on its id (in uuid format).

{% hint style="info" %}
As a reminder, GraphQL doesn't explicitly expose the notion of "contact", but it's entirely possible to reconstruct this notion by exploring the lifecycle of the conversation through the various distribution events ([**`routingEvents`**](https://graphql.iadvize.dev/types/RoutingEvent)) or events occurring during the conversation via messages of type [**`SystemMessage`**](https://graphql.iadvize.dev/types/SystemMessage)in the messages property (the[**`ConversationPushedSystemAttachment`**](https://graphql.iadvize.dev/types/ConversationPushedSystemAttachment)attachment that systematically marks the start of a new contact).
{% endhint %}

Here are all the fields/properties of the Conversation object you'll need to make your request:

<table><thead><tr><th width="189">Field</th><th>Comments</th></tr></thead><tbody><tr><td>DATE/TIME (opening)</td><td>The goal is to retrieve the start date of each contact for which a <strong><code>ConversationPushedSystemAttachment</code></strong> message occurs systematically.</td></tr><tr><td>DATE/TIME (close)</td><td><p>See point above.</p><p>If you need to retrieve the conversation's closing date, it is available in the <strong><code>closedAt</code></strong> property.</p></td></tr><tr><td><p>ID_</p><p>CONTACT (unique)</p></td><td>There's no such thing as a contact id, but it's possible to build one by concatenating various pieces of information, such as the conversation id and the date (<strong><code>createdAt</code></strong>) of the <strong><code>ConversationPushedSystemAttachment</code></strong> attachment.</td></tr><tr><td>SITE_ID</td><td>This is the <strong><code>id</code></strong> property in the conversation's <strong><code>project</code></strong> property.</td></tr><tr><td>CHANNEL (chat/wa/ etc.)</td><td>This is the <strong><code>channel</code></strong> property</td></tr><tr><td><p>ID_</p><p>OPERATOR</p></td><td>It is possible to retrieve the information (id, name, email, etc.) of the user who has processed a contact. This information can be accessed in the <strong><code>toUser</code></strong> property of the system message whose attachment is of type <strong><code>ConversationPushedSystemAttachment</code></strong>.</td></tr><tr><td><p>ID_</p><p>CONVERSATION</p></td><td>This information is available in the <strong><code>id</code></strong> property of the <strong><code>Conversation</code></strong> object.</td></tr><tr><td>ROUTING_RULES</td><td><p>The goal is to determine which group(s) of respondents actually handled the contact.</p><p>This information is available in the <strong><code>routingEvents</code></strong> property, which retrieves the date on which the event occurred (<strong><code>createdAt</code></strong>), as well as details of the rule and targeting group (<strong><code>routingRule</code></strong> and <strong><code>routingGroup</code></strong>) to which the conversation was distributed.<br></p><p>Chronologically, a distribution event necessarily occurs before one or more <strong><code>ConversationPushedSystemAttachment</code></strong> messages (corresponding to the sending of the conversation to the advisor's console or the reception of the conversation by a bot).</p><p>For example, a conversation with two contacts handled by the same operator. We can clearly see two <strong><code>ConversationPushedSystemAttachments</code></strong> that can be linked to distribution information (<strong><code>routingRule</code></strong> and <strong><code>routingGroup</code></strong>).</p><p>11:00:00 routingEvent (routingRule+routingGroup)</p><p>11:00:01 ConversationPushedSystemAttachment</p><p>11:00:05 ConversationSnoozedSystemAttachment</p><p>— conversation returns 5 minutes after snooze</p><p>11:05:05 ConversationPushedSystemAttachment</p><p>…</p><p>…</p><p>11:10:00 ConversationClosedSystemAttachment</p><p><br></p></td></tr><tr><td><p>CONTACT_</p><p>STATUS (answered, unanswered, transferred, snoozed...)</p></td><td><p>This involves retrieving events that have occurred during the conversation.</p><p>iAdvize exposes all these events in the <strong><code>messages</code></strong> property with the <strong><code>SystemMessage</code></strong> type. It's possible to retrieve the name of this event using the <strong><code>__typename</code></strong> property, as well as information specific to each event, which you can find in our <a href="https://ha.iadvize.com/apollo">Apollo tool</a>.</p><p>Here is an example of some of the events you may encounter:</p><ul><li><strong><code>ConversationClosedSystemAttachment</code></strong></li><li><strong><code>TransferredToUserSystemAttachment</code></strong></li><li><strong><code>TransferredToRoutingRuleSystemAttachment</code></strong></li><li><strong><code>ConversationSnoozedSystemAttachment</code></strong></li><li>…</li></ul></td></tr><tr><td><p>ENDING_</p><p>CONTACT (reason)</p></td><td><p>The need is to determine whether the contacts have resulted in :</p><p>- a closing</p><p>- a transfer</p><p>- a snooze</p><p>- ...</p><p><br>This information can be retrieved via the <strong><code>SystemMessage</code></strong> mentioned above.</p></td></tr></tbody></table>

## Find conversation contacts through SystemMessage

<figure><img src="/files/CFak8sFBBkGEnK8JQgRD" alt=""><figcaption></figcaption></figure>

## Example of a query

In the following example, we retrieve the distribution information as well as the events in the conversation's lifecycle (marking, in particular, the beginning and end of contacts).

We therefore find 3 contacts symbolized by the presence of 3 attachments of type: **`ConversationPushedSystemAttachment`**.

As the conversation has been transferred to distribution rules, we also find 3 distribution events in the **`routingEvents`** property.

### Query

```graphql
query MyQuery {
  conversation(id: "b90f9039-f993-4221-9293-0000000000fb") {
    id
    channel
    messages {
      edges {
        node {
          __typename
          ... on SystemMessage {
            attachments {
              __typename
              ... on ConversationPushedSystemAttachment {
                toUser {
                  id
                  email
                  firstName
                }
              }
              ... on ConversationClosedSystemAttachment {
                byUser {
                  __typename
                  id
                  email
                  firstName
                  lastName
                }
              }
              ... on TransferredToUserSystemAttachment {
                reason
                toUser {
                  __typename
                  id
                  email
                  firstName
                  lastName
                }
                fromUser {
                  __typename
                  id
                  email
                  firstName
                  lastName
                }
              }
              ... on TransferredToRoutingRuleSystemAttachment {
                reason
                fromUser {
                  __typename
                  id
                  email
                  firstName
                  lastName
                }
              }
              ... on ConversationSnoozedSystemAttachment {
                until
                byUser {
                  __typename
                  id
                  email
                  firstName
                  lastName
                }
              }
            }
            createdAt
          }
        }
      }
    }
    routingEvents {
      routingGroup {
        id
        name
      }
      createdAt
      routingRule {
        id
        name
      }
    }
  }
}

```

### Response / result

```json
{
  "data": {
    "conversation": {
      "id": "b90f9039-f993-4221-9293-0000000000fb",
      "channel": "CHAT",
      "messages": {
        "edges": [
          {
            "node": {
              "__typename": "ParticipantConversationMessage"
            }
          },
          {
            "node": {
              "__typename": "SystemMessage",
              "attachments": [
                {
                  "__typename": "EngagementRuleTriggeredSystemAttachment"
                }
              ],
              "createdAt": "2023-10-08T08:33:04.774429Z"
            }
          },
          {
            "node": {
              "__typename": "SystemMessage",
              "attachments": [
                {
                  "__typename": "NavigationChangedSystemAttachment"
                }
              ],
              "createdAt": "2023-10-08T08:33:05Z"
            }
          },
          {
            "node": {
              "__typename": "SystemMessage",
              "attachments": [],
              "createdAt": "2023-10-08T08:33:05.411381Z"
            }
          },
          {
            "node": {
              "__typename": "SystemMessage",
              "attachments": [
                {
                  "__typename": "ConversationPushedSystemAttachment",
                  "toUser": {
                    "id": 44000,
                    "email": "ha@bot.iadvize.com",
                    "firstName": null
                  }
                }
              ],
              "createdAt": "2023-10-08T08:33:05.490789Z"
            }
          },
          {
            "node": {
              "__typename": "SystemMessage",
              "attachments": [
                {
                  "__typename": "NavigationChangedSystemAttachment"
                }
              ],
              "createdAt": "2023-10-08T08:33:05.559807Z"
            }
          },
          {
            "node": {
              "__typename": "ParticipantConversationMessage"
            }
          },
          {
            "node": {
              "__typename": "ParticipantConversationMessage"
            }
          },
          {
            "node": {
              "__typename": "SystemMessage",
              "attachments": [
                {
                  "__typename": "TransferredToRoutingRuleSystemAttachment",
                  "reason": "",
                  "fromUser": {
                    "__typename": "Bot",
                    "id": 434024,
                    "email": "ha2@bot.iadvize.com",
                    "firstName": null,
                    "lastName": "Page contact"
                  }
                }
              ],
              "createdAt": "2023-10-08T08:33:10.646767Z"
            }
          },
          {
            "node": {
              "__typename": "SystemMessage",
              "attachments": [
                {
                  "__typename": "VisitorNotificationSettingsRequestedSystemAttachment"
                }
              ],
              "createdAt": "2023-10-08T08:33:15.949558Z"
            }
          },
          {
            "node": {
              "__typename": "SystemMessage",
              "attachments": [
                {
                  "__typename": "VisitorNotificationSettingsSetSystemAttachment"
                }
              ],
              "createdAt": "2023-10-08T08:33:19.587015Z"
            }
          },
          {
            "node": {
              "__typename": "SystemMessage",
              "attachments": [
                {
                  "__typename": "VisitorNotificationSettingsConfirmedSystemAttachment"
                }
              ],
              "createdAt": "2023-10-08T08:33:19.879399Z"
            }
          },
          {
            "node": {
              "__typename": "ParticipantConversationMessage"
            }
          },
          {
            "node": {
              "__typename": "SystemMessage",
              "attachments": [],
              "createdAt": "2023-10-08T08:38:58.366868Z"
            }
          },
          {
            "node": {
              "__typename": "SystemMessage",
              "attachments": [
                {
                  "__typename": "ConversationPushedSystemAttachment",
                  "toUser": {
                    "id": 268289,
                    "email": "test@iadvize.com",
                    "firstName": "Pierre HACK"
                  }
                }
              ],
              "createdAt": "2023-10-08T08:39:02.422185Z"
            }
          },
          {
            "node": {
              "__typename": "ParticipantConversationMessage"
            }
          },
          {
            "node": {
              "__typename": "ParticipantConversationMessage"
            }
          },
          {
            "node": {
              "__typename": "SystemMessage",
              "attachments": [
                {
                  "__typename": "TransferredToRoutingRuleSystemAttachment",
                  "reason": "j’aimerais faire réparer l’écran de mon téléphone qui est cassé",
                  "fromUser": {
                    "__typename": "Professional",
                    "id": 260000,
                    "email": "test@iadvize.com",
                    "firstName": "Pierre HACK",
                    "lastName": "MU"
                  }
                },
                {
                  "__typename": "UnsupportedSystemMessageAttachment"
                }
              ],
              "createdAt": "2023-10-08T08:40:03.249159Z"
            }
          },
          {
            "node": {
              "__typename": "SystemMessage",
              "attachments": [
                {
                  "__typename": "VisitorNotificationSettingsRequestedSystemAttachment"
                }
              ],
              "createdAt": "2023-10-08T08:40:09.326441Z"
            }
          },
          {
            "node": {
              "__typename": "SystemMessage",
              "attachments": [],
              "createdAt": "2023-10-08T08:43:03.373263Z"
            }
          },
          {
            "node": {
              "__typename": "SystemMessage",
              "attachments": [
                {
                  "__typename": "ConversationPushedSystemAttachment",
                  "toUser": {
                    "id": 380000,
                    "email": "test2@iadvize.com",
                    "firstName": "AnnH PLEVIN"
                  }
                }
              ],
              "createdAt": "2023-10-08T08:43:04.311492Z"
            }
          },
          {
            "node": {
              "__typename": "ParticipantConversationMessage"
            }
          },
          {
            "node": {
              "__typename": "ParticipantConversationMessage"
            }
          },
          {
            "node": {
              "__typename": "ParticipantConversationMessage"
            }
          },
          {
            "node": {
              "__typename": "ParticipantConversationMessage"
            }
          },
          {
            "node": {
              "__typename": "SystemMessage",
              "attachments": [
                {
                  "__typename": "ConversationClosedSystemAttachment",
                  "byUser": {
                    "__typename": "Professional",
                    "id": 383512,
                    "email": "test2@iadvize.com",
                    "firstName": "AnnH PLEVIN",
                    "lastName": "CA"
                  }
                }
              ],
              "createdAt": "2023-10-08T08:52:11Z"
            }
          }
        ]
      },
      "routingEvents": [
        {
          "routingGroup": {
            "id": "f3485cc1-2a31-00e2-bc0e-000fd57dcf19",
            "name": "Page contact - chatbot routing group"
          },
          "createdAt": "2023-10-08T08:33:04Z",
          "routingRule": {
            "id": "594ee64b-b888-4f1a-8273-47eae1f0a566",
            "name": "Distribuer à bot Page Contact puis au service client"
          }
        },
        {
          "routingGroup": {
            "id": "007fce95-561c-000b-89ff-9b5846398d11",
            "name": "Groupe Service client 1"
          },
          "createdAt": "2023-10-08T08:33:10Z",
          "routingRule": {
            "id": "fed7f40a-0000-43e3-85cd-13eff3c8d64e",
            "name": "Transfert Bot vers Service client commercial"
          }
        },
        {
          "routingGroup": {
            "id": "cbf887b7-e33b-000e-ad2c-33fb7025c03f",
            "name": "Groupe Assistance technique"
          },
          "createdAt": "2023-10-08T08:40:03Z",
          "routingRule": {
            "id": "6b91bba2-78bc-48d2-a5ff-d9f391f0000",
            "name": "Assistance technique"
          }
        }
      ]
    }
  }
}

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.iadvize.dev/use-cases/data-and-analytics/retrieve-messages-exchanged-within-a-conversation-1/find-contact-data-graphql-1.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
