@kyyinfinite/zapo-message 1.0.1 → 1.1.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/CHANGELOG.md +46 -0
- package/README.md +24 -1
- package/dist/airich/airich.js +13 -8
- package/dist/btn/builders.js +8 -2
- package/dist/btn/media-slot.js +12 -3
- package/dist/btn/thumbnail.js +18 -0
- package/dist/core/base-builder.d.ts +1 -0
- package/dist/core/base-builder.js +5 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/message/album.js +3 -2
- package/dist/message/forward.js +3 -2
- package/dist/message/index.d.ts +2 -0
- package/dist/message/index.js +1 -0
- package/dist/message/operations.d.ts +22 -0
- package/dist/message/operations.js +176 -0
- package/dist/message/reaction.js +3 -2
- package/package.json +111 -107
- package/src/airich/airich.ts +16 -7
- package/src/btn/builders.ts +12 -2
- package/src/btn/media-slot.ts +11 -3
- package/src/btn/thumbnail.ts +22 -0
- package/src/core/base-builder.ts +8 -0
- package/src/index.ts +13 -0
- package/src/message/album.ts +3 -2
- package/src/message/forward.ts +3 -2
- package/src/message/index.ts +13 -0
- package/src/message/operations.ts +325 -0
- package/src/message/reaction.ts +3 -2
- package/test/message-operations.test.ts +298 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kyyinfinite/zapo-message",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "WhatsApp message toolkit for ZapoJS: hybrid async + fluent builders (text, buttons, lists, media, stickers, polls, contacts, albums, reactions, forwards, location), AIRich rich responses, serialization and interactive parsing. Import once, use on any ZapoJS client.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "ISC",
|
|
@@ -35,42 +35,6 @@
|
|
|
35
35
|
"types": "./dist/index.d.ts",
|
|
36
36
|
"default": "./dist/index.js"
|
|
37
37
|
},
|
|
38
|
-
"./btn.js": {
|
|
39
|
-
"types": "./dist/btn.d.ts",
|
|
40
|
-
"default": "./dist/btn.js"
|
|
41
|
-
},
|
|
42
|
-
"./btn/builders.js": {
|
|
43
|
-
"types": "./dist/btn/builders.d.ts",
|
|
44
|
-
"default": "./dist/btn/builders.js"
|
|
45
|
-
},
|
|
46
|
-
"./btn/media-slot.js": {
|
|
47
|
-
"types": "./dist/btn/media-slot.d.ts",
|
|
48
|
-
"default": "./dist/btn/media-slot.js"
|
|
49
|
-
},
|
|
50
|
-
"./btn/media-source.js": {
|
|
51
|
-
"types": "./dist/btn/media-source.d.ts",
|
|
52
|
-
"default": "./dist/btn/media-source.js"
|
|
53
|
-
},
|
|
54
|
-
"./btn/thumbnail.js": {
|
|
55
|
-
"types": "./dist/btn/thumbnail.d.ts",
|
|
56
|
-
"default": "./dist/btn/thumbnail.js"
|
|
57
|
-
},
|
|
58
|
-
"./btn/validators.js": {
|
|
59
|
-
"types": "./dist/btn/validators.d.ts",
|
|
60
|
-
"default": "./dist/btn/validators.js"
|
|
61
|
-
},
|
|
62
|
-
"./core/base-builder.js": {
|
|
63
|
-
"types": "./dist/core/base-builder.d.ts",
|
|
64
|
-
"default": "./dist/core/base-builder.js"
|
|
65
|
-
},
|
|
66
|
-
"./core/errors.js": {
|
|
67
|
-
"types": "./dist/core/errors.d.ts",
|
|
68
|
-
"default": "./dist/core/errors.js"
|
|
69
|
-
},
|
|
70
|
-
"./airich/index.js": {
|
|
71
|
-
"types": "./dist/airich/index.d.ts",
|
|
72
|
-
"default": "./dist/airich/index.js"
|
|
73
|
-
},
|
|
74
38
|
"./airich/airich.js": {
|
|
75
39
|
"types": "./dist/airich/airich.d.ts",
|
|
76
40
|
"default": "./dist/airich/airich.js"
|
|
@@ -83,6 +47,10 @@
|
|
|
83
47
|
"types": "./dist/airich/encode.d.ts",
|
|
84
48
|
"default": "./dist/airich/encode.js"
|
|
85
49
|
},
|
|
50
|
+
"./airich/index.js": {
|
|
51
|
+
"types": "./dist/airich/index.d.ts",
|
|
52
|
+
"default": "./dist/airich/index.js"
|
|
53
|
+
},
|
|
86
54
|
"./airich/inline.js": {
|
|
87
55
|
"types": "./dist/airich/inline.d.ts",
|
|
88
56
|
"default": "./dist/airich/inline.js"
|
|
@@ -111,114 +79,150 @@
|
|
|
111
79
|
"types": "./dist/airich/transport.d.ts",
|
|
112
80
|
"default": "./dist/airich/transport.js"
|
|
113
81
|
},
|
|
114
|
-
"./
|
|
115
|
-
"types": "./dist/
|
|
116
|
-
"default": "./dist/
|
|
82
|
+
"./branding.js": {
|
|
83
|
+
"types": "./dist/branding.d.ts",
|
|
84
|
+
"default": "./dist/branding.js"
|
|
117
85
|
},
|
|
118
|
-
"./
|
|
119
|
-
"types": "./dist/
|
|
120
|
-
"default": "./dist/
|
|
86
|
+
"./btn.js": {
|
|
87
|
+
"types": "./dist/btn.d.ts",
|
|
88
|
+
"default": "./dist/btn.js"
|
|
89
|
+
},
|
|
90
|
+
"./btn/builders.js": {
|
|
91
|
+
"types": "./dist/btn/builders.d.ts",
|
|
92
|
+
"default": "./dist/btn/builders.js"
|
|
93
|
+
},
|
|
94
|
+
"./btn/media-slot.js": {
|
|
95
|
+
"types": "./dist/btn/media-slot.d.ts",
|
|
96
|
+
"default": "./dist/btn/media-slot.js"
|
|
97
|
+
},
|
|
98
|
+
"./btn/media-source.js": {
|
|
99
|
+
"types": "./dist/btn/media-source.d.ts",
|
|
100
|
+
"default": "./dist/btn/media-source.js"
|
|
101
|
+
},
|
|
102
|
+
"./btn/sharp-loader.js": {
|
|
103
|
+
"types": "./dist/btn/sharp-loader.d.ts",
|
|
104
|
+
"default": "./dist/btn/sharp-loader.js"
|
|
105
|
+
},
|
|
106
|
+
"./btn/thumbnail.js": {
|
|
107
|
+
"types": "./dist/btn/thumbnail.d.ts",
|
|
108
|
+
"default": "./dist/btn/thumbnail.js"
|
|
109
|
+
},
|
|
110
|
+
"./btn/validators.js": {
|
|
111
|
+
"types": "./dist/btn/validators.d.ts",
|
|
112
|
+
"default": "./dist/btn/validators.js"
|
|
113
|
+
},
|
|
114
|
+
"./core/async-send.js": {
|
|
115
|
+
"types": "./dist/core/async-send.d.ts",
|
|
116
|
+
"default": "./dist/core/async-send.js"
|
|
117
|
+
},
|
|
118
|
+
"./core/base-builder.js": {
|
|
119
|
+
"types": "./dist/core/base-builder.d.ts",
|
|
120
|
+
"default": "./dist/core/base-builder.js"
|
|
121
|
+
},
|
|
122
|
+
"./core/errors.js": {
|
|
123
|
+
"types": "./dist/core/errors.d.ts",
|
|
124
|
+
"default": "./dist/core/errors.js"
|
|
121
125
|
},
|
|
122
126
|
"./download.js": {
|
|
123
127
|
"types": "./dist/download.d.ts",
|
|
124
128
|
"default": "./dist/download.js"
|
|
125
129
|
},
|
|
126
|
-
"./
|
|
127
|
-
"types": "./dist/
|
|
128
|
-
"default": "./dist/
|
|
130
|
+
"./integration/augment.js": {
|
|
131
|
+
"types": "./dist/integration/augment.d.ts",
|
|
132
|
+
"default": "./dist/integration/augment.js"
|
|
133
|
+
},
|
|
134
|
+
"./integration/auto.js": {
|
|
135
|
+
"types": "./dist/integration/auto.d.ts",
|
|
136
|
+
"default": "./dist/integration/auto.js"
|
|
137
|
+
},
|
|
138
|
+
"./integration/index.js": {
|
|
139
|
+
"types": "./dist/integration/index.d.ts",
|
|
140
|
+
"default": "./dist/integration/index.js"
|
|
141
|
+
},
|
|
142
|
+
"./integration/methods.js": {
|
|
143
|
+
"types": "./dist/integration/methods.d.ts",
|
|
144
|
+
"default": "./dist/integration/methods.js"
|
|
145
|
+
},
|
|
146
|
+
"./interactive.js": {
|
|
147
|
+
"types": "./dist/interactive.d.ts",
|
|
148
|
+
"default": "./dist/interactive.js"
|
|
129
149
|
},
|
|
130
150
|
"./media-gate.js": {
|
|
131
151
|
"types": "./dist/media-gate.d.ts",
|
|
132
152
|
"default": "./dist/media-gate.js"
|
|
133
153
|
},
|
|
134
|
-
"./
|
|
135
|
-
"types": "./dist/
|
|
136
|
-
"default": "./dist/
|
|
154
|
+
"./message/album.js": {
|
|
155
|
+
"types": "./dist/message/album.d.ts",
|
|
156
|
+
"default": "./dist/message/album.js"
|
|
137
157
|
},
|
|
138
|
-
"./
|
|
139
|
-
"types": "./dist/
|
|
140
|
-
"default": "./dist/
|
|
158
|
+
"./message/contact.js": {
|
|
159
|
+
"types": "./dist/message/contact.d.ts",
|
|
160
|
+
"default": "./dist/message/contact.js"
|
|
161
|
+
},
|
|
162
|
+
"./message/forward.js": {
|
|
163
|
+
"types": "./dist/message/forward.d.ts",
|
|
164
|
+
"default": "./dist/message/forward.js"
|
|
141
165
|
},
|
|
142
|
-
"./package.json": "./package.json",
|
|
143
166
|
"./message/index.js": {
|
|
144
167
|
"types": "./dist/message/index.d.ts",
|
|
145
168
|
"default": "./dist/message/index.js"
|
|
146
169
|
},
|
|
147
|
-
"./message/text.js": {
|
|
148
|
-
"types": "./dist/message/text.d.ts",
|
|
149
|
-
"default": "./dist/message/text.js"
|
|
150
|
-
},
|
|
151
170
|
"./message/link-preview.js": {
|
|
152
171
|
"types": "./dist/message/link-preview.d.ts",
|
|
153
172
|
"default": "./dist/message/link-preview.js"
|
|
154
173
|
},
|
|
155
|
-
"./message/
|
|
156
|
-
"types": "./dist/message/
|
|
157
|
-
"default": "./dist/message/
|
|
174
|
+
"./message/location.js": {
|
|
175
|
+
"types": "./dist/message/location.d.ts",
|
|
176
|
+
"default": "./dist/message/location.js"
|
|
158
177
|
},
|
|
159
|
-
"./message/
|
|
160
|
-
"types": "./dist/message/
|
|
161
|
-
"default": "./dist/message/
|
|
178
|
+
"./message/media.js": {
|
|
179
|
+
"types": "./dist/message/media.d.ts",
|
|
180
|
+
"default": "./dist/message/media.js"
|
|
162
181
|
},
|
|
163
|
-
"./message/
|
|
164
|
-
"types": "./dist/message/
|
|
165
|
-
"default": "./dist/message/
|
|
182
|
+
"./message/operations.js": {
|
|
183
|
+
"types": "./dist/message/operations.d.ts",
|
|
184
|
+
"default": "./dist/message/operations.js"
|
|
166
185
|
},
|
|
167
186
|
"./message/poll.js": {
|
|
168
187
|
"types": "./dist/message/poll.d.ts",
|
|
169
188
|
"default": "./dist/message/poll.js"
|
|
170
189
|
},
|
|
171
|
-
"./message/
|
|
172
|
-
"types": "./dist/message/
|
|
173
|
-
"default": "./dist/message/
|
|
190
|
+
"./message/reaction.js": {
|
|
191
|
+
"types": "./dist/message/reaction.d.ts",
|
|
192
|
+
"default": "./dist/message/reaction.js"
|
|
174
193
|
},
|
|
175
194
|
"./message/sticker.js": {
|
|
176
195
|
"types": "./dist/message/sticker.d.ts",
|
|
177
196
|
"default": "./dist/message/sticker.js"
|
|
178
197
|
},
|
|
179
|
-
"./message/album.js": {
|
|
180
|
-
"types": "./dist/message/album.d.ts",
|
|
181
|
-
"default": "./dist/message/album.js"
|
|
182
|
-
},
|
|
183
|
-
"./message/webp.js": {
|
|
184
|
-
"types": "./dist/message/webp.d.ts",
|
|
185
|
-
"default": "./dist/message/webp.js"
|
|
186
|
-
},
|
|
187
|
-
"./message/vcard.js": {
|
|
188
|
-
"types": "./dist/message/vcard.d.ts",
|
|
189
|
-
"default": "./dist/message/vcard.js"
|
|
190
|
-
},
|
|
191
198
|
"./message/target.js": {
|
|
192
199
|
"types": "./dist/message/target.d.ts",
|
|
193
200
|
"default": "./dist/message/target.js"
|
|
194
201
|
},
|
|
195
|
-
"./
|
|
196
|
-
"types": "./dist/
|
|
197
|
-
"default": "./dist/
|
|
198
|
-
},
|
|
199
|
-
"./integration/auto.js": {
|
|
200
|
-
"types": "./dist/integration/auto.d.ts",
|
|
201
|
-
"default": "./dist/integration/auto.js"
|
|
202
|
+
"./message/text.js": {
|
|
203
|
+
"types": "./dist/message/text.d.ts",
|
|
204
|
+
"default": "./dist/message/text.js"
|
|
202
205
|
},
|
|
203
|
-
"./
|
|
204
|
-
"types": "./dist/
|
|
205
|
-
"default": "./dist/
|
|
206
|
+
"./message/vcard.js": {
|
|
207
|
+
"types": "./dist/message/vcard.d.ts",
|
|
208
|
+
"default": "./dist/message/vcard.js"
|
|
206
209
|
},
|
|
207
|
-
"./
|
|
208
|
-
"types": "./dist/
|
|
209
|
-
"default": "./dist/
|
|
210
|
+
"./message/webp.js": {
|
|
211
|
+
"types": "./dist/message/webp.d.ts",
|
|
212
|
+
"default": "./dist/message/webp.js"
|
|
210
213
|
},
|
|
211
|
-
"./
|
|
212
|
-
|
|
213
|
-
"
|
|
214
|
+
"./package.json": "./package.json",
|
|
215
|
+
"./serialize.js": {
|
|
216
|
+
"types": "./dist/serialize.d.ts",
|
|
217
|
+
"default": "./dist/serialize.js"
|
|
214
218
|
},
|
|
215
|
-
"./
|
|
216
|
-
"types": "./dist/
|
|
217
|
-
"default": "./dist/
|
|
219
|
+
"./status.js": {
|
|
220
|
+
"types": "./dist/status.d.ts",
|
|
221
|
+
"default": "./dist/status.js"
|
|
218
222
|
},
|
|
219
|
-
"./
|
|
220
|
-
"types": "./dist/
|
|
221
|
-
"default": "./dist/
|
|
223
|
+
"./zapo-client.js": {
|
|
224
|
+
"types": "./dist/zapo-client.d.ts",
|
|
225
|
+
"default": "./dist/zapo-client.js"
|
|
222
226
|
}
|
|
223
227
|
},
|
|
224
228
|
"files": [
|
|
@@ -251,8 +255,8 @@
|
|
|
251
255
|
"prepack": "npm run build"
|
|
252
256
|
},
|
|
253
257
|
"peerDependencies": {
|
|
254
|
-
"
|
|
255
|
-
"
|
|
258
|
+
"sharp": ">=0.33.0",
|
|
259
|
+
"zapo-js": ">=1.11.0 <2.0.0"
|
|
256
260
|
},
|
|
257
261
|
"dependencies": {
|
|
258
262
|
"file-type": "^22.0.2"
|
|
@@ -261,9 +265,9 @@
|
|
|
261
265
|
"@types/node": "^22.10.0",
|
|
262
266
|
"@zapo-js/fake-server": "1.3.1",
|
|
263
267
|
"prettier": "^3.4.2",
|
|
268
|
+
"sharp": "^0.35.4",
|
|
264
269
|
"typescript": "^5.7.2",
|
|
265
|
-
"zapo-js": "1.11.0"
|
|
266
|
-
"sharp": "^0.35.4"
|
|
270
|
+
"zapo-js": "1.11.0"
|
|
267
271
|
},
|
|
268
272
|
"peerDependenciesMeta": {
|
|
269
273
|
"sharp": {
|
package/src/airich/airich.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { BaseBuilder, type SendResolutionArg } from "../core/base-builder.js";
|
|
|
5
5
|
import { sendConfigured, type MessageSendOptions } from "../core/async-send.js";
|
|
6
6
|
import type { MessageSendResult } from "../zapo-client.js";
|
|
7
7
|
import {
|
|
8
|
+
MessageError,
|
|
8
9
|
ValidationError,
|
|
9
10
|
ItemNotFoundError,
|
|
10
11
|
InvalidTargetError,
|
|
@@ -640,7 +641,15 @@ export class AIRich extends BaseBuilder {
|
|
|
640
641
|
|
|
641
642
|
override async send(jid?: string, arg?: SendResolutionArg): Promise<unknown> {
|
|
642
643
|
const { client, options } = this._resolve(arg);
|
|
643
|
-
const
|
|
644
|
+
const target = typeof jid === "string" && jid ? jid : this._defaultTarget();
|
|
645
|
+
if (!target) {
|
|
646
|
+
throw new MessageError(
|
|
647
|
+
"tujuan airich tidak diketahui. panggil send(jid) atau .defaultTo(jid)",
|
|
648
|
+
"NO_TARGET",
|
|
649
|
+
);
|
|
650
|
+
}
|
|
651
|
+
const { twoStep = true, submessages = true, ...restOptions } = options;
|
|
652
|
+
const sendOptions = this._mergedOptions(restOptions);
|
|
644
653
|
|
|
645
654
|
if (!twoStep) {
|
|
646
655
|
const direct = wrapBotForwarded(
|
|
@@ -652,7 +661,7 @@ export class AIRich extends BaseBuilder {
|
|
|
652
661
|
);
|
|
653
662
|
const result = await sendViaZapo(
|
|
654
663
|
client,
|
|
655
|
-
|
|
664
|
+
target,
|
|
656
665
|
direct,
|
|
657
666
|
sendOptions,
|
|
658
667
|
);
|
|
@@ -662,20 +671,20 @@ export class AIRich extends BaseBuilder {
|
|
|
662
671
|
|
|
663
672
|
const sent = await sendPlaceholderThenEdit({
|
|
664
673
|
client,
|
|
665
|
-
jid:
|
|
674
|
+
jid: target,
|
|
666
675
|
placeholder: this.buildPlaceholder(),
|
|
667
676
|
buildEdit: (messageId) =>
|
|
668
|
-
this.buildEdit(
|
|
677
|
+
this.buildEdit(target, messageId, {
|
|
669
678
|
submessages: Boolean(submessages),
|
|
670
679
|
}),
|
|
671
680
|
options: sendOptions,
|
|
672
|
-
onPlaceholderSent: (
|
|
681
|
+
onPlaceholderSent: (sentTarget, messageId) => {
|
|
673
682
|
this.#lastId = messageId;
|
|
674
|
-
this.#pendingEdits.set(
|
|
683
|
+
this.#pendingEdits.set(sentTarget, messageId);
|
|
675
684
|
},
|
|
676
685
|
});
|
|
677
686
|
|
|
678
|
-
this.#pendingEdits.delete(
|
|
687
|
+
this.#pendingEdits.delete(target);
|
|
679
688
|
return sent;
|
|
680
689
|
}
|
|
681
690
|
|
package/src/btn/builders.ts
CHANGED
|
@@ -267,6 +267,15 @@ class HeaderMessage extends BaseMessage {
|
|
|
267
267
|
`.${kind}() tidak bisa dipakai bareng .headerThumbnail() — thumbnail gambar header pakai .${kind}(source, { thumbnail })`,
|
|
268
268
|
);
|
|
269
269
|
}
|
|
270
|
+
if (
|
|
271
|
+
kind === "document" &&
|
|
272
|
+
options.fileName === undefined &&
|
|
273
|
+
typeof source !== "string"
|
|
274
|
+
) {
|
|
275
|
+
throw new ValidationError(
|
|
276
|
+
`header ${kind} butuh fileName — berikan options.fileName (sumber bukan path tidak bisa menebak nama file)`,
|
|
277
|
+
);
|
|
278
|
+
}
|
|
270
279
|
this._mediaSlot = {
|
|
271
280
|
kind,
|
|
272
281
|
source,
|
|
@@ -808,9 +817,10 @@ export class ListMessage extends BaseMessage {
|
|
|
808
817
|
const useNativeFlow =
|
|
809
818
|
this._fallback === "native" || (this._fallback === "auto" && isGroup);
|
|
810
819
|
const content = useNativeFlow ? this.toNativeFlow() : this.build();
|
|
820
|
+
const merged = this._mergedOptions(options);
|
|
811
821
|
const send = client.message.send.bind(client.message);
|
|
812
|
-
return Object.keys(
|
|
813
|
-
? send(target, content,
|
|
822
|
+
return Object.keys(merged).length
|
|
823
|
+
? send(target, content, merged as ZapoSendOptions)
|
|
814
824
|
: send(target, content);
|
|
815
825
|
}
|
|
816
826
|
}
|
package/src/btn/media-slot.ts
CHANGED
|
@@ -164,9 +164,17 @@ const resolveThumbnail = async (
|
|
|
164
164
|
});
|
|
165
165
|
}
|
|
166
166
|
if (kind === "image" && bytes) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
167
|
+
try {
|
|
168
|
+
return await generateImageThumbnail(bytes, {
|
|
169
|
+
label: `${label} (thumbnail otomatis)`,
|
|
170
|
+
});
|
|
171
|
+
} catch (error) {
|
|
172
|
+
const meta = (error as MediaError) as { kind?: string };
|
|
173
|
+
if (error instanceof MediaError && meta.kind === "thumbnail_failed") {
|
|
174
|
+
return undefined;
|
|
175
|
+
}
|
|
176
|
+
throw error;
|
|
177
|
+
}
|
|
170
178
|
}
|
|
171
179
|
if (kind === "sticker" && bytes) {
|
|
172
180
|
return generatePngThumbnail(bytes, {
|
package/src/btn/thumbnail.ts
CHANGED
|
@@ -87,6 +87,10 @@ export const generateImageThumbnail = async (
|
|
|
87
87
|
}: GenerateThumbnailOptions = {},
|
|
88
88
|
): Promise<Buffer> => {
|
|
89
89
|
const input = asThumbnailBytes(bytes);
|
|
90
|
+
if (isJpegBytes(input)) {
|
|
91
|
+
const withinLimit = await isWithinThumbnailLimit(input, maxDimension);
|
|
92
|
+
if (withinLimit) return bufferFromBytes(input);
|
|
93
|
+
}
|
|
90
94
|
const sharp = await loadSharp();
|
|
91
95
|
if (!sharp) {
|
|
92
96
|
throw new MediaError(
|
|
@@ -180,3 +184,21 @@ const describeBytes = (bytes: Uint8Array): string => {
|
|
|
180
184
|
.join(" ");
|
|
181
185
|
return `bytes dengan magic ${hex}`;
|
|
182
186
|
};
|
|
187
|
+
|
|
188
|
+
const isWithinThumbnailLimit = async (
|
|
189
|
+
bytes: Uint8Array,
|
|
190
|
+
maxDimension: number,
|
|
191
|
+
): Promise<boolean> => {
|
|
192
|
+
const sharp = await loadSharp();
|
|
193
|
+
if (!sharp) return true;
|
|
194
|
+
const metadata = await sharp(bytes).metadata().catch(() => undefined);
|
|
195
|
+
if (
|
|
196
|
+
metadata?.width === undefined ||
|
|
197
|
+
metadata?.height === undefined ||
|
|
198
|
+
!Number.isFinite(metadata.width) ||
|
|
199
|
+
!Number.isFinite(metadata.height)
|
|
200
|
+
) {
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
return metadata.width <= maxDimension && metadata.height <= maxDimension;
|
|
204
|
+
};
|
package/src/core/base-builder.ts
CHANGED
|
@@ -56,6 +56,14 @@ export class BaseBuilder<
|
|
|
56
56
|
return this.#defaultJid;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
protected _mergedOptions(
|
|
60
|
+
options: Record<string, unknown>,
|
|
61
|
+
): Record<string, unknown> {
|
|
62
|
+
return this.#defaultQuote !== undefined && options.quote === undefined
|
|
63
|
+
? { quote: this.#defaultQuote, ...options }
|
|
64
|
+
: options;
|
|
65
|
+
}
|
|
66
|
+
|
|
59
67
|
build(): TBuild | Promise<TBuild> {
|
|
60
68
|
throw new MessageError(
|
|
61
69
|
`${this.constructor.name}.build() belum diimplementasi`,
|
package/src/index.ts
CHANGED
|
@@ -227,3 +227,16 @@ export const messageKit = (client?: ZapoClient) => ({
|
|
|
227
227
|
listMessage: () => listMessage(client),
|
|
228
228
|
airich: (options?: AIRichConstructorOptions) => airich(client, options),
|
|
229
229
|
});
|
|
230
|
+
export {
|
|
231
|
+
editMessage,
|
|
232
|
+
revokeMessage,
|
|
233
|
+
pinMessage,
|
|
234
|
+
unpinMessage,
|
|
235
|
+
keepMessage,
|
|
236
|
+
unkeepMessage,
|
|
237
|
+
votePoll,
|
|
238
|
+
sendEvent,
|
|
239
|
+
respondEvent,
|
|
240
|
+
resolveMessageTargetKey,
|
|
241
|
+
} from "./message/operations.js";
|
|
242
|
+
export type { PollVoteInput, MessageOperationTargetInput } from "./message/operations.js";
|
package/src/message/album.ts
CHANGED
|
@@ -110,7 +110,8 @@ export class AlbumBuilder extends BaseBuilder<AlbumBuildResult> {
|
|
|
110
110
|
|
|
111
111
|
const children = await this.resolveChildren();
|
|
112
112
|
const album = this.build();
|
|
113
|
-
const
|
|
113
|
+
const mergedOptions = this._mergedOptions(options);
|
|
114
|
+
const albumOptions: ZapoSendOptions = { ...mergedOptions };
|
|
114
115
|
const albumSend = client.message.send.bind(client.message);
|
|
115
116
|
const albumResult = (await (Object.keys(albumOptions).length
|
|
116
117
|
? albumSend(target, album, albumOptions)
|
|
@@ -124,7 +125,7 @@ export class AlbumBuilder extends BaseBuilder<AlbumBuildResult> {
|
|
|
124
125
|
const selfJid = resolveSelfJid(client);
|
|
125
126
|
for (const child of children) {
|
|
126
127
|
const childOptions: ZapoSendOptions = {
|
|
127
|
-
...
|
|
128
|
+
...mergedOptions,
|
|
128
129
|
quote: {
|
|
129
130
|
id: albumId,
|
|
130
131
|
remoteJid: target,
|
package/src/message/forward.ts
CHANGED
|
@@ -72,10 +72,11 @@ export class ForwardBuilder extends BaseBuilder<Proto.IMessage> {
|
|
|
72
72
|
"NO_SOURCE",
|
|
73
73
|
);
|
|
74
74
|
}
|
|
75
|
+
const merged = this._mergedOptions(options);
|
|
75
76
|
const sendOptions: ZapoSendOptions = {
|
|
76
|
-
...
|
|
77
|
+
...merged,
|
|
77
78
|
forward:
|
|
78
|
-
|
|
79
|
+
merged.forward ??
|
|
79
80
|
(this.#score !== undefined ? { score: this.#score } : true),
|
|
80
81
|
};
|
|
81
82
|
return client.message.send(target, this.build(), sendOptions);
|
package/src/message/index.ts
CHANGED
|
@@ -81,3 +81,16 @@ export { buildVcard } from "./vcard.js";
|
|
|
81
81
|
export type { VcardInput } from "./vcard.js";
|
|
82
82
|
export { targetKeyOf, targetChatJidOf, targetIdOf } from "./target.js";
|
|
83
83
|
export type { MessageKeyLike, MessageTargetLike } from "./target.js";
|
|
84
|
+
export {
|
|
85
|
+
editMessage,
|
|
86
|
+
revokeMessage,
|
|
87
|
+
pinMessage,
|
|
88
|
+
unpinMessage,
|
|
89
|
+
keepMessage,
|
|
90
|
+
unkeepMessage,
|
|
91
|
+
votePoll,
|
|
92
|
+
sendEvent,
|
|
93
|
+
respondEvent,
|
|
94
|
+
resolveMessageTargetKey,
|
|
95
|
+
} from "./operations.js";
|
|
96
|
+
export type { PollVoteInput, MessageOperationTargetInput } from "./operations.js";
|