diff --git a/dist/buildinfo.json b/dist/buildinfo.json index ccceea2b..d6df7b5b 100644 --- a/dist/buildinfo.json +++ b/dist/buildinfo.json @@ -1 +1 @@ -{"sha":"92ed0fc","timestamp":1724323685} \ No newline at end of file +{"sha":"27afa4a","timestamp":1724326940} \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index 009991af..65b98cfd 100644 --- a/dist/index.js +++ b/dist/index.js @@ -657,6 +657,10 @@ function sendMessageToTelegramWithContext(context) { context._info, msgType ); + if (!resp.ok) { + console.error(await resp.clone().text()); + return resp; + } return await checkIsNeedTagIds(context, msgType, resp); }; } @@ -694,20 +698,20 @@ async function deleteMessagesFromTelegram(chat_id, bot_token, message_ids) { } async function sendPhotoToTelegram(photo, token, context, _info = null) { try { + let photo_url = photo.url[0]; const url = `${ENV2.TELEGRAM_API_DOMAIN}/bot${token}/sendPhoto`; let body; const headers = {}; - if (typeof photo.url[0] === "string") { + if (typeof photo_url === "string") { if (ENV2.TELEGRAPH_IMAGE_ENABLE) { try { - const new_url = await uploadImageToTelegraph(photo.url[0]); - photo.url = new_url; + photo_url = await uploadImageToTelegraph(photo_url); } catch (e2) { console.error(e2.message); } } body = { - photo: photo.url[0] + photo: photo_url }; for (const key of Object.keys(context)) { if (context[key] !== void 0 && context[key] !== null) { @@ -749,6 +753,10 @@ function sendPhotoToTelegramWithContext(context) { context.CURRENT_CHAT_CONTEXT, context._info ); + if (!resp.ok) { + console.error(await resp.clone().text()); + return resp; + } return checkIsNeedTagIds(context, msgType, resp); }; } @@ -1161,9 +1169,9 @@ var Environment = class { // -- 版本数据 -- // // 当前版本 - BUILD_TIMESTAMP = 1724323685; + BUILD_TIMESTAMP = 1724326940; // 当前版本 commit id - BUILD_VERSION = "92ed0fc"; + BUILD_VERSION = "27afa4a"; // -- 基础配置 -- /** * @type {I18n | null} diff --git a/dist/timestamp b/dist/timestamp index acb751c6..c65ebf2b 100644 --- a/dist/timestamp +++ b/dist/timestamp @@ -1 +1 @@ -1724323685 \ No newline at end of file +1724326940 \ No newline at end of file diff --git a/src/telegram/telegram.js b/src/telegram/telegram.js index 0907641b..b811bfe1 100644 --- a/src/telegram/telegram.js +++ b/src/telegram/telegram.js @@ -142,14 +142,18 @@ export async function sendMessageToTelegram(message, token, context, _info, type */ export function sendMessageToTelegramWithContext(context) { return async (message, msgType = 'chat') => { - const resp = await sendMessageToTelegram( - message, - context.SHARE_CONTEXT.currentBotToken, - context.CURRENT_CHAT_CONTEXT, - context._info, - msgType, - ); - return await checkIsNeedTagIds(context, msgType, resp); + const resp = await sendMessageToTelegram( + message, + context.SHARE_CONTEXT.currentBotToken, + context.CURRENT_CHAT_CONTEXT, + context._info, + msgType, + ); + if (!resp.ok) { + console.error(await resp.clone().text()); + return resp; + } + return await checkIsNeedTagIds(context, msgType, resp); }; } @@ -204,21 +208,22 @@ export async function deleteMessagesFromTelegram(chat_id, bot_token, message_id */ export async function sendPhotoToTelegram(photo, token, context, _info = null) { try { + let photo_url = photo.url[0]; const url = `${ENV.TELEGRAM_API_DOMAIN}/bot${token}/sendPhoto`; let body; const headers = {}; - if (typeof photo.url[0] === 'string') { + if (typeof photo_url === 'string') { if (ENV.TELEGRAPH_IMAGE_ENABLE) { try { - const new_url = await uploadImageToTelegraph(photo.url[0]); - photo.url = new_url; + photo_url = await uploadImageToTelegraph(photo_url); } catch (e) { console.error(e.message); } } body = { - photo: photo.url[0], + photo: photo_url, }; + for (const key of Object.keys(context)) { if (context[key] !== undefined && context[key] !== null) { body[key] = context[key]; @@ -231,7 +236,6 @@ export async function sendPhotoToTelegram(photo, token, context, _info = null) { info = (info ? info + '\n\n' : '') + photo.text; } body.caption = '>`' + escape(info) + '`' + `\n[原始图片](${photo.url})`; - body = JSON.stringify(body); headers['Content-Type'] = 'application/json'; } else { @@ -243,6 +247,7 @@ export async function sendPhotoToTelegram(photo, token, context, _info = null) { } } } + return await fetch(url, { method: 'POST', headers, @@ -250,7 +255,6 @@ export async function sendPhotoToTelegram(photo, token, context, _info = null) { }); } catch (e) { console.error(e); - // throw new Error('send telegram message failed, please see the log'); } } @@ -267,6 +271,10 @@ export function sendPhotoToTelegramWithContext(context) { context.CURRENT_CHAT_CONTEXT, context._info, ); + if (!resp.ok) { + console.error(await resp.clone().text()); + return resp; + } return checkIsNeedTagIds(context, msgType, resp); }; }