|
| 1 | +# SOLAPI Kotlin SDK - Knowledge Base |
| 2 | + |
| 3 | +**Generated:** 2026-01-27 | **Commit:** 618f129 | **Branch:** main |
| 4 | + |
| 5 | +## CRITICAL: Development Principles |
| 6 | + |
| 7 | +**MUST follow `CLAUDE.md` development principles:** |
| 8 | + |
| 9 | +| Principle | Rule | |
| 10 | +|-----------|------| |
| 11 | +| **Tidy First** | NEVER mix structural and behavioral changes in a single commit | |
| 12 | +| **Commit Separation** | `refactor:` (structural) vs `feat:`/`fix:` (behavioral) in separate commits | |
| 13 | +| **TDD** | Write tests first (Red → Green → Refactor) | |
| 14 | +| **Single Responsibility** | Classes/methods have single responsibility only | |
| 15 | +| **Tidy Code First** | Clean up target area code before adding features | |
| 16 | + |
| 17 | +```bash |
| 18 | +# Correct commit order |
| 19 | +git commit -m "refactor: extract validation logic to separate method" |
| 20 | +git commit -m "feat: add phone number format validation" |
| 21 | + |
| 22 | +# Forbidden (mixed commit) |
| 23 | +git commit -m "feat: add validation and refactor code" # ❌ FORBIDDEN |
| 24 | +``` |
| 25 | + |
| 26 | +--- |
| 27 | + |
| 28 | +## OVERVIEW |
| 29 | + |
| 30 | +Kotlin/Java SDK for SOLAPI messaging platform. Supports SMS, LMS, MMS, Kakao Alimtalk/Brand Message, Naver Smart Notification, RCS, Fax, and Voice messaging. |
| 31 | + |
| 32 | +## STRUCTURE |
| 33 | + |
| 34 | +``` |
| 35 | +src/main/java/com/solapi/sdk/ |
| 36 | +├── SolapiClient.kt # Entry point (use this) |
| 37 | +├── NurigoApp.kt # DEPRECATED - do not use |
| 38 | +└── message/ |
| 39 | + ├── service/ # API operations (send, query, templates) |
| 40 | + ├── model/ # Domain models (Message, options) |
| 41 | + │ └── kakao/ # 19 files - Kakao templates, buttons, options |
| 42 | + ├── dto/ # Request/Response DTOs |
| 43 | + ├── exception/ # Exception hierarchy (8 types) |
| 44 | + └── lib/ # Internal utilities (auth, helpers) |
| 45 | +``` |
| 46 | + |
| 47 | +## WHERE TO LOOK |
| 48 | + |
| 49 | +| Task | Location | Notes | |
| 50 | +|------|----------|-------| |
| 51 | +| **Initialize SDK** | `SolapiClient.kt` | `createInstance(apiKey, secretKey)` | |
| 52 | +| **Send messages** | `service/DefaultMessageService.kt` | `send(message)` or `send(messages)` | |
| 53 | +| **Query messages** | `service/DefaultMessageService.kt` | `getMessageList(params)` | |
| 54 | +| **Upload files** | `service/DefaultMessageService.kt` | `uploadFile(file, type)` for MMS/Fax | |
| 55 | +| **Kakao Alimtalk** | `service/DefaultMessageService.kt` | 11 template methods | |
| 56 | +| **Create Message** | `model/Message.kt` | Data class with all message options | |
| 57 | +| **Kakao options** | `model/kakao/KakaoOption.kt` | Alimtalk/FriendTalk config | |
| 58 | +| **Handle errors** | `exception/` | Catch specific `Solapi*Exception` types | |
| 59 | +| **HTTP layer** | `service/MessageHttpService.kt` | Retrofit interface (internal) | |
| 60 | +| **Auth** | `lib/Authenticator.kt` | HMAC-SHA256 (internal, auto-injected) | |
| 61 | + |
| 62 | +## CODE PATTERNS |
| 63 | + |
| 64 | +### Serialization |
| 65 | +```kotlin |
| 66 | +@Serializable |
| 67 | +data class Message( |
| 68 | + var to: String? = null, |
| 69 | + var from: String? = null, |
| 70 | + // All fields nullable with defaults for flexibility |
| 71 | +) |
| 72 | +``` |
| 73 | +- **ALWAYS** use `@Serializable` annotation |
| 74 | +- **ALWAYS** use `kotlinx.serialization` (not Jackson/Gson) |
| 75 | +- **ALWAYS** provide nullable fields with defaults |
| 76 | + |
| 77 | +### Service Methods |
| 78 | +```kotlin |
| 79 | +@JvmOverloads // Java interop |
| 80 | +@Throws(SolapiMessageNotReceivedException::class, ...) |
| 81 | +fun send(messages: List<Message>, config: SendRequestConfig? = null): MultipleDetailMessageSentResponse |
| 82 | +``` |
| 83 | +- **ALWAYS** annotate with `@JvmOverloads` for optional params |
| 84 | +- **ALWAYS** declare `@Throws` for checked exceptions |
| 85 | + |
| 86 | +### Exception Handling |
| 87 | +```kotlin |
| 88 | +// Internal: Map error codes to exceptions |
| 89 | +when (errorResponse.errorCode) { |
| 90 | + "ValidationError" -> throw SolapiBadRequestException(msg) |
| 91 | + "InvalidApiKey" -> throw SolapiInvalidApiKeyException(msg) |
| 92 | + else -> throw SolapiUnknownException(msg) |
| 93 | +} |
| 94 | +``` |
| 95 | +- Exceptions are `sealed interface` based (SolapiException) |
| 96 | +- 8 specific exception types |
| 97 | + |
| 98 | +### Phone Number Normalization |
| 99 | +```kotlin |
| 100 | +init { |
| 101 | + from = from?.replace("-", "") |
| 102 | + to = to?.replace("-", "") |
| 103 | +} |
| 104 | +``` |
| 105 | +- Dashes auto-stripped from phone numbers in `Message.init` |
| 106 | + |
| 107 | +### Test Conventions |
| 108 | +```kotlin |
| 109 | +import kotlin.test.Test |
| 110 | +import kotlin.test.assertEquals |
| 111 | +import kotlin.test.assertTrue |
| 112 | +import kotlin.test.assertFailsWith |
| 113 | + |
| 114 | +class AuthenticatorTest { |
| 115 | + @Test |
| 116 | + fun `generateAuthInfo returns HMAC-SHA256 format`() { |
| 117 | + // Given |
| 118 | + val authenticator = Authenticator("api-key", "secret") |
| 119 | + // When |
| 120 | + val result = authenticator.generateAuthInfo() |
| 121 | + // Then |
| 122 | + assertTrue(result.startsWith("HMAC-SHA256 ")) |
| 123 | + } |
| 124 | +} |
| 125 | +``` |
| 126 | +- **ALWAYS** use `kotlin.test` (NOT JUnit directly) |
| 127 | +- **ALWAYS** use Given-When-Then comment structure |
| 128 | +- **ALWAYS** use backtick method names for readability |
| 129 | + |
| 130 | +## ANTI-PATTERNS |
| 131 | + |
| 132 | +| Forbidden | Required | |
| 133 | +|-----------|----------| |
| 134 | +| `NurigoApp.initialize()` | `SolapiClient.createInstance()` | |
| 135 | +| Direct `DefaultMessageService()` | Use factory via `SolapiClient` | |
| 136 | +| Catch generic `Exception` | Catch specific `Solapi*Exception` | |
| 137 | +| `net.nurigo.sdk` imports | `com.solapi.sdk` package only | |
| 138 | +| Jackson/Gson serialization | `kotlinx.serialization` only | |
| 139 | +| Mixed structural+behavioral commits | Separate commits per Tidy First | |
| 140 | + |
| 141 | +## INTERNAL CLASSES (Do Not Use Directly) |
| 142 | + |
| 143 | +- `Authenticator` - HMAC auth (auto-injected via interceptor) |
| 144 | +- `ErrorResponse` - Internal error DTO |
| 145 | +- `MessageHttpService` - Retrofit interface |
| 146 | +- `JsonSupport` - Serialization config |
| 147 | +- `MapHelper`, `Criterion` - Internal utilities |
| 148 | + |
| 149 | +## EXCEPTION TYPES |
| 150 | + |
| 151 | +| Exception | When Thrown | |
| 152 | +|-----------|-------------| |
| 153 | +| `SolapiApiKeyException` | Empty/missing API key | |
| 154 | +| `SolapiInvalidApiKeyException` | Invalid credentials | |
| 155 | +| `SolapiBadRequestException` | Validation error, bad input | |
| 156 | +| `SolapiEmptyResponseException` | Server returned empty body | |
| 157 | +| `SolapiFileUploadException` | File upload failed | |
| 158 | +| `SolapiMessageNotReceivedException` | All messages failed (has `failedMessageList`) | |
| 159 | +| `SolapiUnknownException` | Unclassified server error | |
| 160 | + |
| 161 | +## KAKAO INTEGRATION |
| 162 | + |
| 163 | +19 model files in `model/kakao/`: |
| 164 | +- `KakaoOption` - Main config (pfId, templateId, variables) |
| 165 | +- `KakaoAlimtalkTemplate*` - Template CRUD models |
| 166 | +- `KakaoBrandMessageTemplate` - Brand message with carousels |
| 167 | +- `KakaoButton`, `KakaoButtonType` - Button configurations |
| 168 | + |
| 169 | +Template workflow: `getKakaoAlimtalkTemplateCategories()` → `createKakaoAlimtalkTemplate()` → `requestKakaoAlimtalkTemplateInspection()` |
| 170 | + |
| 171 | +## BUILD & TEST |
| 172 | + |
| 173 | +```bash |
| 174 | +./gradlew clean build test # Full build |
| 175 | +./gradlew test # Tests only |
| 176 | +./gradlew shadowJar # Fat JAR with relocated deps |
| 177 | +``` |
| 178 | + |
| 179 | +**Shadow JAR**: Dependencies relocated to `com.solapi.shadow.*` to prevent conflicts. |
| 180 | + |
| 181 | +## NOTES |
| 182 | + |
| 183 | +- **Java 8 target**: Code must work on JVM 1.8 |
| 184 | +- **Source location**: Kotlin in `src/main/java/` (unconventional but intentional) |
| 185 | +- **Tests**: `src/test/kotlin/`, `kotlin.test` (Kotlin native), Given-When-Then style |
| 186 | +- **Version**: Auto-generated at `build/generated/source/kotlin/com/solapi/sdk/Version.kt` |
| 187 | +- **Docs**: Dokka output to `./docs/`, run `./gradlew dokkaGeneratePublicationHtml` |
0 commit comments