@noti-bot/sdk 0.12.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -2
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +2 -0
- package/dist/index.d.ts +33 -1
- package/dist/index.js +45 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -97,7 +97,7 @@ await bot.sendMessage({
|
|
|
97
97
|
- 같은 `requestId`로 다시 보내면 중복으로 처리합니다. 같은 `requestId`에 다른 파일이면 `idempotency_conflict`.
|
|
98
98
|
- 이미지 메시지는 수정할 수 없습니다(REST `PATCH /v1/messages/{requestId}`는 `edit_not_supported`). 삭제와 공감은 됩니다.
|
|
99
99
|
|
|
100
|
-
거절은 `NotiBotApiError`의 `code`로 옵니다: `image_url_not_allowed`(보낼 수 없는 주소), `image_fetch_failed`(받지 못함, HTTP 422), `image_too_large`, `unsupported_image`, `image_send_disabled`(서비스에서 꺼져 있음), `image_busy`(잠시 뒤 다시), `image_processing_unavailable`(HTTP 503, `retryAfterMs` 뒤 다시).
|
|
100
|
+
거절은 `NotiBotApiError`의 `code`로 옵니다: `image_url_not_allowed`(보낼 수 없는 주소), `image_fetch_failed`(받지 못함, HTTP 422), `image_too_large`, `unsupported_image`, `image_send_disabled`(서비스에서 꺼져 있음), `plan_image_not_allowed`(이미지를 보낼 수 없는 플랜), `image_busy`(잠시 뒤 다시), `image_processing_unavailable`(HTTP 503, `retryAfterMs` 뒤 다시).
|
|
101
101
|
|
|
102
102
|
## 이름으로 태그
|
|
103
103
|
|
|
@@ -120,6 +120,22 @@ if (target) await bot.sendMessage({ roomSlug: "tf", text: `${target.mention} 확
|
|
|
120
120
|
|
|
121
121
|
그 방에 없는 사람이면 `mention_unresolved`로 발송되지 않습니다. 상황에 따라 태그 없이 `@이름` 글자로만 나갈 수 있습니다.
|
|
122
122
|
|
|
123
|
+
## "입력 중" 표시
|
|
124
|
+
|
|
125
|
+
답을 만드는 데 시간이 걸릴 때(AI 응답 등) `setTyping`을 먼저 부르면, 방 사람들에게 봇이 "입력 중"으로 보입니다. 준비되면 `sendMessage`로 보내세요. 메시지가 나가면 표시는 바로 꺼집니다.
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
await bot.setTyping({ room: event.room }); // 웹훅의 방 이름, 10초
|
|
129
|
+
// 또는 { roomSlug: "tf" } / { roomId: "…" }
|
|
130
|
+
const answer = await generateAnswer(event.content); // 오래 걸리는 작업
|
|
131
|
+
await bot.sendMessage({ room: event.room, text: answer, replyTo: event.messageId });
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
- `durationSeconds`(1~30, 기본 10)초 동안 보입니다. 더 오래 걸리면 끝나기 전에 다시 부르세요. 다시 부르면 그때부터 다시 셉니다.
|
|
135
|
+
- 접수만 하고 기다리지 않습니다. 상대 화면에 보였는지는 카카오톡이 알려 주지 않고, 봇폰이 연결돼 있지 않으면 조용히 건너뜁니다. 실패해도 발송에는 영향이 없으니 결과를 기다리지 않아도 됩니다.
|
|
136
|
+
- `messages:send` 권한이 필요하고, 방마다 분당 30번까지입니다(넘으면 `429 rate_limited`, `body.scope: "room_typing"`). 아직 카톡 방과 연결되지 않은 방은 `409 typing_unsupported`.
|
|
137
|
+
- 테스트 키는 `{ typing: false, test: true }`로 답하고 폰에 넘기지 않습니다.
|
|
138
|
+
|
|
123
139
|
## 오류 처리
|
|
124
140
|
|
|
125
141
|
모든 오류는 `NotiBotError`를 상속합니다. 한 번의 `catch`로 전부 받고, `name`이나 `instanceof`로 갈라 봅니다.
|
|
@@ -153,8 +169,24 @@ try {
|
|
|
153
169
|
- 각 메서드의 두 번째 인자에 `{ signal }`을 넣어 취소할 수 있습니다.
|
|
154
170
|
- `fetch`와 `timeoutMs`(기본 10초)를 생성자에서 주입할 수 있습니다.
|
|
155
171
|
|
|
172
|
+
## API 버전
|
|
173
|
+
|
|
174
|
+
SDK는 모든 요청에 `NotiBot-Version` 헤더를 보냅니다. 값은 이 SDK가 만들어진 API 버전(`API_VERSION`, 지금은 `2026-12-01`)입니다.
|
|
175
|
+
허브가 호환이 깨지는 변경을 새 날짜 버전으로 내도, SDK를 올리기 전에는 지금 받는 응답 모양이 그대로 유지됩니다.
|
|
176
|
+
|
|
177
|
+
```ts
|
|
178
|
+
import { API_VERSION } from '@noti-bot/sdk';
|
|
179
|
+
console.log(API_VERSION); // "2026-12-01"
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
- 경로의 `/v1`은 바뀌지 않습니다. 새 필드와 새 오류 코드는 버전을 올리지 않고 더해집니다.
|
|
183
|
+
- webhook 요청에도 같은 헤더가 붙습니다. 본문과 서명은 그대로입니다.
|
|
184
|
+
- 허브가 모르는 버전이면 `400 unsupported_api_version`(`NotiBotApiError`, `retryable: false`)입니다. 이 SDK보다 오래된 허브에 붙였을 때만 납니다.
|
|
185
|
+
|
|
156
186
|
## 변경 이력
|
|
157
187
|
|
|
188
|
+
- **0.14.0** — 모든 요청에 `NotiBot-Version` 헤더를 보냅니다. `API_VERSION` export. 오류 코드 `unsupported_api_version`.
|
|
189
|
+
- **0.13.0** — `setTyping({ room | roomId | roomSlug, durationSeconds? })`: 봇의 "입력 중" 표시(`POST /v1/typing`, `/v1/rooms/{slug}/typing`).
|
|
158
190
|
- **0.9.0** — `getMessage(requestId)`: 보낸 메시지의 전달 결과(`GET /v1/messages/{requestId}`).
|
|
159
191
|
- **0.8.0** — 워크스페이스 API 키(`nb_live_`/`nb_test_`). `kb_` 키는 더 이상 동작하지 않음. 콘솔에서 새로 발급해 교체하세요. `room_not_bound` 대신 `404 room_not_found`.
|
|
160
192
|
|
|
@@ -169,7 +201,7 @@ pnpm --filter @noti-bot/sdk pack --pack-destination /tmp/notibot-sdk-release
|
|
|
169
201
|
|
|
170
202
|
## 키 권한
|
|
171
203
|
|
|
172
|
-
대시보드에서 키 이름과 허용 작업을 선택합니다. `listRooms()`는 `rooms:read`, `sendMessage()
|
|
204
|
+
대시보드에서 키 이름과 허용 작업을 선택합니다. `listRooms()`는 `rooms:read`, `sendMessage()`·`setTyping()`은 `messages:send`(이미지는 `messages:image`도)가 필요하며 부족하면 `403 insufficient_scope`가 반환됩니다. 키 권한은 워크스페이스의 방 범위를 넓히지 않습니다. 권한을 바꾸려면 새 키를 발급하고 연동을 교체한 뒤 이전 키를 폐기하세요.
|
|
173
205
|
|
|
174
206
|
## 실제 발송 없는 테스트 키
|
|
175
207
|
|
package/dist/errors.d.ts
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
*/
|
|
20
20
|
export declare const NOTIBOT_ERROR_BRAND: unique symbol;
|
|
21
21
|
/** 허브가 돌려주는 오류 코드. 서버 라우트(`src/outbound/routes.ts`)가 정본이다. */
|
|
22
|
-
export declare const NOTIBOT_ERROR_CODES: readonly ["validation_error", "invalid_room_slug", "unauthorized", "plan_message_limit", "insufficient_scope", "room_not_found", "message_not_found", "room_inactive", "idempotency_conflict", "rate_limited", "kill_switch", "queue_full", "request_failed"];
|
|
22
|
+
export declare const NOTIBOT_ERROR_CODES: readonly ["validation_error", "unsupported_api_version", "invalid_room_slug", "unauthorized", "plan_message_limit", "insufficient_scope", "room_not_found", "message_not_found", "room_inactive", "idempotency_conflict", "rate_limited", "kill_switch", "queue_full", "typing_unsupported", "request_failed"];
|
|
23
23
|
export type NotiBotErrorCode = (typeof NOTIBOT_ERROR_CODES)[number];
|
|
24
24
|
/**
|
|
25
25
|
* 알려진 코드는 자동완성으로 뜨되, 허브가 새 코드를 추가해도 타입이 깨지지 않는다.
|
package/dist/errors.js
CHANGED
|
@@ -21,6 +21,7 @@ export const NOTIBOT_ERROR_BRAND = Symbol.for("@noti-bot/sdk.error");
|
|
|
21
21
|
/** 허브가 돌려주는 오류 코드. 서버 라우트(`src/outbound/routes.ts`)가 정본이다. */
|
|
22
22
|
export const NOTIBOT_ERROR_CODES = [
|
|
23
23
|
"validation_error",
|
|
24
|
+
"unsupported_api_version",
|
|
24
25
|
"invalid_room_slug",
|
|
25
26
|
"unauthorized",
|
|
26
27
|
"plan_message_limit",
|
|
@@ -32,6 +33,7 @@ export const NOTIBOT_ERROR_CODES = [
|
|
|
32
33
|
"rate_limited",
|
|
33
34
|
"kill_switch",
|
|
34
35
|
"queue_full",
|
|
36
|
+
"typing_unsupported",
|
|
35
37
|
"request_failed",
|
|
36
38
|
];
|
|
37
39
|
/** 모든 허브 오류의 베이스. `catch` 에서 `isNotiBotError(e)` 한 번으로 전부 잡는다. */
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
export type { NotiBotErrorCode, NotiBotErrorCodeLike, NotiBotErrorJSON } from "./errors.js";
|
|
2
2
|
export { isNotiBotError, NOTIBOT_ERROR_BRAND, NOTIBOT_ERROR_CODES, NotiBotApiError, NotiBotError, NotiBotProtocolError, NotiBotTimeoutError, NotiBotTransportError, } from "./errors.js";
|
|
3
|
+
/**
|
|
4
|
+
* The API version this SDK was built for. It is sent as `NotiBot-Version` on every request,
|
|
5
|
+
* so responses keep the shape this SDK knows until you upgrade the SDK.
|
|
6
|
+
*/
|
|
7
|
+
export declare const API_VERSION = "2026-12-01";
|
|
3
8
|
/**
|
|
4
9
|
* Tag a member in `sendMessage` text: `` `${mention(ev.senderId)} 확인했어요` ``.
|
|
5
10
|
* The bridge swaps it for `@표시이름` and sends a real Kakao mention (notification to that person).
|
|
@@ -53,7 +58,7 @@ export type SendMessageInput = ({
|
|
|
53
58
|
* when it accepts the request. Requires the `messages:image` scope. Cannot be combined
|
|
54
59
|
* with `text`, `image`, `mentions` or `replyTo`. Rejections: `image_url_not_allowed`,
|
|
55
60
|
* `image_fetch_failed` (HTTP 422), `image_too_large`, `unsupported_image`,
|
|
56
|
-
* `image_send_disabled`, `image_busy`, `image_processing_unavailable` (HTTP 503, retry later).
|
|
61
|
+
* `image_send_disabled`, `plan_image_not_allowed`, `image_busy`, `image_processing_unavailable` (HTTP 503, retry later).
|
|
57
62
|
* Images other than GIF are resized to at most 2560 px on the long side and their
|
|
58
63
|
* metadata (EXIF, location) is removed.
|
|
59
64
|
*/
|
|
@@ -155,6 +160,27 @@ export interface InboundWebhookEvent {
|
|
|
155
160
|
}[];
|
|
156
161
|
test?: boolean;
|
|
157
162
|
}
|
|
163
|
+
/** `room` 은 방 이름(웹훅 이벤트의 `room`). `roomId`·`roomSlug` 와 같이 쓰지 않는다 */
|
|
164
|
+
export type SetTypingInput = ({
|
|
165
|
+
roomId: string;
|
|
166
|
+
} | {
|
|
167
|
+
roomSlug: string;
|
|
168
|
+
} | {
|
|
169
|
+
room: string;
|
|
170
|
+
}) & {
|
|
171
|
+
/** 몇 초 동안 보일지. 1~30, 기본 10. 그 방으로 봇 메시지가 나가면 바로 꺼진다 */
|
|
172
|
+
durationSeconds?: number;
|
|
173
|
+
};
|
|
174
|
+
export interface SetTypingResult {
|
|
175
|
+
ok: true;
|
|
176
|
+
/** 폰에 넘길 요청을 접수했는지. 테스트 키(`nb_test_`)는 false */
|
|
177
|
+
typing: boolean;
|
|
178
|
+
durationSeconds: number;
|
|
179
|
+
/** 표시가 끝나는 시각(ISO 8601). 테스트 키에는 없다 */
|
|
180
|
+
until?: string;
|
|
181
|
+
room?: string;
|
|
182
|
+
test?: boolean;
|
|
183
|
+
}
|
|
158
184
|
export interface RequestOptions {
|
|
159
185
|
signal?: AbortSignal;
|
|
160
186
|
}
|
|
@@ -190,5 +216,11 @@ export declare class NotiBot {
|
|
|
190
216
|
}) & {
|
|
191
217
|
q?: string;
|
|
192
218
|
}, options?: RequestOptions): Promise<RoomMembers>;
|
|
219
|
+
/**
|
|
220
|
+
* 방 사람들에게 봇이 "입력 중"으로 보이게 한다. 답을 만드는 데 시간이 걸릴 때 먼저 부르고,
|
|
221
|
+
* 준비되면 `sendMessage` 로 보낸다(메시지가 나가면 바로 꺼진다). 더 오래 보이려면 끝나기 전에 다시 부른다.
|
|
222
|
+
* 접수만 하고 기다리지 않으며, 상대에게 보였는지는 알 수 없다. `messages:send` 권한, 방마다 분당 30번.
|
|
223
|
+
*/
|
|
224
|
+
setTyping(input: SetTypingInput, options?: RequestOptions): Promise<SetTypingResult>;
|
|
193
225
|
private request;
|
|
194
226
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
export { isNotiBotError, NOTIBOT_ERROR_BRAND, NOTIBOT_ERROR_CODES, NotiBotApiError, NotiBotError, NotiBotProtocolError, NotiBotTimeoutError, NotiBotTransportError, } from "./errors.js";
|
|
2
2
|
import { NotiBotApiError, NotiBotProtocolError, NotiBotTimeoutError, NotiBotTransportError, } from "./errors.js";
|
|
3
|
+
/**
|
|
4
|
+
* The API version this SDK was built for. It is sent as `NotiBot-Version` on every request,
|
|
5
|
+
* so responses keep the shape this SDK knows until you upgrade the SDK.
|
|
6
|
+
*/
|
|
7
|
+
export const API_VERSION = "2026-12-01";
|
|
3
8
|
/**
|
|
4
9
|
* Tag a member in `sendMessage` text: `` `${mention(ev.senderId)} 확인했어요` ``.
|
|
5
10
|
* The bridge swaps it for `@표시이름` and sends a real Kakao mention (notification to that person).
|
|
@@ -167,6 +172,45 @@ export class NotiBot {
|
|
|
167
172
|
syncedAt: typeof data.syncedAt === "number" ? data.syncedAt : null,
|
|
168
173
|
};
|
|
169
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* 방 사람들에게 봇이 "입력 중"으로 보이게 한다. 답을 만드는 데 시간이 걸릴 때 먼저 부르고,
|
|
177
|
+
* 준비되면 `sendMessage` 로 보낸다(메시지가 나가면 바로 꺼진다). 더 오래 보이려면 끝나기 전에 다시 부른다.
|
|
178
|
+
* 접수만 하고 기다리지 않으며, 상대에게 보였는지는 알 수 없다. `messages:send` 권한, 방마다 분당 30번.
|
|
179
|
+
*/
|
|
180
|
+
async setTyping(input, options = {}) {
|
|
181
|
+
const duration = input.durationSeconds;
|
|
182
|
+
if (duration !== undefined && (!Number.isInteger(duration) || duration < 1 || duration > 30))
|
|
183
|
+
throw new TypeError("durationSeconds must be an integer between 1 and 30.");
|
|
184
|
+
if ("roomId" in input
|
|
185
|
+
? !input.roomId?.trim()
|
|
186
|
+
: "roomSlug" in input
|
|
187
|
+
? !/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(input.roomSlug ?? "")
|
|
188
|
+
: !input.room?.trim())
|
|
189
|
+
throw new TypeError("room, roomId or a valid roomSlug is required.");
|
|
190
|
+
const data = await this.request("roomId" in input
|
|
191
|
+
? `/v1/rooms/id/${encodeURIComponent(input.roomId)}/typing`
|
|
192
|
+
: "roomSlug" in input
|
|
193
|
+
? `/v1/rooms/${encodeURIComponent(input.roomSlug)}/typing`
|
|
194
|
+
: "/v1/typing", "POST", {
|
|
195
|
+
...("room" in input ? { room: input.room } : {}),
|
|
196
|
+
...(duration === undefined ? {} : { duration_s: duration }),
|
|
197
|
+
}, options.signal);
|
|
198
|
+
if (!object(data) ||
|
|
199
|
+
data.ok !== true ||
|
|
200
|
+
typeof data.typing !== "boolean" ||
|
|
201
|
+
typeof data.duration_s !== "number" ||
|
|
202
|
+
(data.until !== undefined && typeof data.until !== "string") ||
|
|
203
|
+
(data.room !== undefined && typeof data.room !== "string"))
|
|
204
|
+
throw new NotiBotProtocolError();
|
|
205
|
+
return {
|
|
206
|
+
ok: true,
|
|
207
|
+
typing: data.typing,
|
|
208
|
+
durationSeconds: data.duration_s,
|
|
209
|
+
...(typeof data.until === "string" ? { until: data.until } : {}),
|
|
210
|
+
...(typeof data.room === "string" ? { room: data.room } : {}),
|
|
211
|
+
...(data.test === true ? { test: true } : {}),
|
|
212
|
+
};
|
|
213
|
+
}
|
|
170
214
|
async request(path, method, body, signal, requestId) {
|
|
171
215
|
const timeout = AbortSignal.timeout(this.timeoutMs);
|
|
172
216
|
const combined = signal ? AbortSignal.any([signal, timeout]) : timeout;
|
|
@@ -178,6 +222,7 @@ export class NotiBot {
|
|
|
178
222
|
headers: {
|
|
179
223
|
Authorization: `Bearer ${this.apiKey}`,
|
|
180
224
|
Accept: "application/json",
|
|
225
|
+
"NotiBot-Version": API_VERSION,
|
|
181
226
|
// multipart: fetch sets the Content-Type with its boundary
|
|
182
227
|
...(body === undefined || body instanceof FormData
|
|
183
228
|
? {}
|