@daolmedo/openclaw-twilio-whatsapp 1.1.2 → 1.1.4
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/dist/index.js +13 -13
- package/openclaw.plugin.json +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -177,7 +177,6 @@ var twilioWhatsappPlugin = {
|
|
|
177
177
|
// src/http-routes.ts
|
|
178
178
|
import { dispatchInboundDirectDmWithRuntime } from "openclaw/plugin-sdk/direct-dm";
|
|
179
179
|
import {
|
|
180
|
-
fetchRemoteMedia,
|
|
181
180
|
saveMediaBuffer
|
|
182
181
|
} from "openclaw/plugin-sdk/media-runtime";
|
|
183
182
|
|
|
@@ -233,22 +232,23 @@ function twimlError(res, status, message) {
|
|
|
233
232
|
async function downloadTwilioMedia(url, account) {
|
|
234
233
|
try {
|
|
235
234
|
const authHeader = "Basic " + Buffer.from(`${account.accountSid}:${account.authToken}`).toString("base64");
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
...init,
|
|
240
|
-
headers: {
|
|
241
|
-
...init?.headers,
|
|
242
|
-
Authorization: authHeader
|
|
243
|
-
}
|
|
244
|
-
}),
|
|
245
|
-
maxBytes: MEDIA_MAX_BYTES,
|
|
246
|
-
readIdleTimeoutMs: 3e4
|
|
235
|
+
const response = await fetch(url, {
|
|
236
|
+
headers: { Authorization: authHeader },
|
|
237
|
+
signal: AbortSignal.timeout(3e4)
|
|
247
238
|
});
|
|
239
|
+
if (!response.ok) {
|
|
240
|
+
throw new Error(`HTTP ${response.status} fetching media`);
|
|
241
|
+
}
|
|
242
|
+
const contentType = response.headers.get("content-type") ?? "application/octet-stream";
|
|
243
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
244
|
+
if (arrayBuffer.byteLength > MEDIA_MAX_BYTES) {
|
|
245
|
+
throw new Error(`Media too large: ${arrayBuffer.byteLength} bytes`);
|
|
246
|
+
}
|
|
247
|
+
const buffer = Buffer.from(arrayBuffer);
|
|
248
248
|
const saved = await saveMediaBuffer(buffer, contentType, "inbound", MEDIA_MAX_BYTES);
|
|
249
249
|
return {
|
|
250
250
|
path: saved.path,
|
|
251
|
-
contentType: saved.contentType ?? contentType
|
|
251
|
+
contentType: saved.contentType ?? contentType
|
|
252
252
|
};
|
|
253
253
|
} catch (err) {
|
|
254
254
|
console.error("[twilio-whatsapp] Failed to download media:", url, err);
|
package/openclaw.plugin.json
CHANGED