@noti-bot/sdk 0.11.0 → 0.12.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 +15 -6
- package/dist/index.d.ts +27 -6
- package/dist/index.js +35 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -71,24 +71,33 @@ await kakao.sendMessage({
|
|
|
71
71
|
|
|
72
72
|
## 이미지 보내기
|
|
73
73
|
|
|
74
|
-
`text` 대신 `imageUrl
|
|
74
|
+
`text` 대신 `imageUrl`(공개 주소) 또는 `image`(파일 바이트)를 주면 이미지 한 장을 보냅니다. 키에 `messages:image` 권한이 있어야 합니다(키를 만들 때 따로 고릅니다).
|
|
75
75
|
|
|
76
76
|
```ts
|
|
77
|
+
// 주소로: 허브가 한 번 내려받습니다
|
|
77
78
|
await bot.sendMessage({
|
|
78
79
|
roomSlug: "reports",
|
|
79
80
|
imageUrl: "https://cdn.example.com/reports/2026-11-30.png",
|
|
80
81
|
requestId: "report:2026-11-30",
|
|
81
82
|
});
|
|
83
|
+
|
|
84
|
+
// 파일로: 공개 주소가 필요 없습니다(multipart/form-data 로 올라갑니다)
|
|
85
|
+
await bot.sendMessage({
|
|
86
|
+
roomSlug: "reports",
|
|
87
|
+
image: await fs.promises.readFile("chart.png"), // Blob 또는 Uint8Array
|
|
88
|
+
filename: "chart.png", // 선택. 허브는 무시합니다
|
|
89
|
+
requestId: "report:2026-12-01",
|
|
90
|
+
});
|
|
82
91
|
```
|
|
83
92
|
|
|
84
93
|
- 주소는 `https://`로 시작하는 공개 주소여야 하고, 리다이렉트 없이 이미지를 바로 돌려줘야 합니다.
|
|
85
|
-
- PNG·JPEG·GIF, 5MB
|
|
86
|
-
-
|
|
87
|
-
-
|
|
88
|
-
-
|
|
94
|
+
- PNG·JPEG·WebP·AVIF·GIF, 원본 15MB 이하(GIF는 5MB). 형식은 파일 내용으로 판단합니다.
|
|
95
|
+
- GIF 외에는 긴 변 2560px 이하로 줄이고 메타데이터(EXIF·위치 정보)를 지워서 보냅니다.
|
|
96
|
+
- `text`·`mentions`·`replyTo`와 같이 쓸 수 없고, `imageUrl`과 `image`도 같이 못 씁니다. 글을 같이 보내려면 요청을 따로 보내세요.
|
|
97
|
+
- 같은 `requestId`로 다시 보내면 중복으로 처리합니다. 같은 `requestId`에 다른 파일이면 `idempotency_conflict`.
|
|
89
98
|
- 이미지 메시지는 수정할 수 없습니다(REST `PATCH /v1/messages/{requestId}`는 `edit_not_supported`). 삭제와 공감은 됩니다.
|
|
90
99
|
|
|
91
|
-
거절은 `NotiBotApiError`의 `code`로 옵니다: `image_url_not_allowed`(보낼 수 없는 주소), `image_fetch_failed`(받지
|
|
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` 뒤 다시).
|
|
92
101
|
|
|
93
102
|
## 이름으로 태그
|
|
94
103
|
|
package/dist/index.d.ts
CHANGED
|
@@ -33,6 +33,8 @@ export type SendMessageInput = ({
|
|
|
33
33
|
/** `<@kakaoUserId>` (see {@link mention}) becomes a real Kakao tag. */
|
|
34
34
|
text: string;
|
|
35
35
|
imageUrl?: never;
|
|
36
|
+
image?: never;
|
|
37
|
+
filename?: never;
|
|
36
38
|
/**
|
|
37
39
|
* Tag people by display name (e.g. `["김철수"]`). Each must match exactly one room member;
|
|
38
40
|
* `@이름` in `text` becomes the tag, otherwise tags go first. Unknown or ambiguous names
|
|
@@ -46,14 +48,33 @@ export type SendMessageInput = ({
|
|
|
46
48
|
replyTo?: string;
|
|
47
49
|
} | {
|
|
48
50
|
/**
|
|
49
|
-
* Send one image instead of text: a public `https://` address of a PNG, JPEG
|
|
50
|
-
* to 5 MB, served directly (no redirect). The hub downloads it once
|
|
51
|
-
* request. Requires the `messages:image` scope. Cannot be combined
|
|
52
|
-
* `mentions` or `replyTo`. Rejections: `image_url_not_allowed`,
|
|
53
|
-
* `image_too_large`, `unsupported_image`,
|
|
54
|
-
*
|
|
51
|
+
* Send one image instead of text: a public `https://` address of a PNG, JPEG, WebP, AVIF
|
|
52
|
+
* or GIF up to 15 MB (GIF: 5 MB), served directly (no redirect). The hub downloads it once
|
|
53
|
+
* when it accepts the request. Requires the `messages:image` scope. Cannot be combined
|
|
54
|
+
* with `text`, `image`, `mentions` or `replyTo`. Rejections: `image_url_not_allowed`,
|
|
55
|
+
* `image_fetch_failed` (HTTP 422), `image_too_large`, `unsupported_image`,
|
|
56
|
+
* `image_send_disabled`, `image_busy`, `image_processing_unavailable` (HTTP 503, retry later).
|
|
57
|
+
* Images other than GIF are resized to at most 2560 px on the long side and their
|
|
58
|
+
* metadata (EXIF, location) is removed.
|
|
55
59
|
*/
|
|
56
60
|
imageUrl: string;
|
|
61
|
+
image?: never;
|
|
62
|
+
filename?: never;
|
|
63
|
+
text?: never;
|
|
64
|
+
mentions?: never;
|
|
65
|
+
replyTo?: never;
|
|
66
|
+
} | {
|
|
67
|
+
/**
|
|
68
|
+
* Upload one image file (`multipart/form-data`) instead of text: PNG, JPEG, WebP, AVIF or
|
|
69
|
+
* GIF up to 15 MB (GIF: 5 MB). Nothing is fetched by the hub, so no public URL is needed.
|
|
70
|
+
* Requires the `messages:image` scope. Cannot be combined with `text`, `imageUrl`,
|
|
71
|
+
* `mentions` or `replyTo`. The format is detected from the content, not from the name.
|
|
72
|
+
* Same rejections as `imageUrl`, plus `image_too_large` when the upload exceeds 15 MB.
|
|
73
|
+
*/
|
|
74
|
+
image: Blob | Uint8Array;
|
|
75
|
+
/** Optional file name for the upload. The hub ignores it. */
|
|
76
|
+
filename?: string;
|
|
77
|
+
imageUrl?: never;
|
|
57
78
|
text?: never;
|
|
58
79
|
mentions?: never;
|
|
59
80
|
replyTo?: never;
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,8 @@ export function mention(kakaoUserId) {
|
|
|
10
10
|
throw new TypeError("kakaoUserId must be a numeric Kakao user ID");
|
|
11
11
|
return `<@${kakaoUserId}>`;
|
|
12
12
|
}
|
|
13
|
+
/** Largest original image the hub accepts. */
|
|
14
|
+
const MAX_UPLOAD_BYTES = 15 * 1024 * 1024;
|
|
13
15
|
function object(value) {
|
|
14
16
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
15
17
|
}
|
|
@@ -43,8 +45,23 @@ export class NotiBot {
|
|
|
43
45
|
: input.roomSlug !== undefined
|
|
44
46
|
? !/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(input.roomSlug)
|
|
45
47
|
: !input.room?.trim()) ||
|
|
46
|
-
(input.imageUrl === undefined &&
|
|
48
|
+
(input.imageUrl === undefined &&
|
|
49
|
+
input.image === undefined &&
|
|
50
|
+
(!input.text?.trim() || input.text.length > 4000)))
|
|
47
51
|
throw new TypeError("room and text are required; text must be at most 4000 characters.");
|
|
52
|
+
if (input.imageUrl !== undefined && input.image !== undefined)
|
|
53
|
+
throw new TypeError("imageUrl and image cannot be combined.");
|
|
54
|
+
let upload;
|
|
55
|
+
if (input.image !== undefined) {
|
|
56
|
+
if (input.text !== undefined || input.mentions !== undefined || input.replyTo !== undefined)
|
|
57
|
+
throw new TypeError("image cannot be combined with text, mentions or replyTo.");
|
|
58
|
+
upload =
|
|
59
|
+
input.image instanceof Blob
|
|
60
|
+
? input.image
|
|
61
|
+
: new Blob([input.image]);
|
|
62
|
+
if (upload.size < 1 || upload.size > MAX_UPLOAD_BYTES)
|
|
63
|
+
throw new TypeError("image must be between 1 byte and 15 MB.");
|
|
64
|
+
}
|
|
48
65
|
if (input.imageUrl !== undefined) {
|
|
49
66
|
if (input.text !== undefined || input.mentions !== undefined || input.replyTo !== undefined)
|
|
50
67
|
throw new TypeError("imageUrl cannot be combined with text, mentions or replyTo.");
|
|
@@ -56,11 +73,20 @@ export class NotiBot {
|
|
|
56
73
|
throw new TypeError("requestId must contain 1 to 128 characters.");
|
|
57
74
|
if (input.replyTo !== undefined && !/^\d{1,20}$/.test(input.replyTo))
|
|
58
75
|
throw new TypeError("replyTo must be a Kakao message ID (digits only).");
|
|
76
|
+
let uploadForm;
|
|
77
|
+
if (upload) {
|
|
78
|
+
// room 과 request_id 를 파일보다 앞에 둔다: 허브가 한도 검사를 끝낸 뒤에 파일을 읽는다
|
|
79
|
+
uploadForm = new FormData();
|
|
80
|
+
if (input.room !== undefined)
|
|
81
|
+
uploadForm.append("room", input.room);
|
|
82
|
+
uploadForm.append("request_id", requestId);
|
|
83
|
+
uploadForm.append("image", upload, input.filename?.trim() || "image");
|
|
84
|
+
}
|
|
59
85
|
const data = await this.request(input.roomId !== undefined
|
|
60
86
|
? `/v1/rooms/id/${encodeURIComponent(input.roomId)}/messages`
|
|
61
87
|
: input.roomSlug !== undefined
|
|
62
88
|
? `/v1/rooms/${encodeURIComponent(input.roomSlug)}/messages`
|
|
63
|
-
: "/v1/messages", "POST", {
|
|
89
|
+
: "/v1/messages", "POST", uploadForm ?? {
|
|
64
90
|
room: input.room,
|
|
65
91
|
...(input.imageUrl !== undefined ? { image_url: input.imageUrl } : { msg: input.text }),
|
|
66
92
|
request_id: requestId,
|
|
@@ -152,9 +178,14 @@ export class NotiBot {
|
|
|
152
178
|
headers: {
|
|
153
179
|
Authorization: `Bearer ${this.apiKey}`,
|
|
154
180
|
Accept: "application/json",
|
|
155
|
-
|
|
181
|
+
// multipart: fetch sets the Content-Type with its boundary
|
|
182
|
+
...(body === undefined || body instanceof FormData
|
|
183
|
+
? {}
|
|
184
|
+
: { "Content-Type": "application/json" }),
|
|
156
185
|
},
|
|
157
|
-
...(body === undefined
|
|
186
|
+
...(body === undefined
|
|
187
|
+
? {}
|
|
188
|
+
: { body: body instanceof FormData ? body : JSON.stringify(body) }),
|
|
158
189
|
signal: combined,
|
|
159
190
|
// API keys must never be forwarded to a redirected origin.
|
|
160
191
|
redirect: "error",
|