@noti-bot/sdk 0.12.0 → 0.13.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 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`로 갈라 봅니다.
@@ -155,6 +171,7 @@ try {
155
171
 
156
172
  ## 변경 이력
157
173
 
174
+ - **0.13.0** — `setTyping({ room | roomId | roomSlug, durationSeconds? })`: 봇의 "입력 중" 표시(`POST /v1/typing`, `/v1/rooms/{slug}/typing`).
158
175
  - **0.9.0** — `getMessage(requestId)`: 보낸 메시지의 전달 결과(`GET /v1/messages/{requestId}`).
159
176
  - **0.8.0** — 워크스페이스 API 키(`nb_live_`/`nb_test_`). `kb_` 키는 더 이상 동작하지 않음. 콘솔에서 새로 발급해 교체하세요. `room_not_bound` 대신 `404 room_not_found`.
160
177
 
@@ -169,7 +186,7 @@ pnpm --filter @noti-bot/sdk pack --pack-destination /tmp/notibot-sdk-release
169
186
 
170
187
  ## 키 권한
171
188
 
172
- 대시보드에서 키 이름과 허용 작업을 선택합니다. `listRooms()`는 `rooms:read`, `sendMessage()`는 `messages:send`(이미지는 `messages:image`도)가 필요하며 부족하면 `403 insufficient_scope`가 반환됩니다. 키 권한은 워크스페이스의 방 범위를 넓히지 않습니다. 권한을 바꾸려면 새 키를 발급하고 연동을 교체한 뒤 이전 키를 폐기하세요.
189
+ 대시보드에서 키 이름과 허용 작업을 선택합니다. `listRooms()`는 `rooms:read`, `sendMessage()`·`setTyping()`은 `messages:send`(이미지는 `messages:image`도)가 필요하며 부족하면 `403 insufficient_scope`가 반환됩니다. 키 권한은 워크스페이스의 방 범위를 넓히지 않습니다. 권한을 바꾸려면 새 키를 발급하고 연동을 교체한 뒤 이전 키를 폐기하세요.
173
190
 
174
191
  ## 실제 발송 없는 테스트 키
175
192
 
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", "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
@@ -32,6 +32,7 @@ export const NOTIBOT_ERROR_CODES = [
32
32
  "rate_limited",
33
33
  "kill_switch",
34
34
  "queue_full",
35
+ "typing_unsupported",
35
36
  "request_failed",
36
37
  ];
37
38
  /** 모든 허브 오류의 베이스. `catch` 에서 `isNotiBotError(e)` 한 번으로 전부 잡는다. */
package/dist/index.d.ts CHANGED
@@ -53,7 +53,7 @@ export type SendMessageInput = ({
53
53
  * when it accepts the request. Requires the `messages:image` scope. Cannot be combined
54
54
  * with `text`, `image`, `mentions` or `replyTo`. Rejections: `image_url_not_allowed`,
55
55
  * `image_fetch_failed` (HTTP 422), `image_too_large`, `unsupported_image`,
56
- * `image_send_disabled`, `image_busy`, `image_processing_unavailable` (HTTP 503, retry later).
56
+ * `image_send_disabled`, `plan_image_not_allowed`, `image_busy`, `image_processing_unavailable` (HTTP 503, retry later).
57
57
  * Images other than GIF are resized to at most 2560 px on the long side and their
58
58
  * metadata (EXIF, location) is removed.
59
59
  */
@@ -155,6 +155,27 @@ export interface InboundWebhookEvent {
155
155
  }[];
156
156
  test?: boolean;
157
157
  }
158
+ /** `room` 은 방 이름(웹훅 이벤트의 `room`). `roomId`·`roomSlug` 와 같이 쓰지 않는다 */
159
+ export type SetTypingInput = ({
160
+ roomId: string;
161
+ } | {
162
+ roomSlug: string;
163
+ } | {
164
+ room: string;
165
+ }) & {
166
+ /** 몇 초 동안 보일지. 1~30, 기본 10. 그 방으로 봇 메시지가 나가면 바로 꺼진다 */
167
+ durationSeconds?: number;
168
+ };
169
+ export interface SetTypingResult {
170
+ ok: true;
171
+ /** 폰에 넘길 요청을 접수했는지. 테스트 키(`nb_test_`)는 false */
172
+ typing: boolean;
173
+ durationSeconds: number;
174
+ /** 표시가 끝나는 시각(ISO 8601). 테스트 키에는 없다 */
175
+ until?: string;
176
+ room?: string;
177
+ test?: boolean;
178
+ }
158
179
  export interface RequestOptions {
159
180
  signal?: AbortSignal;
160
181
  }
@@ -190,5 +211,11 @@ export declare class NotiBot {
190
211
  }) & {
191
212
  q?: string;
192
213
  }, options?: RequestOptions): Promise<RoomMembers>;
214
+ /**
215
+ * 방 사람들에게 봇이 "입력 중"으로 보이게 한다. 답을 만드는 데 시간이 걸릴 때 먼저 부르고,
216
+ * 준비되면 `sendMessage` 로 보낸다(메시지가 나가면 바로 꺼진다). 더 오래 보이려면 끝나기 전에 다시 부른다.
217
+ * 접수만 하고 기다리지 않으며, 상대에게 보였는지는 알 수 없다. `messages:send` 권한, 방마다 분당 30번.
218
+ */
219
+ setTyping(input: SetTypingInput, options?: RequestOptions): Promise<SetTypingResult>;
193
220
  private request;
194
221
  }
package/dist/index.js CHANGED
@@ -167,6 +167,45 @@ export class NotiBot {
167
167
  syncedAt: typeof data.syncedAt === "number" ? data.syncedAt : null,
168
168
  };
169
169
  }
170
+ /**
171
+ * 방 사람들에게 봇이 "입력 중"으로 보이게 한다. 답을 만드는 데 시간이 걸릴 때 먼저 부르고,
172
+ * 준비되면 `sendMessage` 로 보낸다(메시지가 나가면 바로 꺼진다). 더 오래 보이려면 끝나기 전에 다시 부른다.
173
+ * 접수만 하고 기다리지 않으며, 상대에게 보였는지는 알 수 없다. `messages:send` 권한, 방마다 분당 30번.
174
+ */
175
+ async setTyping(input, options = {}) {
176
+ const duration = input.durationSeconds;
177
+ if (duration !== undefined && (!Number.isInteger(duration) || duration < 1 || duration > 30))
178
+ throw new TypeError("durationSeconds must be an integer between 1 and 30.");
179
+ if ("roomId" in input
180
+ ? !input.roomId?.trim()
181
+ : "roomSlug" in input
182
+ ? !/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(input.roomSlug ?? "")
183
+ : !input.room?.trim())
184
+ throw new TypeError("room, roomId or a valid roomSlug is required.");
185
+ const data = await this.request("roomId" in input
186
+ ? `/v1/rooms/id/${encodeURIComponent(input.roomId)}/typing`
187
+ : "roomSlug" in input
188
+ ? `/v1/rooms/${encodeURIComponent(input.roomSlug)}/typing`
189
+ : "/v1/typing", "POST", {
190
+ ...("room" in input ? { room: input.room } : {}),
191
+ ...(duration === undefined ? {} : { duration_s: duration }),
192
+ }, options.signal);
193
+ if (!object(data) ||
194
+ data.ok !== true ||
195
+ typeof data.typing !== "boolean" ||
196
+ typeof data.duration_s !== "number" ||
197
+ (data.until !== undefined && typeof data.until !== "string") ||
198
+ (data.room !== undefined && typeof data.room !== "string"))
199
+ throw new NotiBotProtocolError();
200
+ return {
201
+ ok: true,
202
+ typing: data.typing,
203
+ durationSeconds: data.duration_s,
204
+ ...(typeof data.until === "string" ? { until: data.until } : {}),
205
+ ...(typeof data.room === "string" ? { room: data.room } : {}),
206
+ ...(data.test === true ? { test: true } : {}),
207
+ };
208
+ }
170
209
  async request(path, method, body, signal, requestId) {
171
210
  const timeout = AbortSignal.timeout(this.timeoutMs);
172
211
  const combined = signal ? AbortSignal.any([signal, timeout]) : timeout;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noti-bot/sdk",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "Typed server-side client for the NotiBot API",
5
5
  "license": "MIT",
6
6
  "author": "Jeongmin Lee",