omp-wechat 1.7.0 → 1.8.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/dist/index.js +22 -11
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1188,6 +1188,11 @@ var logger = {
|
|
|
1188
1188
|
var STATE_DIR = join3(homedir2(), ".omp-wechat");
|
|
1189
1189
|
var CREDENTIALS_FILE = join3(STATE_DIR, "credentials.json");
|
|
1190
1190
|
var SYNC_BUF_FILE = join3(STATE_DIR, "sync_buf.txt");
|
|
1191
|
+
var CHANNEL_VERSION = "2.2.0";
|
|
1192
|
+
var BOT_AGENT = "OMP-Wechat/1.7.0";
|
|
1193
|
+
function baseInfo() {
|
|
1194
|
+
return { channel_version: CHANNEL_VERSION, bot_agent: BOT_AGENT };
|
|
1195
|
+
}
|
|
1191
1196
|
function loadCredentials() {
|
|
1192
1197
|
try {
|
|
1193
1198
|
return JSON.parse(readFileSync(CREDENTIALS_FILE, "utf8"));
|
|
@@ -1241,7 +1246,15 @@ async function apiFetch(creds, endpoint, body, timeoutMs = 15000) {
|
|
|
1241
1246
|
const text = await res.text();
|
|
1242
1247
|
if (!res.ok)
|
|
1243
1248
|
throw new Error(`${endpoint} ${res.status}: ${text}`);
|
|
1244
|
-
|
|
1249
|
+
const data = JSON.parse(text);
|
|
1250
|
+
const ret = typeof data.ret === "number" ? data.ret : undefined;
|
|
1251
|
+
const errcode = typeof data.errcode === "number" ? data.errcode : undefined;
|
|
1252
|
+
if (ret !== undefined && ret !== 0 || errcode !== undefined && errcode !== 0) {
|
|
1253
|
+
const code = errcode ?? ret ?? 0;
|
|
1254
|
+
const errmsg = typeof data.errmsg === "string" ? data.errmsg : "";
|
|
1255
|
+
throw new Error(`${endpoint} error ret=${ret} errcode=${errcode}${errmsg ? `: ${errmsg}` : ""} (code ${code})`);
|
|
1256
|
+
}
|
|
1257
|
+
return data;
|
|
1245
1258
|
} catch (err) {
|
|
1246
1259
|
clearTimeout(timer);
|
|
1247
1260
|
throw err;
|
|
@@ -1251,7 +1264,7 @@ async function getUpdates(creds, buf) {
|
|
|
1251
1264
|
try {
|
|
1252
1265
|
const resp = await apiFetch(creds, "ilink/bot/getupdates", {
|
|
1253
1266
|
get_updates_buf: buf,
|
|
1254
|
-
base_info:
|
|
1267
|
+
base_info: baseInfo()
|
|
1255
1268
|
}, 35000);
|
|
1256
1269
|
return resp;
|
|
1257
1270
|
} catch (err) {
|
|
@@ -1272,7 +1285,7 @@ async function sendMessage(creds, to, text, contextToken, clientId) {
|
|
|
1272
1285
|
item_list: [{ type: 1, text_item: { text } }],
|
|
1273
1286
|
context_token: contextToken
|
|
1274
1287
|
},
|
|
1275
|
-
base_info:
|
|
1288
|
+
base_info: baseInfo()
|
|
1276
1289
|
}, 15000);
|
|
1277
1290
|
}
|
|
1278
1291
|
var typingTicketCache = new Map;
|
|
@@ -1284,7 +1297,7 @@ async function ensureTypingTicket(creds, userId) {
|
|
|
1284
1297
|
try {
|
|
1285
1298
|
const resp = await apiFetch(creds, "ilink/bot/getconfig", {
|
|
1286
1299
|
ilink_user_id: userId,
|
|
1287
|
-
base_info:
|
|
1300
|
+
base_info: baseInfo()
|
|
1288
1301
|
}, 15000);
|
|
1289
1302
|
const data = resp;
|
|
1290
1303
|
if (data.typing_ticket) {
|
|
@@ -1306,10 +1319,9 @@ async function sendTyping(creds, userId, command) {
|
|
|
1306
1319
|
try {
|
|
1307
1320
|
await apiFetch(creds, "ilink/bot/sendtyping", {
|
|
1308
1321
|
ilink_user_id: userId,
|
|
1309
|
-
to_user_id: userId,
|
|
1310
1322
|
typing_ticket: ticket,
|
|
1311
|
-
command,
|
|
1312
|
-
base_info:
|
|
1323
|
+
status: command,
|
|
1324
|
+
base_info: baseInfo()
|
|
1313
1325
|
}, 1e4);
|
|
1314
1326
|
} catch (err) {
|
|
1315
1327
|
logger.debug(`sendTyping failed for ${userId}: ${err}`);
|
|
@@ -1873,7 +1885,7 @@ async function uploadAndSendFile(creds, to, contextToken, filePath, maxSizeBytes
|
|
|
1873
1885
|
filesize: ciphertext.length,
|
|
1874
1886
|
no_need_thumb: true,
|
|
1875
1887
|
aeskey: aesKey.toString("hex"),
|
|
1876
|
-
base_info:
|
|
1888
|
+
base_info: baseInfo()
|
|
1877
1889
|
}, 15000);
|
|
1878
1890
|
const uploadFullUrl = uploadParams.upload_full_url?.trim();
|
|
1879
1891
|
if (!uploadFullUrl && !uploadParams.upload_param) {
|
|
@@ -1920,7 +1932,7 @@ async function uploadAndSendFile(creds, to, contextToken, filePath, maxSizeBytes
|
|
|
1920
1932
|
}
|
|
1921
1933
|
const media = {
|
|
1922
1934
|
encrypt_query_param: encryptQueryParam,
|
|
1923
|
-
aes_key: aesKey.toString("base64"),
|
|
1935
|
+
aes_key: Buffer.from(aesKey.toString("hex"), "utf8").toString("base64"),
|
|
1924
1936
|
encrypt_type: 1
|
|
1925
1937
|
};
|
|
1926
1938
|
const item = mediaType === 1 /* IMAGE */ ? {
|
|
@@ -1931,7 +1943,6 @@ async function uploadAndSendFile(creds, to, contextToken, filePath, maxSizeBytes
|
|
|
1931
1943
|
file_item: {
|
|
1932
1944
|
media,
|
|
1933
1945
|
file_name: fileName,
|
|
1934
|
-
md5: rawMd5,
|
|
1935
1946
|
len: String(data.length)
|
|
1936
1947
|
}
|
|
1937
1948
|
};
|
|
@@ -1948,7 +1959,7 @@ async function uploadAndSendFile(creds, to, contextToken, filePath, maxSizeBytes
|
|
|
1948
1959
|
item_list: [item],
|
|
1949
1960
|
context_token: contextToken
|
|
1950
1961
|
},
|
|
1951
|
-
base_info:
|
|
1962
|
+
base_info: baseInfo()
|
|
1952
1963
|
}, 15000);
|
|
1953
1964
|
logger.info(`Sent ${mediaType === 1 /* IMAGE */ ? "image" : "file"} to ${to}: ${fileName} (${data.length} bytes)`);
|
|
1954
1965
|
return { status: "sent", mediaType, bytes: data.length };
|