mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
Update deps to latest and align tests
This commit is contained in:
11
package.json
11
package.json
@@ -38,8 +38,8 @@
|
|||||||
"json5": "^2.2.3",
|
"json5": "^2.2.3",
|
||||||
"qrcode-terminal": "^0.12.0",
|
"qrcode-terminal": "^0.12.0",
|
||||||
"twilio": "^5.10.6",
|
"twilio": "^5.10.6",
|
||||||
"@whiskeysockets/baileys": "^6.7.7",
|
"pino": "^10.1.0",
|
||||||
"pino": "^9.4.0"
|
"baileys": "^7.0.0-rc.9"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@biomejs/biome": "^2.3.7",
|
"@biomejs/biome": "^2.3.7",
|
||||||
@@ -49,6 +49,11 @@
|
|||||||
"@types/node": "^24.10.1",
|
"@types/node": "^24.10.1",
|
||||||
"tsx": "^4.20.6",
|
"tsx": "^4.20.6",
|
||||||
"typescript": "^5.9.3",
|
"typescript": "^5.9.3",
|
||||||
"vitest": "^2.1.4"
|
"vitest": "^4.0.13"
|
||||||
|
},
|
||||||
|
"vitest": {
|
||||||
|
"exclude": [
|
||||||
|
"dist/**"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
import { normalizeE164, toWhatsappJid, assertProvider } from "./index.js";
|
import { assertProvider, normalizeE164, toWhatsappJid } from "./index.js";
|
||||||
|
|
||||||
describe("normalizeE164", () => {
|
describe("normalizeE164", () => {
|
||||||
it("strips whatsapp: prefix and whitespace", () => {
|
it("strips whatsapp: prefix and whitespace", () => {
|
||||||
|
|||||||
54
src/index.ts
54
src/index.ts
@@ -5,23 +5,23 @@ import net from "node:net";
|
|||||||
import os from "node:os";
|
import os from "node:os";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import process, { stdin as input, stdout as output } from "node:process";
|
import process, { stdin as input, stdout as output } from "node:process";
|
||||||
import { fileURLToPath } from "node:url";
|
|
||||||
import readline from "node:readline/promises";
|
import readline from "node:readline/promises";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
import { promisify } from "node:util";
|
import { promisify } from "node:util";
|
||||||
import bodyParser from "body-parser";
|
import type { ConnectionState } from "baileys";
|
||||||
import chalk from "chalk";
|
|
||||||
import { Command } from "commander";
|
|
||||||
import dotenv from "dotenv";
|
|
||||||
import express, { type Request, type Response } from "express";
|
|
||||||
import JSON5 from "json5";
|
|
||||||
import {
|
import {
|
||||||
DisconnectReason,
|
DisconnectReason,
|
||||||
fetchLatestBaileysVersion,
|
fetchLatestBaileysVersion,
|
||||||
makeCacheableSignalKeyStore,
|
makeCacheableSignalKeyStore,
|
||||||
makeWASocket,
|
makeWASocket,
|
||||||
useMultiFileAuthState,
|
useMultiFileAuthState,
|
||||||
} from "@whiskeysockets/baileys";
|
} from "baileys";
|
||||||
import type { ConnectionState } from "@whiskeysockets/baileys";
|
import bodyParser from "body-parser";
|
||||||
|
import chalk from "chalk";
|
||||||
|
import { Command } from "commander";
|
||||||
|
import dotenv from "dotenv";
|
||||||
|
import express, { type Request, type Response } from "express";
|
||||||
|
import JSON5 from "json5";
|
||||||
import pino from "pino";
|
import pino from "pino";
|
||||||
import qrcode from "qrcode-terminal";
|
import qrcode from "qrcode-terminal";
|
||||||
import Twilio from "twilio";
|
import Twilio from "twilio";
|
||||||
@@ -729,10 +729,13 @@ async function createWaSocket(printQr: boolean, verbose: boolean) {
|
|||||||
qrcode.generate(qr, { small: true });
|
qrcode.generate(qr, { small: true });
|
||||||
}
|
}
|
||||||
if (connection === "close") {
|
if (connection === "close") {
|
||||||
const code = (lastDisconnect?.error as { output?: { statusCode?: number } })
|
const code = (
|
||||||
?.output?.statusCode;
|
lastDisconnect?.error as { output?: { statusCode?: number } }
|
||||||
|
)?.output?.statusCode;
|
||||||
if (code === DisconnectReason.loggedOut) {
|
if (code === DisconnectReason.loggedOut) {
|
||||||
console.error(danger("WhatsApp session logged out. Run: warelay web:login"));
|
console.error(
|
||||||
|
danger("WhatsApp session logged out. Run: warelay web:login"),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (connection === "open" && verbose) {
|
if (connection === "open" && verbose) {
|
||||||
@@ -745,22 +748,23 @@ async function createWaSocket(printQr: boolean, verbose: boolean) {
|
|||||||
|
|
||||||
async function waitForWaConnection(sock: ReturnType<typeof makeWASocket>) {
|
async function waitForWaConnection(sock: ReturnType<typeof makeWASocket>) {
|
||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
const handler = (update: Partial<ConnectionState>) => {
|
type OffCapable = {
|
||||||
|
off?: (event: string, listener: (...args: unknown[]) => void) => void;
|
||||||
|
};
|
||||||
|
const evWithOff = sock.ev as unknown as OffCapable;
|
||||||
|
|
||||||
|
const handler = (...args: unknown[]) => {
|
||||||
|
const update = (args[0] ?? {}) as Partial<ConnectionState>;
|
||||||
if (update.connection === "open") {
|
if (update.connection === "open") {
|
||||||
(sock.ev as unknown as { off?: Function }).off?.(
|
evWithOff.off?.("connection.update", handler);
|
||||||
"connection.update",
|
|
||||||
handler,
|
|
||||||
);
|
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
if (update.connection === "close") {
|
if (update.connection === "close") {
|
||||||
(sock.ev as unknown as { off?: Function }).off?.(
|
evWithOff.off?.("connection.update", handler);
|
||||||
"connection.update",
|
|
||||||
handler,
|
|
||||||
);
|
|
||||||
reject(update.lastDisconnect ?? new Error("Connection closed"));
|
reject(update.lastDisconnect ?? new Error("Connection closed"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
sock.ev.on("connection.update", handler);
|
sock.ev.on("connection.update", handler);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -778,9 +782,7 @@ async function sendMessageWeb(to: string, body: string) {
|
|||||||
const result = await sock.sendMessage(jid, { text: body });
|
const result = await sock.sendMessage(jid, { text: body });
|
||||||
const messageId = result?.key?.id ?? "unknown";
|
const messageId = result?.key?.id ?? "unknown";
|
||||||
console.log(
|
console.log(
|
||||||
success(
|
success(`✅ Sent via web session. Message ID: ${messageId} -> ${jid}`),
|
||||||
`✅ Sent via web session. Message ID: ${messageId} -> ${jid}`,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
@@ -1579,7 +1581,9 @@ Examples:
|
|||||||
|
|
||||||
if (opts.provider === "web") {
|
if (opts.provider === "web") {
|
||||||
if (waitSeconds !== 0) {
|
if (waitSeconds !== 0) {
|
||||||
console.log(info("Wait/poll are Twilio-only; ignored for provider=web."));
|
console.log(
|
||||||
|
info("Wait/poll are Twilio-only; ignored for provider=web."),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
await sendMessageWeb(opts.to, opts.message);
|
await sendMessageWeb(opts.to, opts.message);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -14,5 +14,5 @@
|
|||||||
"allowSyntheticDefaultImports": true
|
"allowSyntheticDefaultImports": true
|
||||||
},
|
},
|
||||||
"include": ["src/**/*"],
|
"include": ["src/**/*"],
|
||||||
"exclude": ["node_modules", "dist"]
|
"exclude": ["node_modules", "dist", "src/**/*.test.ts", "src/**/*.test.tsx"]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user