mirror of
https://github.com/schroinerxy/cloud-mail.git
synced 2026-06-21 19:35:50 +08:00
新增TG自定义是否显示文本消息
This commit is contained in:
@@ -302,7 +302,8 @@ const en = {
|
||||
customDomainDesc: 'Worker custom domain',
|
||||
show: 'Show',
|
||||
hide: 'Hide',
|
||||
onlyName: 'Only name'
|
||||
onlyName: 'Only name',
|
||||
emailText: 'Email Text'
|
||||
}
|
||||
|
||||
export default en
|
||||
|
||||
@@ -302,6 +302,7 @@ const zh = {
|
||||
customDomainDesc: 'Worker 自定义域',
|
||||
show: '显示',
|
||||
hide: '隐藏',
|
||||
onlyName: '仅名字'
|
||||
onlyName: '仅名字',
|
||||
emailText: '邮件文本'
|
||||
}
|
||||
export default zh
|
||||
|
||||
@@ -508,6 +508,17 @@
|
||||
/>
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="tg-msg-label">
|
||||
<span>{{t('emailText')}}</span>
|
||||
<el-select v-model="tgMsgText" >
|
||||
<el-option
|
||||
v-for="item in tgMsgTextOption"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
</div>
|
||||
</div>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
@@ -811,9 +822,11 @@ const ruleType = ref(0)
|
||||
const ruleEmail = ref([])
|
||||
const tgMsgFrom = ref('')
|
||||
const tgMsgTo = ref('')
|
||||
const tgMsgText = ref('')
|
||||
|
||||
const tgMsgFromOption = [{label: t('show'), value: 'show'}, {label: t('hide'), value: 'hide'}, {label: t('onlyName'), value:'only-name'}]
|
||||
const tgMsgToOption = [{label: t('show'), value: 'show'}, {label: t('hide'), value: 'hide'}]
|
||||
const tgMsgTextOption = [{label: t('show'), value: 'show'}, {label: t('hide'), value: 'hide'}]
|
||||
const tgMsgLabelWidth = computed(() => locale.value === 'en' ? '120px' : '100px');
|
||||
|
||||
getSettings()
|
||||
@@ -930,6 +943,7 @@ function openTgSetting() {
|
||||
tgBotToken.value = setting.value.tgBotToken
|
||||
customDomain.value = setting.value.customDomain
|
||||
tgMsgFrom.value = setting.value.tgMsgFrom
|
||||
tgMsgText.value = setting.value.tgMsgText
|
||||
tgMsgTo.value = setting.value.tgMsgTo
|
||||
tgChatId.value = []
|
||||
if (setting.value.tgChatId) {
|
||||
@@ -1068,6 +1082,7 @@ function tgBotSave() {
|
||||
tgBotStatus: tgBotStatus.value,
|
||||
tgChatId: tgChatId.value + '',
|
||||
tgMsgFrom: tgMsgFrom.value,
|
||||
tgMsgText: tgMsgText.value,
|
||||
tgMsgTo: tgMsgTo.value
|
||||
}
|
||||
editSetting(form)
|
||||
|
||||
@@ -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}`
|
||||
}
|
||||
|
||||
|
||||
if(tgMsgText === 'show') {
|
||||
template += `
|
||||
|
||||
${email.text || emailUtils.htmlToText(email.content)}`
|
||||
}
|
||||
|
||||
return template;
|
||||
|
||||
}
|
||||
|
||||
@@ -15,9 +15,16 @@ const emailUtils = {
|
||||
},
|
||||
|
||||
htmlToText(content) {
|
||||
if (!content) return ''
|
||||
try {
|
||||
const { document } = parseHTML(content);
|
||||
document.querySelectorAll('style, script, title').forEach(el => el.remove());
|
||||
return document.documentElement.innerText;
|
||||
let text = document.body.innerText;
|
||||
return text.trim();
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
return ''
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user