# Threads, Group Chats, and DMs

In Glue, conversations occur inside threads, group chats or DMs. The functionality and appearance of these are very similar, and in the API, they are all represented by a `Thread`.

To distinguish the 3 in the API, look at the `isPeristentChat` and `recipients` fields.

## DMs

DMs will have `isPeristentChat: true` and the `recipients` field will contain exactly 2 users.

### GraphQL Response Sample

```graphql
{
  "data": {
    "thread": {
      "id": "thr_2PtTG7GFSgcgwfpeDOBGEQtyB24",
      "isPeristentChat": true,
      "recipients": {
        "edges": [
          {
            "node": {
              "id": "usr_1h3c43PfmSQpPb0CXwRJUYs0ker",
              "name": "Alice Johnson"
            }
          },
          {
            "node": {
              "id": "usr_2mHVPy5LlHYPs2zHcwm56M85J3h",
              "name": "Bob Smith"
            }
          }
        ]
      }
    }
  }
}
```

### Looking Up a DM's Thread ID

To find the thread ID for a DM with a specific user, you can query for a `UserEdge` and access its `persistentChatEdge`. The `UserEdge` represents the relationship between the current user and another user, and contains a `persistentChatEdge` field that points to the DM thread.

**Note**: The `UserEdge` ID follows the pattern `{otherUserID}-{currentUserID}`. In this example, `usr_2mHVPy5LlHYPs2zHcwm56M85J3h-usr_1h3c43PfmSQpPb0CXwRJUYs0ker` represents the edge from Alice (current user) to Bob (other user). One of the 2 user IDs must be the user associated with the access token. You cannot access DMs involving other users.

#### GraphQL Query Example

```graphql
query GetDMThreadID($userID: ID!) {
  node(id: $id) {
    ... on UserEdge {
      id
      persistentChatEdge {
        node {
          id
          isPeristentChat
          recipients {
            edges {
              node {
                id
                name
              }
            }
          }
        }
      }
    }
  }
}
```

#### Variables

```json
{
  "id": "usr_2mHVPy5LlHYPs2zHcwm56M85J3h-usr_1h3c43PfmSQpPb0CXwRJUYs0ker"
}
```

#### Response Sample

```json
{
  "data": {
    "node": {
      "id": "usr_2mHVPy5LlHYPs2zHcwm56M85J3h-usr_1h3c43PfmSQpPb0CXwRJUYs0ker",
      "persistentChatEdge": {
        "node": {
          "id": "thr_2PtTG7GFSgcgwfpeDOBGEQtyB24",
          "isPeristentChat": true,
          "recipients": {
            "edges": [
              {
                "node": {
                  "id": "usr_1h3c43PfmSQpPb0CXwRJUYs0ker",
                  "name": "Alice Johnson"
                }
              },
              {
                "node": {
                  "id": "usr_2mHVPy5LlHYPs2zHcwm56M85J3h",
                  "name": "Bob Smith"
                }
              }
            ]
          }
        }
      }
    }
  }
}
```

## Group Chats

Group Chats will have `isPeristentChat: true` and the `recipients` field will contain exactly 1 group.

### GraphQL Response Sample

```graphql
{
  "data": {
    "thread": {
      "id": "thr_2rdAeYdtPPUOMQx5MgeeUkw9Yar",
      "isPeristentChat": true,
      "recipients": {
        "edges": [
          {
            "node": {
              "id": "grp_2hSyORgf8VqMLg0ADIvTi9oY6Nk",
              "name": "Engineering Team",
              "description": "Core engineering team discussions"
            }
          }
        ]
      }
    }
  }
}
```

## Threads

Threads will have `isPeristentChat: false`. The `recipients` field could contain any combination of users and groups.

### GraphQL Response Sample

```graphql
{
  "data": {
    "thread": {
      "id": "thr_2hTJ4DGsxUAeEhKOyJ2PMePFL0c",
      "isPeristentChat": false,
      "recipients": {
        "edges": [
          {
            "node": {
              "id": "usr_2rdDJjsN0n5HONuOusUoNcdu26X",
              "name": "Charlie Davis"
            }
          },
          {
            "node": {
              "id": "grp_2tuREOmMXCuwA9GDHhJf9CaHaaa",
              "name": "Product Team",
            }
          },
          {
            "node": {
              "id": "usr_2rdAe3Iuh2i92zy9Rq2xsWBQ59u",
              "name": "Diana Wilson"
            }
          }
        ]
      }
    }
  }
}
```


---

# 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.glue.ai/developers/graphql-api/understanding-glue-thread-types/threads_chats_dms.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.
