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

# 빠른 시작

> 다이렉트 메시지를 보내고 그룹 대화를 생성합니다

export const Button = ({href, children}) => {
  return <div className="not-prose group">
    <a href={href}>
      <button className="flex items-center space-x-2.5 py-1 px-4 bg-primary-dark dark:bg-white text-white dark:text-gray-950 rounded-full group-hover:opacity-[0.9] font-medium">
        <span>
          {children}
        </span>
        <svg width="3" height="24" viewBox="0 -9 3 24" class="h-6 rotate-0 overflow-visible"><path d="M0 0L3 3L0 6" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"></path></svg>
      </button>
    </a>
  </div>;
};

이 가이드는 다이렉트 메시지를 보내고 그룹 대화를 생성하는 방법을 단계별로 안내합니다.

<Note>
  **사전 준비 사항**

  시작하기 전에 다음이 필요합니다.

  * 승인된 App이 있는 [개발자 계정](https://developer.x.com/en/portal/petition/essential/basic-info)
  * `dm.write` 및 `dm.read` scope를 가진 User Access Token (OAuth 2.0 PKCE)
</Note>

***

<div id="send-a-one-to-one-message">
  ## 일대일 메시지 보내기
</div>

<Steps>
  <Step title="받는 사람의 사용자 ID 가져오기">
    메시지를 보내려는 사용자의 user ID가 필요합니다. 이 ID는 [사용자 조회 엔드포인트](/ko/x-api/users/lookup/introduction)에서 확인할 수 있습니다.
  </Step>

  <Step title="메시지 보내기">
    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl -X POST "https://api.x.com/2/dm_conversations/with/9876543210/messages" \
        -H "Authorization: Bearer $USER_ACCESS_TOKEN" \
        -H "Content-Type: application/json" \
        -d '{"text": "Hello! This is a message from the API."}'
      ```

      ```python Python SDK theme={null}
      from xdk import Client

      client = Client(bearer_token="YOUR_USER_ACCESS_TOKEN")

      # 일대일 메시지 보내기
      response = client.dm.send_message(
          participant_id="9876543210",
          text="Hello! This is a message from the API."
      )

      print(f"Message sent: {response.data.dm_event_id}")
      print(f"Conversation: {response.data.dm_conversation_id}")
      ```

      ```javascript JavaScript SDK theme={null}
      import { Client } from "@xdevplatform/xdk";

      const client = new Client({ accessToken: "YOUR_USER_ACCESS_TOKEN" });

      // 일대일 메시지 보내기
      const response = await client.dm.sendMessage({
        participantId: "9876543210",
        text: "Hello! This is a message from the API.",
      });

      console.log(`Message sent: ${response.data?.dm_event_id}`);
      console.log(`Conversation: ${response.data?.dm_conversation_id}`);
      ```
    </CodeGroup>
  </Step>

  <Step title="응답 검토하기">
    ```json theme={null}
    {
      "data": {
        "dm_conversation_id": "1234567890-9876543210",
        "dm_event_id": "1582103724607971332"
      }
    }
    ```
  </Step>
</Steps>

***

<div id="create-a-group-conversation">
  ## 그룹 대화 만들기
</div>

<Steps>
  <Step title="참가자 지정">
    그룹에 포함하고 싶은 사용자(본인은 제외)의 사용자 ID를 모읍니다.
  </Step>

  <Step title="첫 번째 메시지와 함께 그룹 생성">
    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl -X POST "https://api.x.com/2/dm_conversations" \
        -H "Authorization: Bearer $USER_ACCESS_TOKEN" \
        -H "Content-Type: application/json" \
        -d '{
          "conversation_type": "Group",
          "participant_ids": ["944480690", "906948460078698496"],
          "message": {"text": "Welcome to our new group!"}
        }'
      ```

      ```python Python SDK theme={null}
      from xdk import Client

      client = Client(bearer_token="YOUR_USER_ACCESS_TOKEN")

      # 그룹 대화 생성
      response = client.dm.create_conversation(
          conversation_type="Group",
          participant_ids=["944480690", "906948460078698496"],
          message={"text": "Welcome to our new group!"}
      )

      print(f"Group created: {response.data.dm_conversation_id}")
      ```

      ```javascript JavaScript SDK theme={null}
      import { Client } from "@xdevplatform/xdk";

      const client = new Client({ accessToken: "YOUR_USER_ACCESS_TOKEN" });

      // 그룹 대화 생성
      const response = await client.dm.createConversation({
        conversationType: "Group",
        participantIds: ["944480690", "906948460078698496"],
        message: { text: "Welcome to our new group!" },
      });

      console.log(`Group created: ${response.data?.dm_conversation_id}`);
      ```
    </CodeGroup>
  </Step>

  <Step title="대화 ID 받기">
    ```json theme={null}
    {
      "data": {
        "dm_conversation_id": "1582103724607971328",
        "dm_event_id": "1582103724607971332"
      }
    }
    ```

    나중에 더 많은 메시지를 추가할 수 있도록 `dm_conversation_id`를 저장합니다.
  </Step>
</Steps>

***

<div id="add-a-message-to-an-existing-conversation">
  ## 기존 대화에 메시지 추가하기
</div>

이미 참여 중인 대화에 메시지를 보냅니다:

<CodeGroup dropdown>
  ```bash cURL theme={null}
  curl -X POST "https://api.x.com/2/dm_conversations/1582103724607971328/messages" \
    -H "Authorization: Bearer $USER_ACCESS_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{"text": "Adding another message to the conversation."}'
  ```

  ```python Python SDK theme={null}
  from xdk import Client

  client = Client(bearer_token="YOUR_USER_ACCESS_TOKEN")

  # 기존 대화에 메시지 추가
  response = client.dm.send_message_to_conversation(
      dm_conversation_id="1582103724607971328",
      text="Adding another message to the conversation."
  )

  print(f"Message sent: {response.data.dm_event_id}")
  ```

  ```javascript JavaScript SDK theme={null}
  import { Client } from "@xdevplatform/xdk";

  const client = new Client({ accessToken: "YOUR_USER_ACCESS_TOKEN" });

  // 기존 대화에 메시지 추가
  const response = await client.dm.sendMessageToConversation(
    "1582103724607971328",
    { text: "Adding another message to the conversation." }
  );

  console.log(`Message sent: ${response.data?.dm_event_id}`);
  ```
</CodeGroup>

***

<div id="send-a-message-with-media">
  ## 미디어가 포함된 메시지 보내기
</div>

<Steps>
  <Step title="미디어 업로드하기">
    먼저 [Media Upload endpoint](/ko/x-api/media/quickstart/media-upload-chunked)를 사용해 미디어를 업로드합니다.
  </Step>

  <Step title="미디어를 첨부해 메시지 보내기">
    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl -X POST "https://api.x.com/2/dm_conversations/with/9876543210/messages" \
        -H "Authorization: Bearer $USER_ACCESS_TOKEN" \
        -H "Content-Type: application/json" \
        -d '{
          "text": "Check out this image!",
          "attachments": [{"media_id": "1234567890123456789"}]
        }'
      ```

      ```python Python SDK theme={null}
      from xdk import Client

      client = Client(bearer_token="YOUR_USER_ACCESS_TOKEN")

      # 미디어가 포함된 메시지 보내기
      response = client.dm.send_message(
          participant_id="9876543210",
          text="Check out this image!",
          attachments=[{"media_id": "1234567890123456789"}]
      )

      print(f"Message with media sent: {response.data.dm_event_id}")
      ```

      ```javascript JavaScript SDK theme={null}
      import { Client } from "@xdevplatform/xdk";

      const client = new Client({ accessToken: "YOUR_USER_ACCESS_TOKEN" });

      // 미디어가 포함된 메시지 보내기
      const response = await client.dm.sendMessage({
        participantId: "9876543210",
        text: "Check out this image!",
        attachments: [{ mediaId: "1234567890123456789" }],
      });

      console.log(`Message with media sent: ${response.data?.dm_event_id}`);
      ```
    </CodeGroup>
  </Step>
</Steps>

***

<div id="delete-a-message">
  ## 메시지 삭제
</div>

보낸 메시지를 삭제하려면:

<CodeGroup dropdown>
  ```bash cURL theme={null}
  curl -X DELETE "https://api.x.com/2/dm_events/1582103724607971332" \
    -H "Authorization: Bearer $USER_ACCESS_TOKEN"
  ```

  ```python Python SDK theme={null}
  from xdk import Client

  client = Client(bearer_token="YOUR_USER_ACCESS_TOKEN")

  # 메시지 삭제
  response = client.dm.delete_message("1582103724607971332")
  print(f"Deleted: {response.data.deleted}")
  ```

  ```javascript JavaScript SDK theme={null}
  import { Client } from "@xdevplatform/xdk";

  const client = new Client({ accessToken: "YOUR_USER_ACCESS_TOKEN" });

  // 메시지 삭제
  const response = await client.dm.deleteMessage("1582103724607971332");
  console.log(`Deleted: ${response.data?.deleted}`);
  ```
</CodeGroup>

**응답:**

```json theme={null}
{
  "data": {
    "deleted": true
  }
}
```

<Warning>
  본인이 보낸 메시지만 삭제할 수 있으며, 다른 참가자가 보낸 메시지는 삭제할 수 없습니다.
</Warning>

***

<div id="required-scopes">
  ## 필요한 scope
</div>

OAuth 2.0 PKCE를 사용할 때는 액세스 토큰에 다음 scope를 포함해야 합니다:

| Scope        | 설명                        |
| :----------- | :------------------------ |
| `dm.write`   | 메시지 전송 및 삭제               |
| `dm.read`    | 대화 읽기 (`dm.write`와 함께 필요) |
| `tweet.read` | 일부 expansions에 필요         |
| `users.read` | 사용자 expansions에 필요        |

***

<div id="next-steps">
  ## 다음 단계
</div>

<CardGroup cols={2}>
  <Card title="DM 조회" icon="inbox" href="/ko/x-api/direct-messages/lookup/quickstart">
    DM 대화 조회
  </Card>

  <Card title="통합 가이드" icon="book" href="/ko/x-api/direct-messages/manage/integrate">
    핵심 개념과 모범 사례
  </Card>

  <Card title="API 참조 문서" icon="code" href="/ko/x-api/direct-messages/create-dm-message-by-participant-id">
    전체 엔드포인트 문서
  </Card>

  <Card title="샘플 코드" icon="github" href="https://github.com/xdevplatform/Twitter-API-v2-sample-code">
    동작하는 코드 예제
  </Card>
</CardGroup>
