From 819ef16e8c8bc64b10c4e77ec976d497c5432aef Mon Sep 17 00:00:00 2001 From: loocao Date: Wed, 6 Sep 2023 18:02:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8card=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E7=BE=8E=E5=8C=96=E9=A3=9E=E4=B9=A6=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/server/src/service/notify.js | 148 +++++++++++++++++++------- 1 file changed, 112 insertions(+), 36 deletions(-) diff --git a/packages/server/src/service/notify.js b/packages/server/src/service/notify.js index 580d39aad7d..4765f20d94f 100644 --- a/packages/server/src/service/notify.js +++ b/packages/server/src/service/notify.js @@ -3,7 +3,6 @@ const crypto = require('crypto'); const FormData = require('form-data'); const fetch = require('node-fetch'); const nodemailer = require('nodemailer'); -const nunjucks = require('nunjucks'); module.exports = class extends think.Service { constructor(ctx) { @@ -395,44 +394,121 @@ module.exports = class extends think.Service { return false; } - self.comment = self.comment.replace(/(<([^>]+)>)/gi, ''); - - const data = { - self, - parent, - site: { - name: SITE_NAME, - url: SITE_URL, - postUrl: SITE_URL + self.url + '#' + self.objectId, - }, - }; - - content = nunjucks.renderString( - think.config('LarkTemplate') || - `【网站名称】:{{site.name|safe}} \n【评论者昵称】:{{self.nick}}\n【评论者邮箱】:{{self.mail}}\n【内容】:{{self.comment}}【地址】:{{site.postUrl}}`, - data, - ); - - const post = { - en_us: { - title: this.ctx.locale(title, data), - content: [ - [ - { - tag: 'text', - text: content, - }, - ], - ], - }, - }; + // 文章地址 + const postUrl = SITE_URL + self.url; + // 评论地址 + const commentUrl = SITE_URL + self.url + '#' + self.objectId; let signData = {}; const msg = { - msg_type: 'post', - content: { - post, - }, + "msg_type": "interactive", + "card": { + "header": { + "template": "blue", + "title": { + "tag": "plain_text", + "content": `🌥️🌥️🌥️ ${SITE_NAME} 有新评论啦` + } + }, + "elements": [ + { + "tag": "markdown", + "content": `**文章地址:** [${postUrl}](${postUrl})` + }, + { + "tag": "hr" + }, + { + "tag": "column_set", + "flex_mode": "none", + "background_style": "default", + "columns": [ + { + "tag": "column", + "width": "weighted", + "weight": 1, + "vertical_align": "top", + "elements": [ + { + "tag": "markdown", + "content": `**🌥️ 站点名称\n ${SITE_NAME}** `, + "text_align": "center" + } + ] + }, + { + "tag": "column", + "width": "weighted", + "weight": 1, + "vertical_align": "top", + "elements": [ + { + "tag": "markdown", + "content": `**👤 昵称** \n[${self.nick}](${self.link})`, + "text_align": "center" + } + ] + }, + { + "tag": "column", + "width": "weighted", + "weight": 1, + "vertical_align": "top", + "elements": [ + { + "tag": "markdown", + "content": `**📪 邮箱\n ${self.mail}**`, + "text_align": "center" + } + ] + } + ] + }, + { + "tag": "column_set", + "flex_mode": "none", + "background_style": "grey", + "columns": [ + { + "tag": "column", + "width": "weighted", + "weight": 1, + "vertical_align": "top", + "elements": [ + { + "tag": "markdown", + "content": "**📝 评论内容 📝**", + "text_align": "center" + }, + { + "tag": "markdown", + "content": self.comment + } + ] + } + ] + }, + { + "tag": "action", + "actions": [ + { + "tag": "button", + "text": { + "tag": "plain_text", + "content": "查看完整內容" + }, + "type": "primary", + "multi_url": { + "url": commentUrl, + "pc_url": "", + "android_url": "", + "ios_url": "" + } + } + ] + } + ] + } }; const sign = (timestamp, secret) => {