Skip to content

Commit

Permalink
chore: update notify, add ServerChan Notification Template (walinejs#…
Browse files Browse the repository at this point in the history
  • Loading branch information
madelcw authored Feb 1, 2024
1 parent 2944af4 commit 5d16e7e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
12 changes: 12 additions & 0 deletions docs/src/guide/features/notification.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ redirectFrom: /guide/server/notification.html
- `AUTHOR_EMAIL`: 博主邮箱,用来区分发布的评论是否是博主本身发布的。如果是博主发布的则不进行提醒通知。
- `SITE_NAME`: 网站名称,用于在消息中显示。
- `SITE_URL`: 网站地址,用于在消息中显示。
- `SC_TEMPLATE`: Server酱 使用的通知模板,变量与具体格式可参见下文的通知模板。未配置则使用默认模板。


## 企业微信应用通知

Expand Down Expand Up @@ -210,6 +212,16 @@ Waline 支持为每个平台分别配置您自定义的通知模板,从而实
仅供评论预览,点击 [查看完整內容]({{site.postUrl}})
````

- SC_TEMPLATE:

```plain
{{site.name|safe}} 有新评论啦
【评论者昵称】:{{self.nick}}
【评论者邮箱】:{{self.mail}}
【内容】:{{self.comment}}
【地址】:{{site.postUrl}}
```

### 附加说明

1. Vercel 的环境变量大小限制为 `4KB` ,所以如果您的模板很长,请使用代码配置,参见 [issue#106](https://github.com/walinejs/waline/issues/106) ;
Expand Down
6 changes: 6 additions & 0 deletions docs/src/reference/server/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ QQ 评论通知模板,等同于环境变量 `QQ_TEMPLATE`。

Telegram 评论通知模板,等同于环境变量 `TG_TEMPLATE`

### SCTemplate

- 类型: `string`

Server酱 评论通知模板,等同于环境变量 `SC_TEMPLATE`

### model

- 类型:`class`
Expand Down
2 changes: 2 additions & 0 deletions packages/server/src/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const {
QQ_TEMPLATE,
TG_TEMPLATE,
WX_TEMPLATE,
SC_TEMPLATE,
DISCORD_TEMPLATE,
LARK_TEMPLATE,

Expand Down Expand Up @@ -134,6 +135,7 @@ module.exports = {
QQTemplate: QQ_TEMPLATE,
TGTemplate: TG_TEMPLATE,
WXTemplate: WX_TEMPLATE,
SCTemplate: SC_TEMPLATE,
DiscordTemplate: DISCORD_TEMPLATE,
LarkTemplate: LARK_TEMPLATE,
};
10 changes: 9 additions & 1 deletion packages/server/src/service/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,16 @@ module.exports = class extends think.Service {
},
};

const contentWechat =
think.config('SCTemplate') ||
`{{site.name|safe}} 有新评论啦
【评论者昵称】:{{self.nick}}
【评论者邮箱】:{{self.mail}}
【内容】:{{self.comment}}
【地址】:{{site.postUrl}}`;

title = this.ctx.locale(title, data);
content = this.ctx.locale(content, data);
content = this.ctx.locale(contentWechat, data);

const form = new FormData();

Expand Down

0 comments on commit 5d16e7e

Please sign in to comment.