Compare commits

...

33 Commits

Author SHA1 Message Date
guanhongfu
07415b7499 feat: 支持模板卡片类型消息;升级依赖;异常处理优化; 2022-09-14 11:49:45 +08:00
guanhongfu
46370aa1f7 feat: 升级依赖;文件结构优化;异常处理优化; 2022-04-27 10:20:40 +08:00
guanhongfu
f99560aa94 feat: 补全 action.yml inputs 参数,消除警告;升级一些库的依赖; 2021-12-27 13:47:39 +08:00
chf007
89f4ffaa53
Update README.md 2021-12-20 12:09:25 +08:00
chf007
6df0f2f152
Merge pull request #12 from chf007/dependabot/npm_and_yarn/axios-0.21.2
Bump axios from 0.21.1 to 0.21.2
2021-09-10 23:35:49 +08:00
chf007
7ecbb4de6c
Update LICENSE 2021-09-10 15:41:45 +08:00
dependabot[bot]
9c8d16d926
Bump axios from 0.21.1 to 0.21.2
Bumps [axios](https://github.com/axios/axios) from 0.21.1 to 0.21.2.
- [Release notes](https://github.com/axios/axios/releases)
- [Changelog](https://github.com/axios/axios/blob/master/CHANGELOG.md)
- [Commits](https://github.com/axios/axios/compare/v0.21.1...v0.21.2)

---
updated-dependencies:
- dependency-name: axios
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-09-10 07:41:19 +00:00
chf007
c6d92613c7
Delete .DS_Store 2021-09-10 15:40:56 +08:00
chf007
2903b97062
Merge pull request #11 from fanchou/master
添加构建依赖,添加多平台测试任务
2021-05-07 18:49:09 +08:00
周凡
59ba9c8152
++ 2021-05-07 16:42:24 +08:00
周凡
8b2766073f
++ 2021-05-07 16:34:57 +08:00
zhoufan
cadaf675dd 忽略文件 2021-05-07 16:08:09 +08:00
zhoufan
e9738beb79 添加构建依赖,添加多平台测试任务 2021-05-07 16:07:16 +08:00
chf007
aa341fdcfe
Update package.json
跨平台支持
2021-05-06 10:02:10 +08:00
chf007
8d6721ecd2
Merge pull request #10 from fanchou/master
改为在node环境中执行,让它可以支持不同的平台
2021-05-06 09:59:44 +08:00
zhoufan
522201f34b 支持跨平台执行 2021-04-29 15:57:10 +08:00
周凡
97dcd7641c
Update action.yml
不要再容器中运行
2021-04-29 13:20:12 +08:00
guanhongfu
a47b2886f8 支持文件类型 2021-04-26 16:32:07 +08:00
guanhongfu
e6ba7dadb8 支持文件类型 2021-04-26 16:29:35 +08:00
guanhongfu
a558a94076 支持文件类型 2021-04-26 16:17:01 +08:00
guanhongfu
b91f63ab83 支持文件类型 2021-04-26 16:16:36 +08:00
guanhongfu
fca74f481b 支持文件类型 2021-04-26 15:56:16 +08:00
guanhongfu
7a9016bb71 支持文件类型 2021-04-26 15:55:44 +08:00
guanhongfu
460f7c9c9c 支持文件类型 2021-04-26 15:55:22 +08:00
chf007
b214c1483f
Merge pull request #7 from chf007/dependabot/npm_and_yarn/axios-0.21.1
Bump axios from 0.19.0 to 0.21.1
2021-01-07 11:39:29 +08:00
dependabot[bot]
b2b6bbbf73
Bump axios from 0.19.0 to 0.21.1
Bumps [axios](https://github.com/axios/axios) from 0.19.0 to 0.21.1.
- [Release notes](https://github.com/axios/axios/releases)
- [Changelog](https://github.com/axios/axios/blob/v0.21.1/CHANGELOG.md)
- [Commits](https://github.com/axios/axios/compare/v0.19.0...v0.21.1)

Signed-off-by: dependabot[bot] <support@github.com>
2021-01-05 14:13:14 +00:00
chf007
99fc51462f
Merge pull request #3 from chf007/dependabot/npm_and_yarn/yargs-parser-13.1.2
Bump yargs-parser from 13.1.1 to 13.1.2
2020-11-12 13:51:41 +08:00
dependabot[bot]
351306edbe
Bump yargs-parser from 13.1.1 to 13.1.2
Bumps [yargs-parser](https://github.com/yargs/yargs-parser) from 13.1.1 to 13.1.2.
- [Release notes](https://github.com/yargs/yargs-parser/releases)
- [Changelog](https://github.com/yargs/yargs-parser/blob/master/docs/CHANGELOG-full.md)
- [Commits](https://github.com/yargs/yargs-parser/commits)

Signed-off-by: dependabot[bot] <support@github.com>
2020-09-11 10:25:03 +00:00
chf007
8ca5e0242a
Merge pull request #1 from chf007/dependabot/npm_and_yarn/lodash-4.17.19
Bump lodash from 4.17.15 to 4.17.19
2020-09-02 10:15:39 +08:00
dependabot[bot]
dcbae93a71
Bump lodash from 4.17.15 to 4.17.19
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.15 to 4.17.19.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.17.15...4.17.19)

Signed-off-by: dependabot[bot] <support@github.com>
2020-07-18 06:07:01 +00:00
chf007
f03bfac03a
Update LICENSE 2020-04-11 17:23:46 +08:00
andreiguan
61138841ff action.yml 2019-09-11 21:36:49 +08:00
andreiguan
ba7f10ea31 doc 2019-09-11 16:21:02 +08:00
22 changed files with 5627 additions and 501 deletions

File diff suppressed because one or more lines are too long

2
.gitignore vendored
View File

@ -1 +1,3 @@
node_modules
/.idea
/.DS_Store

View File

@ -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"]

View File

@ -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

139
README.md

File diff suppressed because one or more lines are too long

View File

@ -1,103 +0,0 @@
# WeChat Work for GitHub Actions
通过企业微信机器人发送消息
![WeChat Work Logo](wechat-work-logo.png "WeChat Work Logo")
<hr/>
## 用法
#### 纯文本格式消息
![WeChat Work message](wechat-work-msg-text.png "WeChat Work message")
```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格式消息
![WeChat Work message](wechat-work-msg-markdown.png "WeChat Work message")
```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
#### 图片格式消息
![WeChat Work message](wechat-work-msg-images.png "WeChat Work message")
```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值
#### 图文格式消息
![WeChat Work message](wechat-work-msg-news.png "WeChat Work message")
```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).

View File

@ -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

File diff suppressed because one or more lines are too long

View File

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

View File

Before

Width:  |  Height:  |  Size: 63 KiB

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 KiB

View File

Before

Width:  |  Height:  |  Size: 176 KiB

After

Width:  |  Height:  |  Size: 176 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 KiB

View File

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 44 KiB

View File

@ -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
View File

@ -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"
}
}
}
}

View File

@ -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
View 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
View 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);
});

View File

@ -1,4 +0,0 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1