Skip to content

Commit

Permalink
Merge pull request #136 from Auxior/main
Browse files Browse the repository at this point in the history
支持飞书推送
  • Loading branch information
iDerekLi authored Jan 16, 2024
2 parents 721211e + 44dfde8 commit e1146d6
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/auto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ env:
PUSHPLUS_TOKEN: ${{ secrets.PUSHPLUS_TOKEN }}
WEIXIN_WEBHOOK: ${{ secrets.WEIXIN_WEBHOOK }}
SERVERPUSHKEY: ${{ secrets.SERVERPUSHKEY }}
FEISHU_WEBHOOK: ${{ secrets.FEISHU_WEBHOOK }}

jobs:
CheckIn:
Expand All @@ -30,6 +31,7 @@ jobs:
cd workflows
yarn
yarn checkin
# SeaGold:
# needs: CheckIn
# runs-on: ubuntu-latest
Expand Down
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@

2. 仓库 -> Settings -> Secrets -> New repository secret, 添加Secrets变量如下:

| Name | Value | Required |
| --- | --- | --- |
| COOKIE | 掘金网站Cookie ||
| COOKIE_2 | 多用户, 当需要同时运行多个掘金用户时所需, 支持最多 **5** 名用户(即COOKIE + COOKIE_2 - COOKIE_5) ||
| EMAIL_USER | 发件人邮箱地址(需要开启 SMTP) ||
| EMAIL_PASS | 发件人邮箱密码(SMTP密码) ||
| EMAIL_TO | 订阅人邮箱地址(收件人). 如需多人订阅使用 `, ` 分割, 例如: `a@163.com, b@qq.com` ||
| DINGDING_WEBHOOK | 钉钉机器人WEBHOOK ||
| PUSHPLUS_TOKEN | [Pushplus](http://www.pushplus.plus/) 官网申请,支持微信消息推送 ||
| SERVERPUSHKEY | [Server酱](https://sct.ftqq.com//) 官网申请,支持微信消息推送 ||
| Name | Value | Required |
| --- | --- | --- |
| COOKIE | 掘金网站Cookie ||
| COOKIE_2 | 多用户, 当需要同时运行多个掘金用户时所需, 支持最多 **5** 名用户(即COOKIE + COOKIE_2 - COOKIE_5) ||
| EMAIL_USER | 发件人邮箱地址(需要开启 SMTP) ||
| EMAIL_PASS | 发件人邮箱密码(SMTP密码) ||
| EMAIL_TO | 订阅人邮箱地址(收件人). 如需多人订阅使用 `, ` 分割, 例如: `a@163.com, b@qq.com` ||
| DINGDING_WEBHOOK | 钉钉机器人WEBHOOK ||
| PUSHPLUS_TOKEN | [Pushplus](http://www.pushplus.plus/) 官网申请,支持微信消息推送 ||
| SERVERPUSHKEY | [Server酱](https://sct.ftqq.com//) 官网申请,支持微信消息推送 ||
| WEIXIN_WEBHOOK | 企业微信机器人WEBHOOK ||
| FEISHU_WEBHOOK | 飞书机器人WEBHOOK ||

4. 仓库 -> Actions, 检查Workflows并启用。

Expand Down
4 changes: 4 additions & 0 deletions workflows/utils/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ module.exports = {
* https://sct.ftqq.com/sendkey
*/
SERVERPUSHKEY: env.SERVERPUSHKEY,
/**
* 飞书配置
*/
FEISHU_WEBHOOK: env.FEISHU_WEBHOOK
};
37 changes: 35 additions & 2 deletions workflows/utils/notification-kit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface DingTalkOptions extends NotificationOptions {}
interface PushPlusOptions extends NotificationOptions {}
interface WeComOptions extends NotificationOptions {}
interface WeiXinOptions extends WeComOptions {}
interface FeiShuOptions extends NotificationOptions {}

export class NotificationKit {
/**
Expand Down Expand Up @@ -145,10 +146,10 @@ export class NotificationKit {
const config = {
title: options.title,
desp: options.content,
channel: "9",
channel: "9"
};

return axios.post(`https://sctapi.ftqq.com/${token}.send`, config, {
return axios.post(`https://sctapi.ftqq.com/${token}.send`, config, {
headers: {
"Content-Type": "application/json"
}
Expand All @@ -173,6 +174,37 @@ export class NotificationKit {
});
}

/**
* 飞书Webhook
* @param options
*/
async feishuWebhook(options: FeiShuOptions) {
const url: string | unknown = env.FEISHU_WEBHOOK;
if (!url || url === "") {
throw new Error("未配置飞书Webhook。");
}

return axios.post(url as string, {
msg_type: "interactive",
card: {
elements: [
{
tag: "markdown",
content: options.content,
text_align: "left"
}
],
header: {
template: "blue",
title: {
content: options.title,
tag: "plain_text"
}
}
}
});
}

/**
* 企业微信Webhook
* @param options
Expand Down Expand Up @@ -230,6 +262,7 @@ export class NotificationKit {
await trycatch("微信", this.wecomWebhook.bind(this));
await trycatch("PushPlus", this.pushplus.bind(this));
await trycatch("Server酱", this.serverPush.bind(this));
await trycatch("飞书", this.feishuWebhook.bind(this));
}
}

Expand Down

0 comments on commit e1146d6

Please sign in to comment.