# การผสานรวมด้วย AI

> รวม 2328.io เข้ากับแอปพลิเคชันของคุณภายในไม่กี่นาทีโดยใช้ผู้ช่วย AI เช่น Claude, ChatGPT, Cursor และ GitHub Copilot

เอกสาร 2328.io ถูกออกแบบให้เป็น **LLM-friendly** คุณสามารถส่งเอกสารอ้างอิง API ทั้งหมดให้ผู้ช่วย AI สมัยใหม่ตัวใดก็ได้ และให้มันสร้างการ integrate ที่ใช้งานได้ในภาษาที่คุณเลือก — PHP, Node.js, Python, Go, Rust — ภายในไม่กี่นาทีแทนที่จะเป็นชั่วโมง

หน้านี้อธิบายวิธีทำอย่างมีประสิทธิภาพ

## ทำไมจึงควรใช้ AI ในการ integrate

- **เริ่มต้นได้เร็วขึ้น** — ข้าม boilerplate ตรงไปยัง business logic
- **การลงลายเซ็นที่ถูกต้อง** — AI สามารถสร้างการลงลายเซ็น HMAC-SHA256 ได้อย่างน่าเชื่อถือในทุกภาษา
- **ตัวจัดการ Webhook** — สร้างการตรวจสอบลายเซ็นและตัวจัดการแบบ idempotent ได้ในทันที
- **ทันสมัย** — `llms-full.txt` ของเราถูก regenerate ทุกครั้งที่อัปเดตเอกสาร คุณจึงได้ schema ปัจจุบันเสมอ

## เอกสารที่อ่านได้ด้วยเครื่อง

เราเผยแพร่ endpoint สามตัวตามมาตรฐาน [llmstxt.org](https://llmstxt.org):

| Endpoint | Purpose |
|----------|---------|
| [`/llms.txt`](https://doc.2328.io/llms.txt) | ดัชนีย่อของเอกสารทั้งหมดพร้อมลิงก์ |
| [`/llms-full.txt`](https://doc.2328.io/llms-full.txt) | เอกสารฉบับเต็มเป็นไฟล์เดียว — วางลงในแชต AI ของคุณได้เลย |
| [`/md/{locale}/{slug}`](https://doc.2328.io/md/en/payments) | หน้าใดก็ตามในรูปแบบ Markdown ดิบ |

ทุกหน้า HTML ยังเปิดเผย `<link rel="alternate" type="text/markdown">` ที่ชี้ไปยังเวอร์ชัน Markdown เพื่อให้ AI crawler ค้นพบโดยอัตโนมัติ

## เริ่มต้นอย่างรวดเร็วด้วย Claude หรือ ChatGPT

### ขั้นที่ 1 — ส่งเอกสารให้

เปิดแชตใหม่และวางเนื้อหาของ [`llms-full.txt`](https://doc.2328.io/llms-full.txt) เป็นข้อความแรก หรือเพียงแบ่งปันลิงก์ถ้าโมเดลสามารถ fetch ได้

### ขั้นที่ 2 — อธิบาย stack ของคุณ

บอกผู้ช่วยว่าคุณกำลังสร้างอะไร:

```
I'm building a Laravel 11 application. I need to:
1. Create a payment for an order (amount in USD, user pays in USDT TRC20)
2. Handle the webhook and credit the user's balance
3. Store payment records in a `payments` table

Use the 2328.io API above. Include HMAC signing, webhook signature
verification, and idempotency.
```

### ขั้นที่ 3 — รีวิวและทดสอบ

ผู้ช่วยจะสร้าง controller, service class และ webhook handler ก่อนนำไปใช้:

- ตรวจสอบว่า `apiSign()` เข้ารหัส body เป็น Base64 **ก่อน** HMAC-SHA256
- ตรวจสอบว่าตัวจัดการ Webhook เรียก `hash_equals()` (ไม่ใช่ `===`) เพื่อเปรียบเทียบลายเซ็น
- ตรวจสอบว่าตัวจัดการเป็นแบบ idempotent — ตรวจ `order_id` / `txid` ก่อนเครดิต
- ทดสอบด้วยการชำระเงินจริงจำนวนเล็กน้อยบนสภาพแวดล้อม dev ก่อน

> **WARNING:** อย่านำโค้ดการชำระเงินที่สร้างโดย AI ขึ้นโปรดักชันโดยไม่รีวิว logic ของการลงลายเซ็นและการตรวจสอบ Webhook ส่วนเหล่านี้คือขอบเขตด้านความปลอดภัยที่สำคัญที่สุด

## การ integrate กับ IDE

### Cursor

เพิ่มเอกสารเป็น docs source ใน Cursor settings:

```
Settings → Features → Docs → Add new doc
URL: https://doc.2328.io
```

จากนั้นในแชต ขึ้นต้นคำถามด้วย `@2328.io`:

```
@2328.io generate a webhook handler in Next.js App Router
with signature verification and idempotent credit logic
```

### GitHub Copilot

Copilot Chat สามารถอ่าน `llms-full.txt` ได้โดยตรง:

```
#fetch https://doc.2328.io/llms-full.txt

Using the 2328.io API docs above, implement a payout endpoint
in Express that withdraws USDT BEP20 to a user-supplied address.
```

### Windsurf / Continue / ผู้ช่วยอื่น ๆ

ผู้ช่วยใด ๆ ที่รองรับการแนบ URL หรือไฟล์ก็ใช้วิธีเดียวกัน — แนบ `llms-full.txt` แล้วอธิบายเป้าหมายของคุณ

## Claude API (Agent SDK)

หากคุณกำลังสร้าง agent หรือ chatbot ของคุณเองที่ต้องโต้ตอบกับ 2328.io ให้ inject เอกสารหนึ่งครั้งเข้าไปใน system prompt:

```python
from anthropic import Anthropic
import urllib.request

docs = urllib.request.urlopen(
    "https://doc.2328.io/llms-full.txt"
).read().decode()

client = Anthropic()

response = client.messages.create(
    model="claude-opus-4-7",
    max_tokens=4096,
    system=f"""You are an integration assistant for 2328.io.
Use the API reference below to answer questions and generate code.

<docs>
{docs}
</docs>""",
    messages=[
        {"role": "user", "content": "Write a Python function that creates a USDT payment"}
    ],
)

print(response.content[0].text)
```

> **INFO:** ไฟล์เอกสารฉบับเต็มมีขนาดประมาณ 15 KB — น้อยกว่าขนาด context limit ของโมเดลสมัยใหม่มาก คุณสามารถ cache ไว้ฝั่งคุณเองและรีเฟรชวันละครั้งได้

## ตัวอย่าง prompt ที่ใช้ได้ดี

คัดลอกเหล่านี้ไปยัง Claude, ChatGPT หรือ AI IDE ของคุณหลังจากแบ่งปัน `llms-full.txt`:

**Full backend integration:**
```
Build a Node.js + Express service that exposes two routes:
- POST /checkout → creates a 2328.io payment and returns the payment URL
- POST /webhook/2328 → verifies the signature and marks the order as paid
Use TypeScript, Zod for validation, and a simple in-memory store.
```

**Payout tool:**
```
Write a CLI in Go that takes a currency, network, amount, and address
and creates a payout via the 2328.io Payout API. Use a separate payout
API key from env. Poll the status endpoint until the payout is completed.
```

**Static wallet for user deposits:**
```
I have a Django app where users deposit USDT TRC20 to top up their balance.
Each user should have a permanent deposit address. Implement this using
2328.io static wallets, including the webhook handler that credits their
balance when a deposit arrives.
```

## แนวปฏิบัติที่ดีสำหรับการ integrate ที่ใช้ AI ช่วย

- **เริ่มจาก `llms-full.txt`** — ออกแบบมาเพื่อ context ของ LLM โดยไม่มี boilerplate
- **เจาะจงเกี่ยวกับ stack ของคุณ** — framework, เวอร์ชันภาษา, ORM
- **ขอเทสต์** — AI ทำได้ดีในการสร้าง unit test สำหรับ logic การลงลายเซ็น
- **ตรวจสอบการจัดการ error อย่างละเอียด** — บางครั้ง AI ข้ามเส้นทางการล้มเหลว
- **รีวิวโค้ดลายเซ็นด้วยตนเอง** — นี่เป็นส่วนเดียวที่*ต้อง*ถูกต้องเป๊ะ ๆ
- **รีเฟรชเป็นระยะ** — ถ้า API ของเราเปลี่ยน ให้ refetch `llms-full.txt` แล้ว prompt ใหม่