@noti-bot/sdk 0.8.0 → 0.10.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
@@ -29,6 +29,15 @@ Node.js 20 이상, ESM을 지원합니다. API 키는 브라우저 번들에 넣
29
29
 
30
30
  `queued: true`는 접수이며 실제 전달 성공이 아닙니다. 서버는 API 키별 `requestId`로 중복을 방지합니다. 같은 논리적 발송에는 같은 ID를 사용하세요. **SDK는 POST 또는 GET을 자동 재시도하지 않습니다.** 타임아웃은 이미 접수된 요청일 수 있으므로 새 ID로 재시도하면 중복 발송됩니다. `NotiBotTransportError.requestId`로 요청을 식별하고 대시보드 로그를 확인하세요.
31
31
 
32
+ ## 전달 결과 확인
33
+
34
+ ```ts
35
+ const r = await kakao.getMessage('deploy:release-2026-10-10');
36
+ // r.status: 'queued' | 'sent' | 'failed' | 'expired' | 'duplicate', r.sent: true | false | null, r.error
37
+ ```
38
+
39
+ 이 API 키로 보낸 `requestId`만 조회됩니다(`messages:send` 필요). 없거나 다른 키가 보낸 ID면 `404 message_not_found`. `failed` + `error: 'delivery_unknown'`은 폰이 가져갔지만 결과를 못 받은 상태라 실제로 갔을 수 있습니다. 중복이 괜찮을 때만 **새** `requestId`로 다시 보내세요.
40
+
32
41
  ## 멘션
33
42
 
34
43
  받은 웹훅의 `mentions`에는 메시지가 실제로 태그한 계정이 `{ userId, name? }`로 들어옵니다. 이름은 바뀔 수 있으니 `userId`로 비교하세요.
@@ -45,6 +54,23 @@ await kakao.sendMessage({
45
54
  });
46
55
  ```
47
56
 
57
+ ## 답장
58
+
59
+ 받은 웹훅의 `messageId`(카톡이 붙인 메시지 ID)를 `replyTo`에 넣으면 그 메시지를 인용한 답장으로 나갑니다. 같은 방의 메시지만 인용할 수 있고, 없는 ID면 발송 결과가 `failed` + `reply_target_not_found`입니다. Iris 전송에서만 인용되며 그 밖에서는 인용 없이 본문만 나갑니다.
60
+
61
+ ```ts
62
+ await kakao.sendMessage({
63
+ roomId: process.env.KAKAO_ROOM_ID!,
64
+ text: '확인했어요',
65
+ replyTo: event.messageId,
66
+ requestId: `ack:${event.event_id}`,
67
+ });
68
+ ```
69
+
70
+ 웹훅 응답으로 바로 답할 때는 `{"reply": "확인했어요", "reply_to": "<messageId>"}`를 돌려주면 됩니다.
71
+
72
+ ## 이름으로 태그
73
+
48
74
  이름만 알면 `mentions`로 태그할 수 있습니다. 그 방 참여자 한 명으로 정해져야 보내고, 없거나 여럿이면 `NotiBotApiError`(`mention_name_unknown` / `mention_name_ambiguous`, `body.candidates`)로 거절됩니다.
49
75
 
50
76
  ```ts
@@ -99,6 +125,7 @@ try {
99
125
 
100
126
  ## 변경 이력
101
127
 
128
+ - **0.9.0** — `getMessage(requestId)`: 보낸 메시지의 전달 결과(`GET /v1/messages/{requestId}`).
102
129
  - **0.8.0** — 워크스페이스 API 키(`nb_live_`/`nb_test_`). `kb_` 키는 더 이상 동작하지 않음. 콘솔에서 새로 발급해 교체하세요. `room_not_bound` 대신 `404 room_not_found`.
103
130
 
104
131
  ## 릴리스
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", "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", "request_failed"];
23
23
  export type NotiBotErrorCode = (typeof NOTIBOT_ERROR_CODES)[number];
24
24
  /**
25
25
  * 알려진 코드는 자동완성으로 뜨되, 허브가 새 코드를 추가해도 타입이 깨지지 않는다.
package/dist/errors.js CHANGED
@@ -26,6 +26,7 @@ export const NOTIBOT_ERROR_CODES = [
26
26
  "plan_message_limit",
27
27
  "insufficient_scope",
28
28
  "room_not_found",
29
+ "message_not_found",
29
30
  "room_inactive",
30
31
  "idempotency_conflict",
31
32
  "rate_limited",
package/dist/index.d.ts CHANGED
@@ -37,6 +37,11 @@ export type SendMessageInput = ({
37
37
  * reject with `mention_name_unknown` / `mention_name_ambiguous` (and `candidates`), unsent.
38
38
  */
39
39
  mentions?: string[];
40
+ /**
41
+ * Quote a message of the same room: pass `InboundWebhookEvent.messageId`. Iris transport only;
42
+ * elsewhere the text goes out unquoted. An unknown ID fails with `reply_target_not_found`.
43
+ */
44
+ replyTo?: string;
40
45
  };
41
46
  export interface SendMessageResult {
42
47
  ok: true;
@@ -47,6 +52,22 @@ export interface SendMessageResult {
47
52
  request_id: string;
48
53
  room?: string;
49
54
  }
55
+ /** Hub-side delivery state of one sent message. */
56
+ export type MessageStatus = "queued" | "sent" | "failed" | "expired" | "duplicate";
57
+ /** Delivery result for a `requestId` sent with this API key. */
58
+ export interface MessageResult {
59
+ request_id: string;
60
+ room: string;
61
+ status: MessageStatus;
62
+ /** true: the phone handed it to KakaoTalk. false: rejected. null: still queued, or unknown. */
63
+ sent: boolean | null;
64
+ /** e.g. `delivery_unknown`, `no_session`, `expired_in_queue`. */
65
+ error: string | null;
66
+ /** Accepted at (epoch ms). */
67
+ at: number;
68
+ /** Phone result at (epoch ms), or null. */
69
+ sent_at: number | null;
70
+ }
50
71
  export interface Room {
51
72
  id?: string;
52
73
  slug?: string | null;
@@ -82,6 +103,8 @@ export interface InboundWebhookEvent {
82
103
  roomExternalId?: string;
83
104
  sender: string;
84
105
  senderId?: string;
106
+ /** KakaoTalk's ID of this message (Iris transport only). Pass it as `replyTo` to quote it. */
107
+ messageId?: string;
85
108
  msg: string;
86
109
  command: string;
87
110
  isMention: boolean;
@@ -106,6 +129,13 @@ export declare class NotiBot {
106
129
  private readonly fetchFn;
107
130
  constructor(options: NotiBotOptions);
108
131
  sendMessage(input: SendMessageInput, options?: RequestOptions): Promise<SendMessageResult>;
132
+ /**
133
+ * Delivery result of a message this API key sent. Requires the `messages:send` scope.
134
+ * Rejects with `message_not_found` for unknown IDs, IDs of other keys, and test-key sends.
135
+ * `failed` + `delivery_unknown` means the phone may or may not have sent it: retry with a
136
+ * new requestId only when a duplicate is acceptable.
137
+ */
138
+ getMessage(requestId: string, options?: RequestOptions): Promise<MessageResult>;
109
139
  listRooms(options?: RequestOptions): Promise<Room[]>;
110
140
  /** Members of a room in this workspace. Requires the `rooms:read` scope. */
111
141
  listRoomMembers(room: {
package/dist/index.js CHANGED
@@ -49,6 +49,8 @@ export class NotiBot {
49
49
  const requestId = input.requestId ?? globalThis.crypto.randomUUID();
50
50
  if (!requestId.trim() || requestId.length > 128)
51
51
  throw new TypeError("requestId must contain 1 to 128 characters.");
52
+ if (input.replyTo !== undefined && !/^\d{1,20}$/.test(input.replyTo))
53
+ throw new TypeError("replyTo must be a Kakao message ID (digits only).");
52
54
  const data = await this.request(input.roomId !== undefined
53
55
  ? `/v1/rooms/id/${encodeURIComponent(input.roomId)}/messages`
54
56
  : input.roomSlug !== undefined
@@ -58,6 +60,7 @@ export class NotiBot {
58
60
  msg: input.text,
59
61
  request_id: requestId,
60
62
  ...(input.mentions ? { mentions: input.mentions } : {}),
63
+ ...(input.replyTo ? { reply_to: input.replyTo } : {}),
61
64
  }, options.signal, requestId);
62
65
  if (!object(data) ||
63
66
  data.ok !== true ||
@@ -69,6 +72,27 @@ export class NotiBot {
69
72
  throw new NotiBotProtocolError(requestId);
70
73
  return data;
71
74
  }
75
+ /**
76
+ * Delivery result of a message this API key sent. Requires the `messages:send` scope.
77
+ * Rejects with `message_not_found` for unknown IDs, IDs of other keys, and test-key sends.
78
+ * `failed` + `delivery_unknown` means the phone may or may not have sent it: retry with a
79
+ * new requestId only when a duplicate is acceptable.
80
+ */
81
+ async getMessage(requestId, options = {}) {
82
+ if (!requestId.trim() || requestId.length > 128)
83
+ throw new TypeError("requestId must contain 1 to 128 characters.");
84
+ const data = await this.request(`/v1/messages/${encodeURIComponent(requestId)}`, "GET", undefined, options.signal, requestId);
85
+ if (!object(data) ||
86
+ data.request_id !== requestId ||
87
+ typeof data.room !== "string" ||
88
+ !["queued", "sent", "failed", "expired", "duplicate"].includes(String(data.status)) ||
89
+ !(data.sent === null || typeof data.sent === "boolean") ||
90
+ !(data.error === null || typeof data.error === "string") ||
91
+ typeof data.at !== "number" ||
92
+ !(data.sent_at === null || typeof data.sent_at === "number"))
93
+ throw new NotiBotProtocolError(requestId);
94
+ return data;
95
+ }
72
96
  async listRooms(options = {}) {
73
97
  const data = await this.request("/v1/rooms", "GET", undefined, options.signal);
74
98
  if (!object(data) ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noti-bot/sdk",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "description": "Typed server-side client for the NotiBot API",
5
5
  "license": "MIT",
6
6
  "author": "Jeongmin Lee",