mirror of
https://github.com/schroinerxy/cloud-mail.git
synced 2026-06-21 19:35:50 +08:00
新增TG自定义是否显示文本消息
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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: [
|
||||
[
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
@@ -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 ''
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user