Skip to content

Commit

Permalink
feat(vercel): QQ notification support & Telegram notification update
Browse files Browse the repository at this point in the history
  • Loading branch information
leirock committed Dec 23, 2020
1 parent 88c0305 commit 10d08af
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ English | [中文](https://github.com/lizheming/waline/blob/master/README_CN.md)

- [x] Email notification
- [x] Wechat notification
- [x] QQ notification
- [x] Telegram notification
- [x] Akismet
- [x] Article counter
Expand Down
1 change: 1 addition & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

- [x] 邮件通知
- [x] 微信通知
- [x] QQ 通知
- [x] Telegram 通知
- [x] Akismet 反垃圾评论
- [x] 文章统计
Expand Down
16 changes: 13 additions & 3 deletions docs/en/server/notification.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,22 @@ We use [Server Chan](http://sc.ftqq.com/3.version) to wechat notification. You n
- `SITE_NAME`:Your site name, it will be displayed in notification message.
- `SITE_URL`:Your site url, it will be displayed in notification message.

## QQ Notification

We use [Qmsg Chan](https://qmsg.zendee.cn) to send QQ notification. You need to set `QMSG_KEY` in env which applied in Qmsg Chan.

- `QMSG_KEY`:KEY applied in Qmsg Chan, It's required for this service.
- `QQ_ID`:The QQ ID of the receiver(s), except for QQ group. If there are more than one QQ ID, use commas to separate multiple values, e.g. `1244453393,2952937634` (should all be included in your Qmsg Chan's QQ ID list).
- `AUTHOR_EMAIL`:The blogger’s email is used to distinguish whether the posted comment is posted by the blogger himself. If it is posted by the blogger, there will be no reminder notification.
- `SITE_NAME`:Your site name, it will be displayed in notification message.
- `SITE_URL`:Your site url, it will be displayed in notification message.

## Telegram Notification

We use Telegram bot to send comment notification. You need to set the following env first.
We use Telegram bot to send Telegram notification. You need to set the following env first.

- `TG_BOT_TOKEN`:Telegram bot token to access the HTTP API. Create a bot with [@BotFather](https://t.me/BotFather) to get this token.
- `TG_CHAT_ID`:The `chat_id` of the receiver. It can be an user, a channel or a group. [@userinfobot](https://t.me/userinfobot) will display this `chat_id` when you forward a message to it.
- `TG_BOT_TOKEN`:Telegram bot token to access the HTTP API. Create a bot with [@BotFather](https://t.me/BotFather) to get this token. It's required for this service.
- `TG_CHAT_ID`:The `chat_id` of the receiver. It can be an user, a channel or a group. [@userinfobot](https://t.me/userinfobot) will display this `chat_id` when you forward a message to it. It's required for this service.
- `AUTHOR_EMAIL`:The blogger’s email is used to distinguish whether the posted comment is posted by the blogger himself. If it is posted by the blogger, there will be no reminder notification.
- `SITE_NAME`:Your site name, it will be displayed in notification message.
- `SITE_URL`:Your site url, it will be displayed in notification message.
16 changes: 13 additions & 3 deletions docs/server/notification.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,22 @@
- `SITE_NAME`:网站名称,用于在消息中显示。
- `SITE_URL`:网站地址,用于在消息中显示。

## QQ 通知

QQ 通知使用了 [Qmsg 酱](https://qmsg.zendee.cn) 提供的服务,需要在环境变量中配置在 Qmsg 酱中申请的 `QMSG_KEY`

- `QMSG_KEY`:Qmsg 酱提供的 KEY,必填。
- `QQ_ID`:接收消息的 QQ 号(不支持 QQ 群),可以添加多个,以半角逗号分割,如:`1244453393,2952937634`(必须均在您的 Qmsg 酱 QQ 号列表中)。
- `AUTHOR_EMAIL`:博主邮箱,用来区分发布的评论是否是博主本身发布的。如果是博主发布的则不进行提醒通知。
- `SITE_NAME`:网站名称,用于在消息中显示。
- `SITE_URL`:网站地址,用于在消息中显示。

## Telegram 通知

Telegram 通知通过 Telegram bot 机器人实现,需要在环境变量中配置以下几个
Telegram 通知通过 Telegram bot 机器人实现,需要配置以下几个环境变量

- `TG_BOT_TOKEN`:Telegram 机器人用于访问 HTTP API 的 token,通过 [@BotFather](https://t.me/BotFather) 创建机器人获取。
- `TG_CHAT_ID`Telegram 机器人发送消息对象的 `chat_id`,可以是单一用户、频道、群组,通过 [@userinfobot](https://t.me/userinfobot) 获取。
- `TG_BOT_TOKEN`:Telegram 机器人用于访问 HTTP API 的 token,通过 [@BotFather](https://t.me/BotFather) 创建机器人获取,必填
- `TG_CHAT_ID`接收消息对象的 `chat_id`,可以是单一用户、频道、群组,通过 [@userinfobot](https://t.me/userinfobot) 获取,必填
- `AUTHOR_EMAIL`:博主邮箱,用来区分发布的评论是否是博主本身发布的。如果是博主发布的则不进行提醒通知。
- `SITE_NAME`:网站名称,用于在消息中显示。
- `SITE_URL`:网站地址,用于在消息中显示。
73 changes: 66 additions & 7 deletions packages/server/src/service/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,80 @@ module.exports = class extends think.Service {
json: true
});
}


async qq(self, parent) {
const {QMSG_KEY, QQ_ID, SITE_NAME, SITE_URL} = process.env;
if (!QMSG_KEY) {
return false;
}

const data = {
self,
parent,
site: {
name: SITE_NAME,
url: SITE_URL,
postUrl: SITE_URL + self.url + '#' + self.objectId
}
};

const contentQQ = `💬 {{site.name}} 有新评论啦
{{self.nick}} 回复说:
`+
self.comment
.replace(/<a href="(.*?)">(.*?)<\/a>/g, "\n[$2] $1\n")
.replace(/<[^>]+>/g, '')
+ `
邮箱:{{self.mail}}
审核:{{self.status}}
仅供评论预览,查看完整內容:
{{site.postUrl}}`;

return request({
uri: `https://qmsg.zendee.cn/send/${QMSG_KEY}`,
method: 'POST',
form: {
msg: nunjucks.renderString(contentQQ, data),
qq: QQ_ID
}
});
}

async telegram(self, parent) {
const rawComment = self.rawComment.replace(/\!\[(.*?)\]\((.*?)\)/g,' ');
var commentLink = ""
var href = self.comment.match(/<a href="(.*?)">(.*?)<\/a>/g);
if (href != null) {
for (var i = 0, j = 0; i < href.length; i++) {
href[i] = href[i].replace(/<a href="(.*?)">(.*?)<\/a>/g, "$1");
j = i + 1;
href[i] = "[链接" + j + "](" + href[i] + ") ";
commentLink = commentLink + href[i];
}
}
if (commentLink != "") {
commentLink = `\n`+ commentLink + `\n`;
}

const contentTG = `
💬 *[{{site.name}}]({{site.url}}) 有新评论啦*
*{{self.nick}}* 回复说:
\`\`\`
` + rawComment + `
\`\`\`
` +
self.comment
.replace(/<a href="(.*?)">(.*?)<\/a>/g, '\[链接 $2\]')
.replace(/<[^>]+>/g, '')
+ `\`\`\``
+ commentLink
+ `
*邮箱:*\`{{self.mail}}\`
*审核:*{{self.status}}
评论仅显示源码,点击[查看完整內容]({{site.postUrl}})`;
仅供评论预览,点击[查看完整內容]({{site.postUrl}})`;

const {TG_BOT_TOKEN, TG_CHAT_ID, SITE_NAME, SITE_URL} = process.env;
if(!TG_BOT_TOKEN || !TG_CHAT_ID) {
Expand Down Expand Up @@ -147,8 +205,9 @@ module.exports = class extends think.Service {

if(!isAuthorComment) {
const wechat = await this.wechat({title, content}, comment, parent);
const qq = await this.qq(comment, parent);
const telegram = await this.telegram(comment, parent);
if(think.isEmpty(wechat) && think.isEmpty(telegram) && !isReplyAuthor) {
if(think.isEmpty(wechat) && think.isEmpty(qq) && think.isEmpty(telegram) && !isReplyAuthor) {
mailList.push({to: AUTHOR, title, content});
}
}
Expand Down

0 comments on commit 10d08af

Please sign in to comment.