> ## Documentation Index
> Fetch the complete documentation index at: https://docs.x.com/llms.txt
> Use this file to discover all available pages before exploring further.

# DirectMessagesClient

> Reference for the DirectMessagesClient class in the X API TypeScript SDK. Methods, parameters, and return types for the X API v2 direct messages endpoints.

Client for direct messages operations

This client provides methods for interacting with the direct messages endpoints
of the X API. It handles authentication, request formatting, and response
parsing for all direct messages related operations.

## Constructors

### constructor

• **new DirectMessagesClient**(`client`): [`DirectMessagesClient`](/xdks/typescript/reference/classes/DirectMessagesClient)

Creates a new direct messages client instance

#### Parameters

| Name     | Type                                                  | Description                    |
| :------- | :---------------------------------------------------- | :----------------------------- |
| `client` | [`Client`](/xdks/typescript/reference/classes/Client) | The main X API client instance |

#### Returns

[`DirectMessagesClient`](/xdks/typescript/reference/classes/DirectMessagesClient)

#### Defined in

[direct\_messages/client.ts:340](https://github.com/xdevplatform/xdk-typescript/blob/81aacb165e0802e188f608bdf462b60fc4e713a2/src/direct_messages/client.ts#L340)

## Methods

### createByConversationId

▸ **createByConversationId**(`dmConversationId`, `options`): `Promise`\<`Response`>

Create DM message by conversation ID
Sends a new direct message to a specific conversation by its ID.

#### Parameters

| Name               | Type                                                                          | Description             |
| :----------------- | :---------------------------------------------------------------------------- | :---------------------- |
| `dmConversationId` | `string`                                                                      | The DM Conversation ID. |
| `options`          | `CreateByConversationIdOptions` & \{ `requestOptions`: \{ `raw`: `true`  }  } | -                       |

#### Returns

`Promise`\<`Response`>

Promise resolving to the API response, or raw Response if requestOptions.raw is true

#### Defined in

[direct\_messages/client.ts:385](https://github.com/xdevplatform/xdk-typescript/blob/81aacb165e0802e188f608bdf462b60fc4e713a2/src/direct_messages/client.ts#L385)

▸ **createByConversationId**(`dmConversationId`, `options?`): `Promise`\<[`CreateDmEventResponse`](/xdks/typescript/reference/interfaces/Schemas.CreateDmEventResponse)>

#### Parameters

| Name               | Type                            |
| :----------------- | :------------------------------ |
| `dmConversationId` | `string`                        |
| `options?`         | `CreateByConversationIdOptions` |

#### Returns

`Promise`\<[`CreateDmEventResponse`](/xdks/typescript/reference/interfaces/Schemas.CreateDmEventResponse)>

#### Defined in

[direct\_messages/client.ts:398](https://github.com/xdevplatform/xdk-typescript/blob/81aacb165e0802e188f608bdf462b60fc4e713a2/src/direct_messages/client.ts#L398)

***

### getEventsByConversationId

▸ **getEventsByConversationId**(`id`, `options`): `Promise`\<`Response`>

Get DM events for a DM conversation
Retrieves direct message events for a specific conversation.

#### Parameters

| Name      | Type                                                                             | Description             |
| :-------- | :------------------------------------------------------------------------------- | :---------------------- |
| `id`      | `string`                                                                         | The DM conversation ID. |
| `options` | `GetEventsByConversationIdOptions` & \{ `requestOptions`: \{ `raw`: `true`  }  } | -                       |

#### Returns

`Promise`\<`Response`>

Promise resolving to the API response, or raw Response if requestOptions.raw is true

#### Defined in

[direct\_messages/client.ts:506](https://github.com/xdevplatform/xdk-typescript/blob/81aacb165e0802e188f608bdf462b60fc4e713a2/src/direct_messages/client.ts#L506)

▸ **getEventsByConversationId**(`id`, `options?`): `Promise`\<[`Get2DmConversationsIdDmEventsResponse`](/xdks/typescript/reference/interfaces/Schemas.Get2DmConversationsIdDmEventsResponse)>

#### Parameters

| Name       | Type                               |
| :--------- | :--------------------------------- |
| `id`       | `string`                           |
| `options?` | `GetEventsByConversationIdOptions` |

#### Returns

`Promise`\<[`Get2DmConversationsIdDmEventsResponse`](/xdks/typescript/reference/interfaces/Schemas.Get2DmConversationsIdDmEventsResponse)>

#### Defined in

[direct\_messages/client.ts:519](https://github.com/xdevplatform/xdk-typescript/blob/81aacb165e0802e188f608bdf462b60fc4e713a2/src/direct_messages/client.ts#L519)

***

### createConversation

▸ **createConversation**(`options`): `Promise`\<`Response`>

Create DM conversation
Initiates a new direct message conversation with specified participants.

#### Parameters

| Name      | Type                                                                      |
| :-------- | :------------------------------------------------------------------------ |
| `options` | `CreateConversationOptions` & \{ `requestOptions`: \{ `raw`: `true`  }  } |

#### Returns

`Promise`\<`Response`>

Promise resolving to the API response, or raw Response if requestOptions.raw is true

#### Defined in

[direct\_messages/client.ts:784](https://github.com/xdevplatform/xdk-typescript/blob/81aacb165e0802e188f608bdf462b60fc4e713a2/src/direct_messages/client.ts#L784)

▸ **createConversation**(`options?`): `Promise`\<[`CreateDmEventResponse`](/xdks/typescript/reference/interfaces/Schemas.CreateDmEventResponse)>

#### Parameters

| Name       | Type                        |
| :--------- | :-------------------------- |
| `options?` | `CreateConversationOptions` |

#### Returns

`Promise`\<[`CreateDmEventResponse`](/xdks/typescript/reference/interfaces/Schemas.CreateDmEventResponse)>

#### Defined in

[direct\_messages/client.ts:793](https://github.com/xdevplatform/xdk-typescript/blob/81aacb165e0802e188f608bdf462b60fc4e713a2/src/direct_messages/client.ts#L793)

***

### getEventsByParticipantId

▸ **getEventsByParticipantId**(`participantId`, `options`): `Promise`\<`Response`>

Get DM events for a DM conversation
Retrieves direct message events for a specific conversation.

#### Parameters

| Name            | Type                                                                            | Description                                                        |
| :-------------- | :------------------------------------------------------------------------------ | :----------------------------------------------------------------- |
| `participantId` | `string`                                                                        | The ID of the participant user for the One to One DM conversation. |
| `options`       | `GetEventsByParticipantIdOptions` & \{ `requestOptions`: \{ `raw`: `true`  }  } | -                                                                  |

#### Returns

`Promise`\<`Response`>

Promise resolving to the API response, or raw Response if requestOptions.raw is true

#### Defined in

[direct\_messages/client.ts:889](https://github.com/xdevplatform/xdk-typescript/blob/81aacb165e0802e188f608bdf462b60fc4e713a2/src/direct_messages/client.ts#L889)

▸ **getEventsByParticipantId**(`participantId`, `options?`): `Promise`\<[`Get2DmConversationsWithParticipantIdDmEventsResponse`](/xdks/typescript/reference/interfaces/Schemas.Get2DmConversationsWithParticipantIdDmEventsResponse)>

#### Parameters

| Name            | Type                              |
| :-------------- | :-------------------------------- |
| `participantId` | `string`                          |
| `options?`      | `GetEventsByParticipantIdOptions` |

#### Returns

`Promise`\<[`Get2DmConversationsWithParticipantIdDmEventsResponse`](/xdks/typescript/reference/interfaces/Schemas.Get2DmConversationsWithParticipantIdDmEventsResponse)>

#### Defined in

[direct\_messages/client.ts:902](https://github.com/xdevplatform/xdk-typescript/blob/81aacb165e0802e188f608bdf462b60fc4e713a2/src/direct_messages/client.ts#L902)

***

### getEvents

▸ **getEvents**(`options`): `Promise`\<`Response`>

Get DM events
Retrieves a list of recent direct message events across all conversations.

#### Parameters

| Name      | Type                                                             |
| :-------- | :--------------------------------------------------------------- |
| `options` | `GetEventsOptions` & \{ `requestOptions`: \{ `raw`: `true`  }  } |

#### Returns

`Promise`\<`Response`>

Promise resolving to the API response, or raw Response if requestOptions.raw is true

#### Defined in

[direct\_messages/client.ts:1167](https://github.com/xdevplatform/xdk-typescript/blob/81aacb165e0802e188f608bdf462b60fc4e713a2/src/direct_messages/client.ts#L1167)

▸ **getEvents**(`options?`): `Promise`\<[`Get2DmEventsResponse`](/xdks/typescript/reference/interfaces/Schemas.Get2DmEventsResponse)>

#### Parameters

| Name       | Type               |
| :--------- | :----------------- |
| `options?` | `GetEventsOptions` |

#### Returns

`Promise`\<[`Get2DmEventsResponse`](/xdks/typescript/reference/interfaces/Schemas.Get2DmEventsResponse)>

#### Defined in

[direct\_messages/client.ts:1176](https://github.com/xdevplatform/xdk-typescript/blob/81aacb165e0802e188f608bdf462b60fc4e713a2/src/direct_messages/client.ts#L1176)

***

### getEventsById

▸ **getEventsById**(`eventId`, `options`): `Promise`\<`Response`>

Get DM event by ID
Retrieves details of a specific direct message event by its ID.

#### Parameters

| Name      | Type                                                                 | Description  |
| :-------- | :------------------------------------------------------------------- | :----------- |
| `eventId` | `string`                                                             | dm event id. |
| `options` | `GetEventsByIdOptions` & \{ `requestOptions`: \{ `raw`: `true`  }  } | -            |

#### Returns

`Promise`\<`Response`>

Promise resolving to the API response, or raw Response if requestOptions.raw is true

#### Defined in

[direct\_messages/client.ts:1433](https://github.com/xdevplatform/xdk-typescript/blob/81aacb165e0802e188f608bdf462b60fc4e713a2/src/direct_messages/client.ts#L1433)

▸ **getEventsById**(`eventId`, `options?`): `Promise`\<[`Get2DmEventsEventIdResponse`](/xdks/typescript/reference/interfaces/Schemas.Get2DmEventsEventIdResponse)>

#### Parameters

| Name       | Type                   |
| :--------- | :--------------------- |
| `eventId`  | `string`               |
| `options?` | `GetEventsByIdOptions` |

#### Returns

`Promise`\<[`Get2DmEventsEventIdResponse`](/xdks/typescript/reference/interfaces/Schemas.Get2DmEventsEventIdResponse)>

#### Defined in

[direct\_messages/client.ts:1446](https://github.com/xdevplatform/xdk-typescript/blob/81aacb165e0802e188f608bdf462b60fc4e713a2/src/direct_messages/client.ts#L1446)

***

### deleteEvents

▸ **deleteEvents**(`eventId`, `options`): `Promise`\<`Response`>

Delete DM event
Deletes a specific direct message event by its ID, if owned by the authenticated user.

#### Parameters

| Name                         | Type     | Description                                   |
| :--------------------------- | :------- | :-------------------------------------------- |
| `eventId`                    | `string` | The ID of the direct-message event to delete. |
| `options`                    | `Object` | -                                             |
| `options.requestOptions`     | `Object` | -                                             |
| `options.requestOptions.raw` | `true`   | -                                             |

#### Returns

`Promise`\<`Response`>

Promise resolving to the API response, or raw Response if requestOptions.raw is true

#### Defined in

[direct\_messages/client.ts:1656](https://github.com/xdevplatform/xdk-typescript/blob/81aacb165e0802e188f608bdf462b60fc4e713a2/src/direct_messages/client.ts#L1656)

▸ **deleteEvents**(`eventId`): `Promise`\<[`DeleteDmResponse`](/xdks/typescript/reference/interfaces/Schemas.DeleteDmResponse)>

#### Parameters

| Name      | Type     |
| :-------- | :------- |
| `eventId` | `string` |

#### Returns

`Promise`\<[`DeleteDmResponse`](/xdks/typescript/reference/interfaces/Schemas.DeleteDmResponse)>

#### Defined in

[direct\_messages/client.ts:1669](https://github.com/xdevplatform/xdk-typescript/blob/81aacb165e0802e188f608bdf462b60fc4e713a2/src/direct_messages/client.ts#L1669)

***

### createByParticipantId

▸ **createByParticipantId**(`participantId`, `options`): `Promise`\<`Response`>

Create DM message by participant ID
Sends a new direct message to a specific participant by their ID.

#### Parameters

| Name            | Type                                                                         | Description                                            |
| :-------------- | :--------------------------------------------------------------------------- | :----------------------------------------------------- |
| `participantId` | `string`                                                                     | The ID of the recipient user that will receive the DM. |
| `options`       | `CreateByParticipantIdOptions` & \{ `requestOptions`: \{ `raw`: `true`  }  } | -                                                      |

#### Returns

`Promise`\<`Response`>

Promise resolving to the API response, or raw Response if requestOptions.raw is true

#### Defined in

[direct\_messages/client.ts:1760](https://github.com/xdevplatform/xdk-typescript/blob/81aacb165e0802e188f608bdf462b60fc4e713a2/src/direct_messages/client.ts#L1760)

▸ **createByParticipantId**(`participantId`, `options?`): `Promise`\<[`CreateDmEventResponse`](/xdks/typescript/reference/interfaces/Schemas.CreateDmEventResponse)>

#### Parameters

| Name            | Type                           |
| :-------------- | :----------------------------- |
| `participantId` | `string`                       |
| `options?`      | `CreateByParticipantIdOptions` |

#### Returns

`Promise`\<[`CreateDmEventResponse`](/xdks/typescript/reference/interfaces/Schemas.CreateDmEventResponse)>

#### Defined in

[direct\_messages/client.ts:1773](https://github.com/xdevplatform/xdk-typescript/blob/81aacb165e0802e188f608bdf462b60fc4e713a2/src/direct_messages/client.ts#L1773)
