新增TG自定义是否显示文本消息

This commit is contained in:
eoao
2025-10-23 23:55:00 +08:00
parent fcf15dd3cb
commit 4c5fef2d91
8 changed files with 52 additions and 13 deletions
+2 -1
View File
@@ -44,6 +44,7 @@ export const setting = sqliteTable('setting', {
forcePathStyle: integer('force_path_style').default(1).notNull(),
customDomain: text('custom_domain').default('').notNull(),
tgMsgFrom: text('tg_msg_from').default('only-name').notNull(),
tgMsgTo: text('tg_msg_to').default('show').notNull()
tgMsgTo: text('tg_msg_to').default('show').notNull(),
tgMsgText: text('tg_msg_text').default('hide').notNull()
});
export default setting
+7
View File
@@ -39,6 +39,13 @@ const init = {
} catch (e) {
console.error(e)
}
try {
await c.env.db.prepare(`ALTER TABLE setting ADD COLUMN tg_msg_text TEXT NOT NULL DEFAULT 'hide';`).run();
} catch (e) {
console.error(e)
}
},
async v2DB(c) {
+2 -2
View File
@@ -44,7 +44,7 @@ const telegramService = {
async sendEmailToBot(c, email) {
const { tgBotToken, tgChatId, customDomain, tgMsgTo, tgMsgFrom } = await settingService.query(c);
const { tgBotToken, tgChatId, customDomain, tgMsgTo, tgMsgFrom, tgMsgText } = await settingService.query(c);
const tgChatIds = tgChatId.split(',');
@@ -62,7 +62,7 @@ const telegramService = {
body: JSON.stringify({
chat_id: chatId,
parse_mode: 'HTML',
text: emailMsgTemplate(email, tgMsgTo, tgMsgFrom),
text: emailMsgTemplate(email, tgMsgTo, tgMsgFrom, tgMsgText),
reply_markup: {
inline_keyboard: [
[
+12 -5
View File
@@ -1,4 +1,6 @@
export default function emailMsgTemplate(email, tgMsgTo, tgMsgFrom) {
import emailUtils from '../utils/email-utils';
export default function emailMsgTemplate(email, tgMsgTo, tgMsgFrom, tgMsgText) {
let template = `<b>${email.subject}</b>`
@@ -18,14 +20,19 @@ export default function emailMsgTemplate(email, tgMsgTo, tgMsgFrom) {
template += `
收件人:\u200B${email.toEmail}`
return template
}
if(tgMsgTo === 'show') {
} else if(tgMsgTo === 'show') {
template += `
收件人:\u200B${email.toEmail}`
}
return template;
if(tgMsgText === 'show') {
template += `
${email.text || emailUtils.htmlToText(email.content)}`
}
return template;
}
+10 -3
View File
@@ -15,9 +15,16 @@ const emailUtils = {
},
htmlToText(content) {
const { document } = parseHTML(content);
document.querySelectorAll('style, script, title').forEach(el => el.remove());
return document.documentElement.innerText;
if (!content) return ''
try {
const { document } = parseHTML(content);
document.querySelectorAll('style, script, title').forEach(el => el.remove());
let text = document.body.innerText;
return text.trim();
} catch (e) {
console.error(e)
return ''
}
}
};