# JAVA 샘플 코드 

# 세션 API

### 세션 생성

벨루가 채널 세션(방)을 생성합니다.

```javascript
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;

public class VelugaApiClient {
    public static void main(String[] args) {
        String apiKey = "[YOUR_API_KEY]";
        String channelId = "[YOUR_CHANNEL_ID]";
        String eventId = "[OPTIONAL_EVENT_ID]";
        String eventValue = "[OPTIONAL_EVENT_VALUE]";
        
        String apiUrl = "[DOMAIN]/api/v1/session";
        String jsonPayload = String.format("{\"channelId\": \"%s\", \"eventId\": \"%s\", \"eventValue\": \"%s\"}",
                channelId, eventId, eventValue);

        try {
            URL url = new URL(apiUrl);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("POST");
            conn.setRequestProperty("X-VELUGA-API-KEY", apiKey);
            conn.setRequestProperty("Content-Type", "application/json");
            conn.setDoOutput(true);

            try (OutputStream os = conn.getOutputStream()) {
                byte[] input = jsonPayload.getBytes(StandardCharsets.UTF_8);
                os.write(input, 0, input.length);
            }

            int responseCode = conn.getResponseCode();
            System.out.println("Response Code: " + responseCode);
            
            if (responseCode == HttpURLConnection.HTTP_OK) {
                System.out.println("Session created successfully.");
            } else {
                System.out.println("Failed to create session.");
            }

            conn.disconnect();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

```

### 세션 리스트

채널 세션(방) 리스트를 가져옵니다

```javascript
curl -X GET "https://usamsung-api.veluga.app/api/v1/session" \
     -H "X-VELUGA-API-KEY: [YOUR_API_KEY]" \
     -G \
     -d "channelId=[YOUR_CHANNEL_ID]" \
     -d "eventId=[OPTIONAL_EVENT_ID]" \
     -d "eventValue=[OPTIONAL_EVENT_VALUE]" \
     -d "page=[PAGE_NUMBER]" \
     -d "limit=[LIMIT_NUMBER]" \
     -d "sort=[SORT_ORDER]"
```

# 채팅 API

### 채팅 히스토리

채팅 히스토리를 가져옵니다.

```javascript
curl -X GET "/api/v1/chat/history" \
     -H "X-VELUGA-API-KEY: [YOUR_API_KEY]" \
     -G \
     -d "sessionId=[YOUR_SESSION_ID]" \
     -d "page=[PAGE_NUMBER]" \
     -d "limit=[LIMIT_NUMBER]" \
     -d "sort=[SORT_ORDER]"
```

# 학습 API

## 파일 학습 요청

파일 학습을 요청합니다.
업로드 시 AI 서버에 학습 요청을 하고, 학습 결과를 조회하여 AI를 통해 확인할 수 있습니다.

```javascript
curl -X POST "/api/v2/document/file" \
     -H "X-VELUGA-API-KEY: [YOUR_API_KEY]" \
     -H "Content-Type: multipart/form-data" \
     -F "channelId=[YOUR_CHANNEL_ID]" \
     -F "file=@[PATH_TO_YOUR_FILE]"
```

## 파일 리스트 조회

학습 요청 된 파일 리스트를 조회합니다.

```javascript
curl -X GET "/api/v1/document/file" \
     -H "X-VELUGA-API-KEY: [YOUR_API_KEY]" \
     -G \
     -d "channelId=[YOUR_CHANNEL_ID]" \
     -d "keyword=[OPTIONAL_KEYWORD]" \
     -d "page=[PAGE_NUMBER]" \
     -d "limit=[LIMIT_NUMBER]" \
     -d "sortType=[SORT_TYPE]" \
     -d "sort=[SORT_ORDER]"
```

## 파일 개별 조회

학습 요청 된 파일을 개별 조회합니다.

```javascript
curl -X GET "/api/v1/document/file/{id}" \
     -H "X-VELUGA-API-KEY: [YOUR_API_KEY]"
```

## 학습 파일 삭제

학습한 파일을 삭제 요청합니다.

```javascript
curl -X DELETE "/api/v2/document/file/{id}" \
     -H "X-VELUGA-API-KEY: [YOUR_API_KEY]"
```

## WEB URL 학습 요청

web url 학습을 요청합니다.
동적 렌더링을 사용하는 Web은 학습이 원활하지 않을 수 있습니다.

```javascript
curl -X POST "/api/v1/document/web-url" \
     -H "X-VELUGA-API-KEY: [YOUR_API_KEY]" \
     -H "Content-Type: application/json" \
     -d '{
           "channelId": "[YOUR_CHANNEL_ID]",
           "webUrl": "[URL_TO_LEARN]"
         }'
```

## 학습 WEB URL 리스트 조회

학습 요청 된 Web Url 리스트를 조회합니다.

```javascript
curl -X POST "/api/v1/document/web-url" \
     -H "X-VELUGA-API-KEY: [YOUR_API_KEY]" \
     -H "Content-Type: application/json" \
     -d '{
           "channelId": "[YOUR_CHANNEL_ID]",
           "webUrl": "[URL_TO_LEARN]"
         }'
```

## 학습 WEB URL 개별 조회

학습 요청 된 Web Url를 개별 조회합니다.

```javascript
curl -X GET "/api/v1/document/web-url/{id}" \
     -H "X-VELUGA-API-KEY: [YOUR_API_KEY]"
```

## 학습 WEB URL 삭제

학습 된 Web Url 삭제 요청합니다.

```javascript
curl -X GET "/api/v1/document/web-url/{id}" \
     -H "X-VELUGA-API-KEY: [YOUR_API_KEY]"
```

## 게시물 학습 요청

게시물 학습을 요청합니다.
html 콘텐츠를 직접 전달 받아 학습합니다.

```javascript
curl -X POST "/api/v1/document/post" \
     -H "X-VELUGA-API-KEY: [YOUR_API_KEY]" \
     -H "Content-Type: application/json" \
     -d '{
           "channelId": "[YOUR_CHANNEL_ID]",
           "title": "[YOUR_TITLE]",
           "content": "[YOUR_HTML_CONTENT]",
           "board": "[YOUR_BOARD]",
           "fromUrl": "[YOUR_FROM_URL]",
           "attachments": [
            {
              "name": "string",
              "fileUrl": "string"
            }
           ],
           "regDatetime": "[YOUR_REG_DATETIME]",
           "metadata": {
               "author": "[AUTHOR_NAME]",
               "attachment": "[ATTACHMENT_FILENAME]"
           },
           "docFilter": {
               "filter1": "[FILTER_VALUE1]",
               "filter2": "[FILTER_VALUE2]"
           }
         }'
```

## 게시물 리스트 조회

학습 요청된 게시물 리스트를 조회합니다.

```javascript
curl -X GET "/api/v1/document/post" \
     -H "X-VELUGA-API-KEY: [YOUR_API_KEY]" \
     -G \
     -d "channelId=[YOUR_CHANNEL_ID]" \
     -d "keyword=[OPTIONAL_KEYWORD]" \
     -d "boardName=[OPTIONAL_BOARD_NAME]" \
     -d "page=[PAGE_NUMBER]" \
     -d "limit=[LIMIT_NUMBER]" \
     -d "sortType=[SORT_TYPE]" \
     -d "sort=[SORT_ORDER]"
```

## 게시물 개별 조회

학습 요청 된 게시물을 개별 조회합니다.

```javascript
curl -X GET "/api/v1/document/post/{id}" \
     -H "X-VELUGA-API-KEY: [YOUR_API_KEY]"
```

## 학습 게시물 삭제 

학습한 게시물을 삭제 요청합니다.

```javascript
curl -X DELETE "/api/v2/document/post/{id}" \
     -H "X-VELUGA-API-KEY: [YOUR_API_KEY]"
```

# 채널 API

## 채널 리스트 조회

채널 리스트를 조회 합니다.

```javascript
curl -X GET "/api/v1/channel" \
     -H "X-VELUGA-API-KEY: [YOUR_API_KEY]" 
```

## 채널 개별 조회

채널을 개별 조회합니다.

```javascript
curl -X GET "/api/v1/channel/{id}" \
     -H "X-VELUGA-API-KEY: [YOUR_API_KEY]"
```

## 채널 생성 API

이 API는 사용자가 제공한 정보로 새로운 채널을 생성합니다. 추가적으로 채널의 성격(temperature), 답변 타입(answerType) 등을 설정할 수 있습니다. 이 API는 인증된 사용자가 접근해야 하며, Bearer Token 보안 방식이 적용됩니다.

```javascript
curl -X POST "/api/v1/channel"
     -H "X-VELUGA-API-KEY: your_api_key_here"
     -H "Content-Type: application/json"
     -d '{
           "name": "개발팀채널",
           "description": "개발팀 채널입니다.",
           "welcomeMessage": "안녕하세요. 개발팀 채널입니다.",
           "temperature": "inFact",
           "answerTypeIfCant": ["advice", "managerPhone"],
           "answerType": ""respectful, long and detailed"",
           "languages": "korean",
           "isPublic": false,
           "enableQuestionHint": true,
           "enableFollowQuestion": true,
           "shouldReturnFile": true,
           "searchModel": "hybrid",
           "channelTemplateId": "660f83012c068b20e130781b"
         }'
```

## 채널 사용량 조회

채널 사용량을 조회합니다.

```javascript
curl -X GET "/api/v1/channel/{id}/usage" \
     -H "X-VELUGA-API-KEY: [YOUR_API_KEY]"
```

# 계정 API

## 계정 정보 조회

내 계정의 정보를 조회합니다.

```javascript
curl -X GET "/api/v1/user/me" \
     -H "X-VELUGA-API-KEY: [YOUR_API_KEY]"
```

For the site tree, see the [root Markdown](https://slashpage.com/veluga-api.md).
