Compare commits
33 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
07415b7499 | ||
![]() |
46370aa1f7 | ||
![]() |
f99560aa94 | ||
![]() |
89f4ffaa53 | ||
![]() |
6df0f2f152 | ||
![]() |
7ecbb4de6c | ||
![]() |
9c8d16d926 | ||
![]() |
c6d92613c7 | ||
![]() |
2903b97062 | ||
![]() |
59ba9c8152 | ||
![]() |
8b2766073f | ||
![]() |
cadaf675dd | ||
![]() |
e9738beb79 | ||
![]() |
aa341fdcfe | ||
![]() |
8d6721ecd2 | ||
![]() |
522201f34b | ||
![]() |
97dcd7641c | ||
![]() |
a47b2886f8 | ||
![]() |
e6ba7dadb8 | ||
![]() |
a558a94076 | ||
![]() |
b91f63ab83 | ||
![]() |
fca74f481b | ||
![]() |
7a9016bb71 | ||
![]() |
460f7c9c9c | ||
![]() |
b214c1483f | ||
![]() |
b2b6bbbf73 | ||
![]() |
99fc51462f | ||
![]() |
351306edbe | ||
![]() |
8ca5e0242a | ||
![]() |
dcbae93a71 | ||
![]() |
f03bfac03a | ||
![]() |
61138841ff | ||
![]() |
ba7f10ea31 |
46
.github/workflows/main.yml
vendored
2
.gitignore
vendored
@ -1 +1,3 @@
|
||||
node_modules
|
||||
/.idea
|
||||
/.DS_Store
|
||||
|
17
Dockerfile
@ -1,17 +0,0 @@
|
||||
FROM mhart/alpine-node:10.15.1
|
||||
|
||||
LABEL "com.github.actions.name"="GitHub Action for WeChat Work"
|
||||
LABEL "com.github.actions.description"="Send WeChat Work message. Run on any operating platform, such as Windows, Linux, Mac supported by GitHub"
|
||||
LABEL "com.github.actions.icon"="message-circle"
|
||||
LABEL "com.github.actions.color"="red"
|
||||
|
||||
LABEL "repository"="https://github.com/chf007/action-wechat-work"
|
||||
LABEL "homepage"="https://github.com/chf007/action-wechat-work"
|
||||
LABEL "maintainer"="chf007 <chf007server@gmail.com>"
|
||||
LABEL "version"="1.0.0"
|
||||
|
||||
ADD entrypoint.js package.json package-lock.json /
|
||||
RUN npm ci
|
||||
RUN chmod +x /entrypoint.js
|
||||
|
||||
ENTRYPOINT ["node", "/entrypoint.js"]
|
2
LICENSE
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 Nicolas Coutin
|
||||
Copyright (c) 2020-present chf007 and contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
103
README.zh-CN.md
@ -1,103 +0,0 @@
|
||||
# WeChat Work for GitHub Actions
|
||||
|
||||
通过企业微信机器人发送消息
|
||||
|
||||

|
||||
|
||||
<hr/>
|
||||
|
||||
## 用法
|
||||
|
||||
#### 纯文本格式消息
|
||||
|
||||

|
||||
|
||||
```yaml
|
||||
- name: WeChat Work notification by text
|
||||
uses: chf007/action-wechat-work@master
|
||||
env:
|
||||
WECHAT_WORK_BOT_WEBHOOK: ${{secrets.WECHAT_WORK_BOT_WEBHOOK}}
|
||||
with:
|
||||
msgtype: text
|
||||
content: 广州今日天气:29度,大部分多云,降雨概率:60%
|
||||
mentioned_list: '["wangqing","@all"]'
|
||||
mentioned_mobile_list: '["13800001111","@all"]'
|
||||
```
|
||||
|
||||
参数 | 必须 | 说明
|
||||
------------ | ------------- | -------------
|
||||
msgtype | true | 消息类型,此时固定为text
|
||||
content | true | 文本内容,最长不超过2048个字节,必须是utf8编码
|
||||
mentioned_list | false | userid的列表,提醒群中的指定成员(@某个成员),@all表示提醒所有人,如果开发者获取不到userid,可以使用mentioned_mobile_list,必须是序列化后的JSON字符串
|
||||
mentioned_mobile_list | false | 手机号列表,提醒手机号对应的群成员(@某个成员),@all表示提醒所有人,必须是序列化后的JSON字符串
|
||||
|
||||
#### markdown格式消息
|
||||
|
||||

|
||||
|
||||
```yaml
|
||||
- name: WeChat Work notification by markdown
|
||||
uses: chf007/action-wechat-work@master
|
||||
env:
|
||||
WECHAT_WORK_BOT_WEBHOOK: ${{secrets.WECHAT_WORK_BOT_WEBHOOK}}
|
||||
with:
|
||||
msgtype: markdown
|
||||
content: "实时新增用户反馈<font color=\"warning\">132例</font>,请相关同事注意。\n
|
||||
> 类型:<font color=\"comment\">用户反馈</font> \n
|
||||
> 普通用户反馈:<font color=\"comment\">117例</font> \n
|
||||
> VIP用户反馈:<font color=\"comment\">15例</font>"
|
||||
```
|
||||
|
||||
参数 | 必须 | 说明
|
||||
------------ | ------------- | -------------
|
||||
msgtype | true | 消息类型,此时固定为markdown
|
||||
content | true | markdown内容,最长不超过4096个字节,必须是utf8编码 支持的格式详见 https://work.weixin.qq.com/api/doc#90000/90136/91770
|
||||
|
||||
#### 图片格式消息
|
||||
|
||||

|
||||
|
||||
```yaml
|
||||
- name: WeChat Work notification by image
|
||||
uses: chf007/action-wechat-work@master
|
||||
env:
|
||||
WECHAT_WORK_BOT_WEBHOOK: ${{secrets.WECHAT_WORK_BOT_WEBHOOK}}
|
||||
with:
|
||||
msgtype: image
|
||||
base64: data:image/png;base64,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
|
||||
md5: 9c2c8daba00a516c0ff469ca13e0edf0
|
||||
```
|
||||
|
||||
参数 | 必须 | 说明
|
||||
------------ | ------------- | -------------
|
||||
msgtype | true | 消息类型,此时固定为image
|
||||
base64 | true | 图片内容的base64编码 注:图片(base64编码前)最大不能超过2M,支持JPG,PNG格式
|
||||
md5 | true | 图片内容(base64编码前)的md5值
|
||||
|
||||
#### 图文格式消息
|
||||
|
||||

|
||||
|
||||
```yaml
|
||||
- name: WeChat Work notification by news
|
||||
uses: chf007/action-wechat-work@master
|
||||
env:
|
||||
WECHAT_WORK_BOT_WEBHOOK: ${{secrets.WECHAT_WORK_BOT_WEBHOOK}}
|
||||
with:
|
||||
msgtype: news
|
||||
articles: '[{"title":"中秋节礼品领取","description":"今年中秋节公司有豪礼相送","url":"URL","picurl":"http://res.mail.qq.com/node/ww/wwopenmng/images/independent/doc/test_pic_msg1.png"}]'
|
||||
```
|
||||
参数 | 必须 | 说明
|
||||
------------ | ------------- | -------------
|
||||
msgtype | true | 消息类型,此时固定为news
|
||||
articles | true | 图文消息,一个图文消息支持1到8条图文,必须是序列化后的JSON字符串
|
||||
articles.title | true | 标题,不超过128个字节,超过会自动截断
|
||||
articles.description | false | 描述,不超过512个字节,超过会自动截断
|
||||
articles.url | false | 点击后跳转的链接。
|
||||
articles.picurl | false | 图文消息的图片链接,支持JPG、PNG格式,较好的效果为大图 1068*455,小图150*150。
|
||||
|
||||
#### 更多详细参数说明,参见 https://work.weixin.qq.com/api/doc#90000/90136/91770
|
||||
|
||||
## WECHAT_WORK_BOT_WEBHOOK
|
||||
|
||||
* **`WECHAT_WORK_BOT_WEBHOOK`**: 企业微信 Webhook URL (**required**, 参见 https://work.weixin.qq.com/api/doc#90000/90136/91770).
|
33
action.yml
@ -5,3 +5,36 @@ author: 'chf007 <chf007server@gmail.com>'
|
||||
branding:
|
||||
icon: 'message-circle'
|
||||
color: 'red'
|
||||
|
||||
inputs:
|
||||
msgtype:
|
||||
description: '消息类型,当前支持 text markdown image news file template_card'
|
||||
required: true
|
||||
content:
|
||||
description: '当 msgtype=text 时:文本内容,最长不超过 2048 个字节,必须是 utf8 编码;当 msgtype=text 时:markdown 内容,最长不超过 4096 个字节,必须是 utf8 编码 支持的格式详见 https://work.weixin.qq.com/api/doc/90000/90136/91770'
|
||||
required: false
|
||||
mentioned_list:
|
||||
description: 'userid 的列表,提醒群中的指定成员(@某个成员),@all表示提醒所有人,如果开发者获取不到 userid,可以使用 mentioned_mobile_list,必须是序列化后的 JSON 字符串'
|
||||
required: false
|
||||
mentioned_mobile_list:
|
||||
description: '手机号列表,提醒手机号对应的群成员(@某个成员),@all表示提醒所有人,必须是序列化后的 JSON 字符串'
|
||||
required: false
|
||||
base64:
|
||||
description: '图片内容的 base64 编码 注:图片(base64 编码前)最大不能超过 2 M,支持 JPG、PNG 格式'
|
||||
required: false
|
||||
md5:
|
||||
description: '图片内容(base64 编码前)的 md5 值'
|
||||
required: false
|
||||
articles:
|
||||
description: '图文消息,一个图文消息支持 1 到 8 条图文,必须是序列化后的 JSON 字符串'
|
||||
required: false
|
||||
media_id:
|
||||
description: '文件 id,通过 [文件上传接口](https://work.weixin.qq.com/api/doc/90000/90136/91770) 获取'
|
||||
required: false
|
||||
template_card:
|
||||
description: '模版卡片参数,必须是序列化后的 JSON 字符串,参数详见 https://developer.work.weixin.qq.com/document/path/91770#%E6%A8%A1%E7%89%88%E5%8D%A1%E7%89%87%E7%B1%BB%E5%9E%8B'
|
||||
required: false
|
||||
|
||||
runs:
|
||||
using: 'node16'
|
||||
main: 'dist/index.js'
|
||||
|
5234
dist/index.js
vendored
Normal file
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
BIN
docs/wechat-work-msg-file.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
docs/wechat-work-msg-image.png
Normal file
After Width: | Height: | Size: 9.7 KiB |
Before Width: | Height: | Size: 63 KiB After Width: | Height: | Size: 63 KiB |
BIN
docs/wechat-work-msg-news-notice.webp
Normal file
After Width: | Height: | Size: 146 KiB |
Before Width: | Height: | Size: 176 KiB After Width: | Height: | Size: 176 KiB |
BIN
docs/wechat-work-msg-text-notice.webp
Normal file
After Width: | Height: | Size: 131 KiB |
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 44 KiB |
@ -1,91 +0,0 @@
|
||||
const axios = require('axios');
|
||||
const _ = require('lodash');
|
||||
const { argv } = require('yargs');
|
||||
|
||||
const payload = {};
|
||||
|
||||
if (process.env.INPUT_MSGTYPE === 'text') {
|
||||
|
||||
payload.msgtype = process.env.INPUT_MSGTYPE;
|
||||
payload.text = {
|
||||
content: process.env.INPUT_CONTENT,
|
||||
};
|
||||
|
||||
if (process.env.INPUT_MENTIONED_LIST) {
|
||||
let mentioned_list;
|
||||
try {
|
||||
mentioned_list = JSON.parse(process.env.INPUT_MENTIONED_LIST);
|
||||
} catch (error) {
|
||||
mentioned_list = [];
|
||||
}
|
||||
payload.text.mentioned_list = mentioned_list;
|
||||
}
|
||||
|
||||
if (process.env.INPUT_MENTIONED_MOBILE_LIST) {
|
||||
let mentioned_mobile_list;
|
||||
try {
|
||||
mentioned_mobile_list = JSON.parse(process.env.INPUT_MENTIONED_MOBILE_LIST);
|
||||
} catch (error) {
|
||||
mentioned_mobile_list = [];
|
||||
}
|
||||
payload.text.mentioned_mobile_list = mentioned_mobile_list;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (process.env.INPUT_MSGTYPE === 'markdown') {
|
||||
|
||||
payload.msgtype = process.env.INPUT_MSGTYPE;
|
||||
payload.markdown = {
|
||||
content: process.env.INPUT_CONTENT,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
if (process.env.INPUT_MSGTYPE === 'image') {
|
||||
|
||||
payload.msgtype = process.env.INPUT_MSGTYPE;
|
||||
payload.image = {
|
||||
base64: process.env.INPUT_BASE64,
|
||||
md5: process.env.INPUT_MD5,
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (process.env.INPUT_MSGTYPE === 'news') {
|
||||
|
||||
payload.msgtype = process.env.INPUT_MSGTYPE;
|
||||
|
||||
let articles;
|
||||
try {
|
||||
articles = JSON.parse(process.env.INPUT_ARTICLES);
|
||||
} catch (error) {
|
||||
articles = [];
|
||||
}
|
||||
payload.news = {
|
||||
articles,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
console.log('The message content in JSON format...');
|
||||
console.log(JSON.stringify(payload));
|
||||
|
||||
const url = process.env.WECHAT_WORK_BOT_WEBHOOK;
|
||||
|
||||
(async () => {
|
||||
console.log('Sending message ...');
|
||||
await axios.post(url, JSON.stringify(payload), {
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
});
|
||||
console.log('Message sent ! Shutting down ...');
|
||||
process.exit(0);
|
||||
})()
|
||||
.catch((err) => {
|
||||
console.error(err.message);
|
||||
console.error('Message :', err.response.data);
|
||||
process.exit(1);
|
||||
});
|
232
package-lock.json
generated
@ -1,232 +0,0 @@
|
||||
{
|
||||
"name": "action-wechat-work",
|
||||
"version": "0.0.1",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"ansi-regex": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npm.taobao.org/ansi-regex/download/ansi-regex-4.1.0.tgz",
|
||||
"integrity": "sha1-i5+PCM8ay4Q3Vqg5yox+MWjFGZc="
|
||||
},
|
||||
"ansi-styles": {
|
||||
"version": "3.2.1",
|
||||
"resolved": "https://registry.npm.taobao.org/ansi-styles/download/ansi-styles-3.2.1.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fansi-styles%2Fdownload%2Fansi-styles-3.2.1.tgz",
|
||||
"integrity": "sha1-QfuyAkPlCxK+DwS43tvwdSDOhB0=",
|
||||
"requires": {
|
||||
"color-convert": "^1.9.0"
|
||||
}
|
||||
},
|
||||
"axios": {
|
||||
"version": "0.19.0",
|
||||
"resolved": "https://registry.npm.taobao.org/axios/download/axios-0.19.0.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Faxios%2Fdownload%2Faxios-0.19.0.tgz",
|
||||
"integrity": "sha1-jgm/89kSLhM/e4EByPvdAO09Krg=",
|
||||
"requires": {
|
||||
"follow-redirects": "1.5.10",
|
||||
"is-buffer": "^2.0.2"
|
||||
}
|
||||
},
|
||||
"camelcase": {
|
||||
"version": "5.3.1",
|
||||
"resolved": "https://registry.npm.taobao.org/camelcase/download/camelcase-5.3.1.tgz",
|
||||
"integrity": "sha1-48mzFWnhBoEd8kL3FXJaH0xJQyA="
|
||||
},
|
||||
"cliui": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npm.taobao.org/cliui/download/cliui-5.0.0.tgz",
|
||||
"integrity": "sha1-3u/P2y6AB4SqNPRvoI4GhRx7u8U=",
|
||||
"requires": {
|
||||
"string-width": "^3.1.0",
|
||||
"strip-ansi": "^5.2.0",
|
||||
"wrap-ansi": "^5.1.0"
|
||||
}
|
||||
},
|
||||
"color-convert": {
|
||||
"version": "1.9.3",
|
||||
"resolved": "https://registry.npm.taobao.org/color-convert/download/color-convert-1.9.3.tgz?cache=0&sync_timestamp=1566248870121&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fcolor-convert%2Fdownload%2Fcolor-convert-1.9.3.tgz",
|
||||
"integrity": "sha1-u3GFBpDh8TZWfeYp0tVHHe2kweg=",
|
||||
"requires": {
|
||||
"color-name": "1.1.3"
|
||||
}
|
||||
},
|
||||
"color-name": {
|
||||
"version": "1.1.3",
|
||||
"resolved": "https://registry.npm.taobao.org/color-name/download/color-name-1.1.3.tgz",
|
||||
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU="
|
||||
},
|
||||
"debug": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npm.taobao.org/debug/download/debug-3.1.0.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fdebug%2Fdownload%2Fdebug-3.1.0.tgz",
|
||||
"integrity": "sha1-W7WgZyYotkFJVmuhaBnmFRjGcmE=",
|
||||
"requires": {
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
},
|
||||
"decamelize": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npm.taobao.org/decamelize/download/decamelize-1.2.0.tgz",
|
||||
"integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA="
|
||||
},
|
||||
"emoji-regex": {
|
||||
"version": "7.0.3",
|
||||
"resolved": "https://registry.npm.taobao.org/emoji-regex/download/emoji-regex-7.0.3.tgz",
|
||||
"integrity": "sha1-kzoEBShgyF6DwSJHnEdIqOTHIVY="
|
||||
},
|
||||
"find-up": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npm.taobao.org/find-up/download/find-up-3.0.0.tgz",
|
||||
"integrity": "sha1-SRafHXmTQwZG2mHsxa41XCHJe3M=",
|
||||
"requires": {
|
||||
"locate-path": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"follow-redirects": {
|
||||
"version": "1.5.10",
|
||||
"resolved": "https://registry.npm.taobao.org/follow-redirects/download/follow-redirects-1.5.10.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Ffollow-redirects%2Fdownload%2Ffollow-redirects-1.5.10.tgz",
|
||||
"integrity": "sha1-e3qfmuov3/NnhqlP9kPtB/T/Xio=",
|
||||
"requires": {
|
||||
"debug": "=3.1.0"
|
||||
}
|
||||
},
|
||||
"get-caller-file": {
|
||||
"version": "2.0.5",
|
||||
"resolved": "https://registry.npm.taobao.org/get-caller-file/download/get-caller-file-2.0.5.tgz",
|
||||
"integrity": "sha1-T5RBKoLbMvNuOwuXQfipf+sDH34="
|
||||
},
|
||||
"is-buffer": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npm.taobao.org/is-buffer/download/is-buffer-2.0.3.tgz",
|
||||
"integrity": "sha1-Ts8/z3ScvR5HJonhCaxmJhol5yU="
|
||||
},
|
||||
"is-fullwidth-code-point": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npm.taobao.org/is-fullwidth-code-point/download/is-fullwidth-code-point-2.0.0.tgz",
|
||||
"integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8="
|
||||
},
|
||||
"locate-path": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npm.taobao.org/locate-path/download/locate-path-3.0.0.tgz",
|
||||
"integrity": "sha1-2+w7OrdZdYBxtY/ln8QYca8hQA4=",
|
||||
"requires": {
|
||||
"p-locate": "^3.0.0",
|
||||
"path-exists": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"lodash": {
|
||||
"version": "4.17.15",
|
||||
"resolved": "https://registry.npm.taobao.org/lodash/download/lodash-4.17.15.tgz",
|
||||
"integrity": "sha1-tEf2ZwoEVbv+7dETku/zMOoJdUg="
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npm.taobao.org/ms/download/ms-2.0.0.tgz",
|
||||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
||||
},
|
||||
"p-limit": {
|
||||
"version": "2.2.1",
|
||||
"resolved": "https://registry.npm.taobao.org/p-limit/download/p-limit-2.2.1.tgz",
|
||||
"integrity": "sha1-qgeniMwxUck5tRMfY1cPDdIAlTc=",
|
||||
"requires": {
|
||||
"p-try": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"p-locate": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npm.taobao.org/p-locate/download/p-locate-3.0.0.tgz",
|
||||
"integrity": "sha1-Mi1poFwCZLJZl9n0DNiokasAZKQ=",
|
||||
"requires": {
|
||||
"p-limit": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"p-try": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npm.taobao.org/p-try/download/p-try-2.2.0.tgz",
|
||||
"integrity": "sha1-yyhoVA4xPWHeWPr741zpAE1VQOY="
|
||||
},
|
||||
"path-exists": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npm.taobao.org/path-exists/download/path-exists-3.0.0.tgz",
|
||||
"integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU="
|
||||
},
|
||||
"require-directory": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npm.taobao.org/require-directory/download/require-directory-2.1.1.tgz",
|
||||
"integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I="
|
||||
},
|
||||
"require-main-filename": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npm.taobao.org/require-main-filename/download/require-main-filename-2.0.0.tgz",
|
||||
"integrity": "sha1-0LMp7MfMD2Fkn2IhW+aa9UqomJs="
|
||||
},
|
||||
"set-blocking": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npm.taobao.org/set-blocking/download/set-blocking-2.0.0.tgz",
|
||||
"integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc="
|
||||
},
|
||||
"string-width": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npm.taobao.org/string-width/download/string-width-3.1.0.tgz",
|
||||
"integrity": "sha1-InZ74htirxCBV0MG9prFG2IgOWE=",
|
||||
"requires": {
|
||||
"emoji-regex": "^7.0.1",
|
||||
"is-fullwidth-code-point": "^2.0.0",
|
||||
"strip-ansi": "^5.1.0"
|
||||
}
|
||||
},
|
||||
"strip-ansi": {
|
||||
"version": "5.2.0",
|
||||
"resolved": "https://registry.npm.taobao.org/strip-ansi/download/strip-ansi-5.2.0.tgz",
|
||||
"integrity": "sha1-jJpTb+tq/JYr36WxBKUJHBrZwK4=",
|
||||
"requires": {
|
||||
"ansi-regex": "^4.1.0"
|
||||
}
|
||||
},
|
||||
"which-module": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npm.taobao.org/which-module/download/which-module-2.0.0.tgz",
|
||||
"integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho="
|
||||
},
|
||||
"wrap-ansi": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npm.taobao.org/wrap-ansi/download/wrap-ansi-5.1.0.tgz",
|
||||
"integrity": "sha1-H9H2cjXVttD+54EFYAG/tpTAOwk=",
|
||||
"requires": {
|
||||
"ansi-styles": "^3.2.0",
|
||||
"string-width": "^3.0.0",
|
||||
"strip-ansi": "^5.0.0"
|
||||
}
|
||||
},
|
||||
"y18n": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npm.taobao.org/y18n/download/y18n-4.0.0.tgz",
|
||||
"integrity": "sha1-le+U+F7MgdAHwmThkKEg8KPIVms="
|
||||
},
|
||||
"yargs": {
|
||||
"version": "14.0.0",
|
||||
"resolved": "https://registry.npm.taobao.org/yargs/download/yargs-14.0.0.tgz?cache=0&sync_timestamp=1567812307271&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fyargs%2Fdownload%2Fyargs-14.0.0.tgz",
|
||||
"integrity": "sha1-ukysyAKzwLPjap55FyN2PVeoUGY=",
|
||||
"requires": {
|
||||
"cliui": "^5.0.0",
|
||||
"decamelize": "^1.2.0",
|
||||
"find-up": "^3.0.0",
|
||||
"get-caller-file": "^2.0.1",
|
||||
"require-directory": "^2.1.1",
|
||||
"require-main-filename": "^2.0.0",
|
||||
"set-blocking": "^2.0.0",
|
||||
"string-width": "^3.0.0",
|
||||
"which-module": "^2.0.0",
|
||||
"y18n": "^4.0.0",
|
||||
"yargs-parser": "^13.1.1"
|
||||
}
|
||||
},
|
||||
"yargs-parser": {
|
||||
"version": "13.1.1",
|
||||
"resolved": "https://registry.npm.taobao.org/yargs-parser/download/yargs-parser-13.1.1.tgz",
|
||||
"integrity": "sha1-0mBYUyqgbTZf4JH2ofwGsvfl7KA=",
|
||||
"requires": {
|
||||
"camelcase": "^5.0.0",
|
||||
"decamelize": "^1.2.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
12
package.json
@ -1,10 +1,11 @@
|
||||
{
|
||||
"name": "action-wechat-work",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.8",
|
||||
"description": "GitHub Action that sends a WeChat Work notification.",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"test": "npm test"
|
||||
"test": "npm test",
|
||||
"build": "ncc build src/entrypoint.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -24,8 +25,9 @@
|
||||
},
|
||||
"homepage": "https://github.com/chf007/action-wechat-work#readme",
|
||||
"dependencies": {
|
||||
"axios": "^0.19.0",
|
||||
"lodash": "^4.17.15",
|
||||
"yargs": "^14.0.0"
|
||||
"axios": "^0.27.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vercel/ncc": "^0.34.0"
|
||||
}
|
||||
}
|
||||
|
74
pnpm-lock.yaml
generated
Normal file
@ -0,0 +1,74 @@
|
||||
lockfileVersion: 5.4
|
||||
|
||||
specifiers:
|
||||
'@vercel/ncc': ^0.34.0
|
||||
axios: ^0.27.2
|
||||
|
||||
dependencies:
|
||||
axios: 0.27.2
|
||||
|
||||
devDependencies:
|
||||
'@vercel/ncc': 0.34.0
|
||||
|
||||
packages:
|
||||
|
||||
/@vercel/ncc/0.34.0:
|
||||
resolution: {integrity: sha512-G9h5ZLBJ/V57Ou9vz5hI8pda/YQX5HQszCs3AmIus3XzsmRn/0Ptic5otD3xVST8QLKk7AMk7AqpsyQGN7MZ9A==}
|
||||
hasBin: true
|
||||
dev: true
|
||||
|
||||
/asynckit/0.4.0:
|
||||
resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==}
|
||||
dev: false
|
||||
|
||||
/axios/0.27.2:
|
||||
resolution: {integrity: sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==}
|
||||
dependencies:
|
||||
follow-redirects: 1.15.2
|
||||
form-data: 4.0.0
|
||||
transitivePeerDependencies:
|
||||
- debug
|
||||
dev: false
|
||||
|
||||
/combined-stream/1.0.8:
|
||||
resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==}
|
||||
engines: {node: '>= 0.8'}
|
||||
dependencies:
|
||||
delayed-stream: 1.0.0
|
||||
dev: false
|
||||
|
||||
/delayed-stream/1.0.0:
|
||||
resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==}
|
||||
engines: {node: '>=0.4.0'}
|
||||
dev: false
|
||||
|
||||
/follow-redirects/1.15.2:
|
||||
resolution: {integrity: sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==}
|
||||
engines: {node: '>=4.0'}
|
||||
peerDependencies:
|
||||
debug: '*'
|
||||
peerDependenciesMeta:
|
||||
debug:
|
||||
optional: true
|
||||
dev: false
|
||||
|
||||
/form-data/4.0.0:
|
||||
resolution: {integrity: sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==}
|
||||
engines: {node: '>= 6'}
|
||||
dependencies:
|
||||
asynckit: 0.4.0
|
||||
combined-stream: 1.0.8
|
||||
mime-types: 2.1.35
|
||||
dev: false
|
||||
|
||||
/mime-db/1.52.0:
|
||||
resolution: {integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==}
|
||||
engines: {node: '>= 0.6'}
|
||||
dev: false
|
||||
|
||||
/mime-types/2.1.35:
|
||||
resolution: {integrity: sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==}
|
||||
engines: {node: '>= 0.6'}
|
||||
dependencies:
|
||||
mime-db: 1.52.0
|
||||
dev: false
|
139
src/entrypoint.js
Normal file
@ -0,0 +1,139 @@
|
||||
const axios = require('axios');
|
||||
|
||||
const payload = {};
|
||||
|
||||
if (process.env.INPUT_MSGTYPE === 'text') {
|
||||
|
||||
payload.msgtype = process.env.INPUT_MSGTYPE;
|
||||
|
||||
if (!process.env.INPUT_CONTENT) {
|
||||
console.log(`[action-wechat-work] INPUT_CONTENT is blank: ${process.env.INPUT_CONTENT}`);
|
||||
}
|
||||
|
||||
payload.text = {
|
||||
content: process.env.INPUT_CONTENT,
|
||||
};
|
||||
|
||||
if (process.env.INPUT_MENTIONED_LIST) {
|
||||
let mentioned_list;
|
||||
try {
|
||||
mentioned_list = JSON.parse(process.env.INPUT_MENTIONED_LIST);
|
||||
} catch (error) {
|
||||
mentioned_list = [];
|
||||
console.log(`[action-wechat-work] INPUT_MENTIONED_LIST JSON.parse error: ${error}, JSON string: ${process.env.INPUT_MENTIONED_LIST}`);
|
||||
}
|
||||
payload.text.mentioned_list = mentioned_list;
|
||||
}
|
||||
|
||||
if (process.env.INPUT_MENTIONED_MOBILE_LIST) {
|
||||
let mentioned_mobile_list;
|
||||
try {
|
||||
mentioned_mobile_list = JSON.parse(process.env.INPUT_MENTIONED_MOBILE_LIST);
|
||||
} catch (error) {
|
||||
mentioned_mobile_list = [];
|
||||
console.log(`[action-wechat-work] INPUT_MENTIONED_MOBILE_LIST JSON.parse error: ${error}, JSON string: ${process.env.INPUT_MENTIONED_MOBILE_LIST}`);
|
||||
}
|
||||
payload.text.mentioned_mobile_list = mentioned_mobile_list;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (process.env.INPUT_MSGTYPE === 'markdown') {
|
||||
|
||||
payload.msgtype = process.env.INPUT_MSGTYPE;
|
||||
|
||||
if (!process.env.INPUT_CONTENT) {
|
||||
console.log(`[action-wechat-work] INPUT_CONTENT is blank: ${process.env.INPUT_CONTENT}`);
|
||||
}
|
||||
|
||||
payload.markdown = {
|
||||
content: process.env.INPUT_CONTENT,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
if (process.env.INPUT_MSGTYPE === 'image') {
|
||||
|
||||
payload.msgtype = process.env.INPUT_MSGTYPE;
|
||||
|
||||
if (!process.env.INPUT_BASE64) {
|
||||
console.log(`[action-wechat-work] INPUT_BASE64 is blank: ${process.env.INPUT_BASE64}`);
|
||||
}
|
||||
|
||||
if (!process.env.INPUT_MD5) {
|
||||
console.log(`[action-wechat-work] INPUT_MD5 is blank: ${process.env.INPUT_MD5}`);
|
||||
}
|
||||
|
||||
payload.image = {
|
||||
base64: process.env.INPUT_BASE64,
|
||||
md5: process.env.INPUT_MD5,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
if (process.env.INPUT_MSGTYPE === 'news') {
|
||||
|
||||
payload.msgtype = process.env.INPUT_MSGTYPE;
|
||||
|
||||
let articles;
|
||||
try {
|
||||
articles = JSON.parse(process.env.INPUT_ARTICLES);
|
||||
} catch (error) {
|
||||
articles = [];
|
||||
console.log(`[action-wechat-work] INPUT_ARTICLES JSON.parse error: ${error}, JSON string: ${process.env.INPUT_ARTICLES}`);
|
||||
}
|
||||
payload.news = {
|
||||
articles,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
if (process.env.INPUT_MSGTYPE === 'file') {
|
||||
|
||||
payload.msgtype = process.env.INPUT_MSGTYPE;
|
||||
|
||||
if (!process.env.INPUT_MEDIA_ID) {
|
||||
console.log(`[action-wechat-work] INPUT_MEDIA_ID is blank: ${process.env.INPUT_MEDIA_ID}`);
|
||||
}
|
||||
|
||||
payload.file = {
|
||||
media_id: process.env.INPUT_MEDIA_ID,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
if (process.env.INPUT_MSGTYPE === 'template_card') {
|
||||
|
||||
payload.msgtype = process.env.INPUT_MSGTYPE;
|
||||
|
||||
let template_card;
|
||||
try {
|
||||
template_card = JSON.parse(process.env.INPUT_TEMPLATE_CARD);
|
||||
} catch (error) {
|
||||
template_card = {};
|
||||
console.log(`[action-wechat-work] INPUT_TEMPLATE_CARD JSON.parse error: ${error}, JSON string: ${process.env.INPUT_TEMPLATE_CARD}`);
|
||||
}
|
||||
payload.template_card = template_card;
|
||||
|
||||
}
|
||||
|
||||
console.log('[action-wechat-work] The message content in JSON format...', JSON.stringify(payload));
|
||||
|
||||
const url = process.env.WECHAT_WORK_BOT_WEBHOOK;
|
||||
|
||||
(async () => {
|
||||
console.log('[action-wechat-work] Sending message ...');
|
||||
await axios.post(url, JSON.stringify(payload), {
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
});
|
||||
console.log('[action-wechat-work] Message sent Success! Shutting down ...');
|
||||
process.exit(0);
|
||||
})()
|
||||
.catch((err) => {
|
||||
console.error('[action-wechat-work] Message sent error:');
|
||||
err.message && console.error(`[action-wechat-work] err.message: ${err.message}`);
|
||||
err.response && err.response.data && console.error(`[action-wechat-work] err.response.data: ${err.response.data}`);
|
||||
process.exit(1);
|
||||
});
|