@noti-bot/sdk 0.9.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 +47 -10
- package/dist/index.d.ts +27 -5
- package/dist/index.js +11 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -54,24 +54,62 @@ await kakao.sendMessage({
|
|
|
54
54
|
});
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
+
## 답장
|
|
58
|
+
|
|
59
|
+
받은 웹훅의 `messageId`(카톡이 붙인 메시지 ID)를 `replyTo`에 넣으면 그 메시지를 인용한 답장으로 나갑니다. 같은 방의 메시지만 인용할 수 있고, 없는 ID면 발송 결과가 `failed` + `reply_target_not_found`입니다.
|
|
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
|
+
|
|
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
|
+
|
|
93
|
+
## 이름으로 태그
|
|
94
|
+
|
|
57
95
|
이름만 알면 `mentions`로 태그할 수 있습니다. 그 방 참여자 한 명으로 정해져야 보내고, 없거나 여럿이면 `NotiBotApiError`(`mention_name_unknown` / `mention_name_ambiguous`, `body.candidates`)로 거절됩니다.
|
|
58
96
|
|
|
59
97
|
```ts
|
|
60
|
-
await bot.sendMessage({ roomSlug: "tf", text: "
|
|
98
|
+
await bot.sendMessage({ roomSlug: "tf", text: "@김철수 확인 부탁해요", mentions: ["김철수"] });
|
|
61
99
|
```
|
|
62
100
|
|
|
63
101
|
방에 누가 있는지는 `listRoomMembers`(목록만) 또는 `getRoomMembers`(검색 `q`, 인원 `known`/`total`, 오픈채팅 여부, 마지막 동기화)로 봅니다(`rooms:read` 권한). 카톡 방 정보에서 온 계정 ID와, 그 방에서 본 적 있는 표시 이름을 돌려줍니다.
|
|
64
102
|
|
|
65
103
|
```ts
|
|
66
104
|
const members = await bot.listRoomMembers({ roomSlug: "tf" });
|
|
67
|
-
// [{ userId: "
|
|
68
|
-
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 === "홍길동");
|
|
69
107
|
if (target) await bot.sendMessage({ roomSlug: "tf", text: `${target.mention} 확인 부탁해요` });
|
|
70
108
|
```
|
|
71
109
|
|
|
72
|
-
`name
|
|
110
|
+
`name`을 아직 모르는 사람은 `null`입니다. 이름을 모르면 태그 글자를 만들 수 없어 `mention_unresolved`로 발송되지 않습니다. 키워드 자동응답(rule) 서비스는 응답 문구에 `{보낸사람}`을 쓰면 말한 사람을 태그합니다.
|
|
73
111
|
|
|
74
|
-
그 방에 없는 사람이면 `mention_unresolved`로 발송되지 않습니다.
|
|
112
|
+
그 방에 없는 사람이면 `mention_unresolved`로 발송되지 않습니다. 상황에 따라 태그 없이 `@이름` 글자로만 나갈 수 있습니다.
|
|
75
113
|
|
|
76
114
|
## 오류 처리
|
|
77
115
|
|
|
@@ -122,7 +160,7 @@ pnpm --filter @noti-bot/sdk pack --pack-destination /tmp/notibot-sdk-release
|
|
|
122
160
|
|
|
123
161
|
## 키 권한
|
|
124
162
|
|
|
125
|
-
대시보드에서 키 이름과 허용 작업을 선택합니다. `listRooms()`는 `rooms:read`, `sendMessage()`는 `messages:send
|
|
163
|
+
대시보드에서 키 이름과 허용 작업을 선택합니다. `listRooms()`는 `rooms:read`, `sendMessage()`는 `messages:send`(이미지는 `messages:image`도)가 필요하며 부족하면 `403 insufficient_scope`가 반환됩니다. 키 권한은 워크스페이스의 방 범위를 넓히지 않습니다. 권한을 바꾸려면 새 키를 발급하고 연동을 교체한 뒤 이전 키를 폐기하세요.
|
|
126
164
|
|
|
127
165
|
## 실제 발송 없는 테스트 키
|
|
128
166
|
|
|
@@ -132,15 +170,14 @@ pnpm --filter @noti-bot/sdk pack --pack-destination /tmp/notibot-sdk-release
|
|
|
132
170
|
|
|
133
171
|
동일 API 키로 이미 접수한 `requestId`의 방 ID 또는 본문을 바꾸면 `409 idempotency_conflict`를 반환합니다. 동일한 방·본문은 중복으로 처리하며 추가 큐/사용량을 만들지 않습니다. slug/방 표시명 변경은 고정 방 ID가 같으면 충돌로 보지 않습니다. 기존 기록 중 본문 검증값이 없는 건은 방 변경만 검출하고 재발송하지 않습니다. 검증값은 서버 비밀키로 보호하므로 비밀키 교체 후 이전 요청의 재시도는 충돌할 수 있습니다.
|
|
134
172
|
|
|
135
|
-
###
|
|
173
|
+
### IDs and webhook events
|
|
136
174
|
|
|
137
175
|
`sendMessage` and `listRooms` retain their existing contracts. Prefer a `roomId` or
|
|
138
|
-
`roomSlug` to a display name.
|
|
139
|
-
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
|
|
140
177
|
hub, not delivered to a recipient, and uncertain sends must not be retried blindly.
|
|
141
178
|
|
|
142
179
|
`InboundWebhookEvent` describes signed webhook events, including optional
|
|
143
|
-
`roomExternalId`, `senderId`, and `imageBase64
|
|
180
|
+
`roomExternalId`, `senderId`, and `imageBase64`. Treat IDs as strings;
|
|
144
181
|
Kakao IDs may exceed JavaScript's safe integer range. Check `X-NotiBot-Signature`
|
|
145
182
|
against the raw request body before parsing. Images are only included for rooms
|
|
146
183
|
explicitly enabled by the owner.
|
package/dist/index.d.ts
CHANGED
|
@@ -27,17 +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. `["
|
|
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
|
+
/**
|
|
43
|
+
* Quote a message of the same room: pass `InboundWebhookEvent.messageId`.
|
|
44
|
+
* An unknown ID fails with `reply_target_not_found`.
|
|
45
|
+
*/
|
|
46
|
+
replyTo?: string;
|
|
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
|
+
});
|
|
41
61
|
export interface SendMessageResult {
|
|
42
62
|
ok: true;
|
|
43
63
|
queued: boolean;
|
|
@@ -98,6 +118,8 @@ export interface InboundWebhookEvent {
|
|
|
98
118
|
roomExternalId?: string;
|
|
99
119
|
sender: string;
|
|
100
120
|
senderId?: string;
|
|
121
|
+
/** KakaoTalk's ID of this message. Pass it as `replyTo` to quote it. */
|
|
122
|
+
messageId?: string;
|
|
101
123
|
msg: string;
|
|
102
124
|
command: string;
|
|
103
125
|
isMention: boolean;
|
|
@@ -105,7 +127,7 @@ export interface InboundWebhookEvent {
|
|
|
105
127
|
received_at: number;
|
|
106
128
|
/** Present only for rooms explicitly enabled by the owner. Never log image bytes. */
|
|
107
129
|
imageBase64?: string;
|
|
108
|
-
/** Accounts the message actually tagged
|
|
130
|
+
/** Accounts the message actually tagged. Compare userId, not name. */
|
|
109
131
|
mentions?: {
|
|
110
132
|
userId: string;
|
|
111
133
|
name?: string;
|
package/dist/index.js
CHANGED
|
@@ -43,21 +43,29 @@ 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
|
|
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
|
+
if (input.replyTo !== undefined && !/^\d{1,20}$/.test(input.replyTo))
|
|
58
|
+
throw new TypeError("replyTo must be a Kakao message ID (digits only).");
|
|
52
59
|
const data = await this.request(input.roomId !== undefined
|
|
53
60
|
? `/v1/rooms/id/${encodeURIComponent(input.roomId)}/messages`
|
|
54
61
|
: input.roomSlug !== undefined
|
|
55
62
|
? `/v1/rooms/${encodeURIComponent(input.roomSlug)}/messages`
|
|
56
63
|
: "/v1/messages", "POST", {
|
|
57
64
|
room: input.room,
|
|
58
|
-
msg: input.text,
|
|
65
|
+
...(input.imageUrl !== undefined ? { image_url: input.imageUrl } : { msg: input.text }),
|
|
59
66
|
request_id: requestId,
|
|
60
67
|
...(input.mentions ? { mentions: input.mentions } : {}),
|
|
68
|
+
...(input.replyTo ? { reply_to: input.replyTo } : {}),
|
|
61
69
|
}, options.signal, requestId);
|
|
62
70
|
if (!object(data) ||
|
|
63
71
|
data.ok !== true ||
|