@noti-bot/sdk 0.10.0 → 0.11.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
@@ -56,7 +56,7 @@ await kakao.sendMessage({
56
56
 
57
57
  ## 답장
58
58
 
59
- 받은 웹훅의 `messageId`(카톡이 붙인 메시지 ID)를 `replyTo`에 넣으면 그 메시지를 인용한 답장으로 나갑니다. 같은 방의 메시지만 인용할 수 있고, 없는 ID면 발송 결과가 `failed` + `reply_target_not_found`입니다. Iris 전송에서만 인용되며 그 밖에서는 인용 없이 본문만 나갑니다.
59
+ 받은 웹훅의 `messageId`(카톡이 붙인 메시지 ID)를 `replyTo`에 넣으면 그 메시지를 인용한 답장으로 나갑니다. 같은 방의 메시지만 인용할 수 있고, 없는 ID면 발송 결과가 `failed` + `reply_target_not_found`입니다.
60
60
 
61
61
  ```ts
62
62
  await kakao.sendMessage({
@@ -69,26 +69,47 @@ await kakao.sendMessage({
69
69
 
70
70
  웹훅 응답으로 바로 답할 때는 `{"reply": "확인했어요", "reply_to": "<messageId>"}`를 돌려주면 됩니다.
71
71
 
72
+ ## 이미지 보내기
73
+
74
+ `text` 대신 `imageUrl`을 주면 이미지 한 장을 보냅니다. 키에 `messages:image` 권한이 있어야 합니다(키를 만들 때 따로 고릅니다).
75
+
76
+ ```ts
77
+ await bot.sendMessage({
78
+ roomSlug: "reports",
79
+ imageUrl: "https://cdn.example.com/reports/2026-11-30.png",
80
+ requestId: "report:2026-11-30",
81
+ });
82
+ ```
83
+
84
+ - 주소는 `https://`로 시작하는 공개 주소여야 하고, 리다이렉트 없이 이미지를 바로 돌려줘야 합니다.
85
+ - PNG·JPEG·GIF, 5MB 이하. 형식은 파일 내용으로 판단합니다.
86
+ - `text`·`mentions`·`replyTo`와 같이 쓸 수 없습니다. 글을 같이 보내려면 요청을 따로 보내세요.
87
+ - 허브가 요청을 받을 때 한 번 내려받습니다. 같은 `requestId`로 다시 보내면 내려받지 않고 중복으로 처리합니다.
88
+ - 이미지는 받은 그대로 나갑니다. 위치 정보 같은 메타데이터(EXIF)는 보내기 전에 지우세요.
89
+ - 이미지 메시지는 수정할 수 없습니다(REST `PATCH /v1/messages/{requestId}`는 `edit_not_supported`). 삭제와 공감은 됩니다.
90
+
91
+ 거절은 `NotiBotApiError`의 `code`로 옵니다: `image_url_not_allowed`(보낼 수 없는 주소), `image_fetch_failed`(받지 못함), `image_too_large`, `unsupported_image`, `image_send_disabled`(서비스에서 꺼져 있음), `image_busy`(잠시 뒤 다시).
92
+
72
93
  ## 이름으로 태그
73
94
 
74
95
  이름만 알면 `mentions`로 태그할 수 있습니다. 그 방 참여자 한 명으로 정해져야 보내고, 없거나 여럿이면 `NotiBotApiError`(`mention_name_unknown` / `mention_name_ambiguous`, `body.candidates`)로 거절됩니다.
75
96
 
76
97
  ```ts
77
- await bot.sendMessage({ roomSlug: "tf", text: "@이현근 확인 부탁해요", mentions: ["이현근"] });
98
+ await bot.sendMessage({ roomSlug: "tf", text: "@김철수 확인 부탁해요", mentions: ["김철수"] });
78
99
  ```
79
100
 
80
101
  방에 누가 있는지는 `listRoomMembers`(목록만) 또는 `getRoomMembers`(검색 `q`, 인원 `known`/`total`, 오픈채팅 여부, 마지막 동기화)로 봅니다(`rooms:read` 권한). 카톡 방 정보에서 온 계정 ID와, 그 방에서 본 적 있는 표시 이름을 돌려줍니다.
81
102
 
82
103
  ```ts
83
104
  const members = await bot.listRoomMembers({ roomSlug: "tf" });
84
- // [{ userId: "353148777", name: "김준민", mention: "<@353148777>" }, { userId: "22854332", name: null, ... }]
85
- const target = members.find((m) => m.name === "김준민");
105
+ // [{ userId: "1234567890", name: "홍길동", mention: "<@1234567890>" }, { userId: "9876543210", name: null, ... }]
106
+ const target = members.find((m) => m.name === "홍길동");
86
107
  if (target) await bot.sendMessage({ roomSlug: "tf", text: `${target.mention} 확인 부탁해요` });
87
108
  ```
88
109
 
89
- `name`은 봇폰 카톡 앱에서 읽어 채웁니다(봇폰에 Frida 설정 필요). 설정이 없으면 그 방에서 말하거나 멘션된 적 있는 사람만 이름이 있고, 나머지는 `null`입니다. 이름을 모르면 태그 글자를 만들 수 없어 `mention_unresolved`로 발송되지 않습니다. 키워드 자동응답(rule) 서비스는 응답 문구에 `{보낸사람}`을 쓰면 말한 사람을 태그합니다.
110
+ `name`을 아직 모르는 사람은 `null`입니다. 이름을 모르면 태그 글자를 만들 수 없어 `mention_unresolved`로 발송되지 않습니다. 키워드 자동응답(rule) 서비스는 응답 문구에 `{보낸사람}`을 쓰면 말한 사람을 태그합니다.
90
111
 
91
- 그 방에 없는 사람이면 `mention_unresolved`로 발송되지 않습니다. 멘션은 Iris 전송에서만 동작하며, 봇폰 설정에 따라 태그 없이 `@이름` 글자로만 나갈 수 있습니다.
112
+ 그 방에 없는 사람이면 `mention_unresolved`로 발송되지 않습니다. 상황에 따라 태그 없이 `@이름` 글자로만 나갈 수 있습니다.
92
113
 
93
114
  ## 오류 처리
94
115
 
@@ -139,7 +160,7 @@ pnpm --filter @noti-bot/sdk pack --pack-destination /tmp/notibot-sdk-release
139
160
 
140
161
  ## 키 권한
141
162
 
142
- 대시보드에서 키 이름과 허용 작업을 선택합니다. `listRooms()`는 `rooms:read`, `sendMessage()`는 `messages:send`가 필요하며 부족하면 `403 insufficient_scope`가 반환됩니다. 키 권한은 워크스페이스의 방 범위를 넓히지 않습니다. 권한을 바꾸려면 새 키를 발급하고 연동을 교체한 뒤 이전 키를 폐기하세요.
163
+ 대시보드에서 키 이름과 허용 작업을 선택합니다. `listRooms()`는 `rooms:read`, `sendMessage()`는 `messages:send`(이미지는 `messages:image`도)가 필요하며 부족하면 `403 insufficient_scope`가 반환됩니다. 키 권한은 워크스페이스의 방 범위를 넓히지 않습니다. 권한을 바꾸려면 새 키를 발급하고 연동을 교체한 뒤 이전 키를 폐기하세요.
143
164
 
144
165
  ## 실제 발송 없는 테스트 키
145
166
 
@@ -149,15 +170,14 @@ pnpm --filter @noti-bot/sdk pack --pack-destination /tmp/notibot-sdk-release
149
170
 
150
171
  동일 API 키로 이미 접수한 `requestId`의 방 ID 또는 본문을 바꾸면 `409 idempotency_conflict`를 반환합니다. 동일한 방·본문은 중복으로 처리하며 추가 큐/사용량을 만들지 않습니다. slug/방 표시명 변경은 고정 방 ID가 같으면 충돌로 보지 않습니다. 기존 기록 중 본문 검증값이 없는 건은 방 변경만 검출하고 재발송하지 않습니다. 검증값은 서버 비밀키로 보호하므로 비밀키 교체 후 이전 요청의 재시도는 충돌할 수 있습니다.
151
172
 
152
- ### Iris migration
173
+ ### IDs and webhook events
153
174
 
154
175
  `sendMessage` and `listRooms` retain their existing contracts. Prefer a `roomId` or
155
- `roomSlug` to a display name. The server resolves the stable Kakao ID internally;
156
- SDK clients must not call the phone directly. `queued: true` means accepted by the
176
+ `roomSlug` to a display name. `queued: true` means accepted by the
157
177
  hub, not delivered to a recipient, and uncertain sends must not be retried blindly.
158
178
 
159
179
  `InboundWebhookEvent` describes signed webhook events, including optional
160
- `roomExternalId`, `senderId`, and `imageBase64` from Iris. Treat IDs as strings;
180
+ `roomExternalId`, `senderId`, and `imageBase64`. Treat IDs as strings;
161
181
  Kakao IDs may exceed JavaScript's safe integer range. Check `X-NotiBot-Signature`
162
182
  against the raw request body before parsing. Images are only included for rooms
163
183
  explicitly enabled by the owner.
package/dist/index.d.ts CHANGED
@@ -27,22 +27,37 @@ export type SendMessageInput = ({
27
27
  room?: never;
28
28
  roomSlug?: never;
29
29
  }) & {
30
- /** `<@kakaoUserId>` (see {@link mention}) becomes a real Kakao tag on the Iris transport. */
31
- text: string;
32
30
  /** Reuse this ID for the same logical send. No automatic retries are performed. */
33
31
  requestId?: string;
32
+ } & ({
33
+ /** `<@kakaoUserId>` (see {@link mention}) becomes a real Kakao tag. */
34
+ text: string;
35
+ imageUrl?: never;
34
36
  /**
35
- * Tag people by display name (e.g. `["이현근"]`). Each must match exactly one room member;
37
+ * Tag people by display name (e.g. `["김철수"]`). Each must match exactly one room member;
36
38
  * `@이름` in `text` becomes the tag, otherwise tags go first. Unknown or ambiguous names
37
39
  * reject with `mention_name_unknown` / `mention_name_ambiguous` (and `candidates`), unsent.
38
40
  */
39
41
  mentions?: string[];
40
42
  /**
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
+ * Quote a message of the same room: pass `InboundWebhookEvent.messageId`.
44
+ * An unknown ID fails with `reply_target_not_found`.
43
45
  */
44
46
  replyTo?: string;
45
- };
47
+ } | {
48
+ /**
49
+ * Send one image instead of text: a public `https://` address of a PNG, JPEG or GIF up
50
+ * to 5 MB, served directly (no redirect). The hub downloads it once when it accepts the
51
+ * request. Requires the `messages:image` scope. Cannot be combined with `text`,
52
+ * `mentions` or `replyTo`. Rejections: `image_url_not_allowed`, `image_fetch_failed`,
53
+ * `image_too_large`, `unsupported_image`, `image_send_disabled`, `image_busy`.
54
+ * The image is sent as it is: strip metadata such as EXIF location yourself.
55
+ */
56
+ imageUrl: string;
57
+ text?: never;
58
+ mentions?: never;
59
+ replyTo?: never;
60
+ });
46
61
  export interface SendMessageResult {
47
62
  ok: true;
48
63
  queued: boolean;
@@ -103,7 +118,7 @@ export interface InboundWebhookEvent {
103
118
  roomExternalId?: string;
104
119
  sender: string;
105
120
  senderId?: string;
106
- /** KakaoTalk's ID of this message (Iris transport only). Pass it as `replyTo` to quote it. */
121
+ /** KakaoTalk's ID of this message. Pass it as `replyTo` to quote it. */
107
122
  messageId?: string;
108
123
  msg: string;
109
124
  command: string;
@@ -112,7 +127,7 @@ export interface InboundWebhookEvent {
112
127
  received_at: number;
113
128
  /** Present only for rooms explicitly enabled by the owner. Never log image bytes. */
114
129
  imageBase64?: string;
115
- /** Accounts the message actually tagged (Iris transport only). Compare userId, not name. */
130
+ /** Accounts the message actually tagged. Compare userId, not name. */
116
131
  mentions?: {
117
132
  userId: string;
118
133
  name?: string;
package/dist/index.js CHANGED
@@ -43,9 +43,14 @@ export class NotiBot {
43
43
  : input.roomSlug !== undefined
44
44
  ? !/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(input.roomSlug)
45
45
  : !input.room?.trim()) ||
46
- !input.text.trim() ||
47
- input.text.length > 4000)
46
+ (input.imageUrl === undefined && (!input.text?.trim() || input.text.length > 4000)))
48
47
  throw new TypeError("room and text are required; text must be at most 4000 characters.");
48
+ if (input.imageUrl !== undefined) {
49
+ if (input.text !== undefined || input.mentions !== undefined || input.replyTo !== undefined)
50
+ throw new TypeError("imageUrl cannot be combined with text, mentions or replyTo.");
51
+ if (!/^https:\/\/\S+$/.test(input.imageUrl) || input.imageUrl.length > 2048)
52
+ throw new TypeError("imageUrl must be an https:// URL of at most 2048 characters.");
53
+ }
49
54
  const requestId = input.requestId ?? globalThis.crypto.randomUUID();
50
55
  if (!requestId.trim() || requestId.length > 128)
51
56
  throw new TypeError("requestId must contain 1 to 128 characters.");
@@ -57,7 +62,7 @@ export class NotiBot {
57
62
  ? `/v1/rooms/${encodeURIComponent(input.roomSlug)}/messages`
58
63
  : "/v1/messages", "POST", {
59
64
  room: input.room,
60
- msg: input.text,
65
+ ...(input.imageUrl !== undefined ? { image_url: input.imageUrl } : { msg: input.text }),
61
66
  request_id: requestId,
62
67
  ...(input.mentions ? { mentions: input.mentions } : {}),
63
68
  ...(input.replyTo ? { reply_to: input.replyTo } : {}),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noti-bot/sdk",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "Typed server-side client for the NotiBot API",
5
5
  "license": "MIT",
6
6
  "author": "Jeongmin Lee",