Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
07415b7499 | ||
|
|
46370aa1f7 | ||
|
|
f99560aa94 | ||
|
|
89f4ffaa53 | ||
|
|
6df0f2f152 | ||
|
|
7ecbb4de6c | ||
|
|
9c8d16d926 | ||
|
|
c6d92613c7 | ||
|
|
2903b97062 | ||
|
|
59ba9c8152 | ||
|
|
8b2766073f | ||
|
|
cadaf675dd | ||
|
|
e9738beb79 | ||
|
|
aa341fdcfe | ||
|
|
8d6721ecd2 | ||
|
|
522201f34b | ||
|
|
97dcd7641c |
25
.github/workflows/main.yml
vendored
@@ -3,7 +3,10 @@ on: [push]
|
||||
|
||||
jobs:
|
||||
send-msg:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
steps:
|
||||
# 纯文本类型
|
||||
- name: WeChat Work notification by text
|
||||
@@ -12,7 +15,7 @@ jobs:
|
||||
WECHAT_WORK_BOT_WEBHOOK: ${{secrets.WECHAT_WORK_BOT_WEBHOOK}}
|
||||
with:
|
||||
msgtype: text
|
||||
content: 广州今日天气:29度,大部分多云,降雨概率:60%
|
||||
content: "广州今日天气:29度,大部分多云,降雨概率:60%"
|
||||
mentioned_list: '["@all"]'
|
||||
|
||||
# markdown类型
|
||||
@@ -54,3 +57,21 @@ jobs:
|
||||
with:
|
||||
msgtype: file
|
||||
media_id: 2eNNDDAZxBnhGvz_KafNtCGC5lZOwJraS5BEe8EvzNAncouNQQrAghfE47uV5RGrg
|
||||
|
||||
# 模版卡片类型 - 文本通知模版卡片
|
||||
- name: WeChat Work notification by template_card.text_notice
|
||||
uses: chf007/action-wechat-work@master
|
||||
env:
|
||||
WECHAT_WORK_BOT_WEBHOOK: ${{secrets.WECHAT_WORK_BOT_WEBHOOK}}
|
||||
with:
|
||||
msgtype: template_card
|
||||
template_card: '{"card_type":"text_notice","source":{"icon_url":"https://wework.qpic.cn/wwpic/252813_jOfDHtcISzuodLa_1629280209/0","desc":"企业微信","desc_color":0},"main_title":{"title":"欢迎使用企业微信","desc":"您的好友正在邀请您加入企业微信"},"emphasis_content":{"title":"100","desc":"数据含义"},"quote_area":{"type":1,"url":"https://work.weixin.qq.com/?from=openApi","appid":"APPID","pagepath":"PAGEPATH","title":"引用文本标题","quote_text":"Jack:企业微信真的很好用~\nBalian:超级好的一款软件!"},"sub_title_text":"下载企业微信还能抢红包!","horizontal_content_list":[{"keyname":"邀请人","value":"张三"},{"keyname":"企微官网","value":"点击访问","type":1,"url":"https://work.weixin.qq.com/?from=openApi"},{"keyname":"企微下载","value":"企业微信.apk","type":2,"media_id":"MEDIAID"}],"jump_list":[{"type":1,"url":"https://work.weixin.qq.com/?from=openApi","title":"企业微信官网"},{"type":2,"appid":"APPID","pagepath":"PAGEPATH","title":"跳转小程序"}],"card_action":{"type":1,"url":"https://work.weixin.qq.com/?from=openApi","appid":"APPID","pagepath":"PAGEPATH"}}'
|
||||
|
||||
# 模版卡片类型 - 图文展示模版卡片
|
||||
- name: WeChat Work notification by template_card.news_notice
|
||||
uses: chf007/action-wechat-work@master
|
||||
env:
|
||||
WECHAT_WORK_BOT_WEBHOOK: ${{secrets.WECHAT_WORK_BOT_WEBHOOK}}
|
||||
with:
|
||||
msgtype: template_card
|
||||
template_card: '{"card_type":"news_notice","source":{"icon_url":"https://wework.qpic.cn/wwpic/252813_jOfDHtcISzuodLa_1629280209/0","desc":"企业微信","desc_color":0},"main_title":{"title":"欢迎使用企业微信","desc":"您的好友正在邀请您加入企业微信"},"card_image":{"url":"https://wework.qpic.cn/wwpic/354393_4zpkKXd7SrGMvfg_1629280616/0","aspect_ratio":2.25},"image_text_area":{"type":1,"url":"https://work.weixin.qq.com","title":"欢迎使用企业微信","desc":"您的好友正在邀请您加入企业微信","image_url":"https://wework.qpic.cn/wwpic/354393_4zpkKXd7SrGMvfg_1629280616/0"},"quote_area":{"type":1,"url":"https://work.weixin.qq.com/?from=openApi","appid":"APPID","pagepath":"PAGEPATH","title":"引用文本标题","quote_text":"Jack:企业微信真的很好用~\nBalian:超级好的一款软件!"},"vertical_content_list":[{"title":"惊喜红包等你来拿","desc":"下载企业微信还能抢红包!"}],"horizontal_content_list":[{"keyname":"邀请人","value":"张三"},{"keyname":"企微官网","value":"点击访问","type":1,"url":"https://work.weixin.qq.com/?from=openApi"},{"keyname":"企微下载","value":"企业微信.apk","type":2,"media_id":"MEDIAID"}],"jump_list":[{"type":1,"url":"https://work.weixin.qq.com/?from=openApi","title":"企业微信官网"},{"type":2,"appid":"APPID","pagepath":"PAGEPATH","title":"跳转小程序"}],"card_action":{"type":1,"url":"https://work.weixin.qq.com/?from=openApi","appid":"APPID","pagepath":"PAGEPATH"}}'
|
||||
|
||||
1
.gitignore
vendored
@@ -1,2 +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.4"
|
||||
|
||||
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) 2020-present chf007
|
||||
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
|
||||
|
||||
111
README.md
@@ -1,8 +1,8 @@
|
||||
# WeChat Work for GitHub Actions
|
||||
|
||||
通过企业微信机器人发送消息
|
||||
通过企业微信机器人发送消息。
|
||||
|
||||

|
||||

|
||||
|
||||
<hr/>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
### 纯文本格式消息
|
||||
|
||||

|
||||

|
||||
|
||||
```yaml
|
||||
- name: WeChat Work notification by text
|
||||
@@ -19,21 +19,21 @@
|
||||
WECHAT_WORK_BOT_WEBHOOK: ${{secrets.WECHAT_WORK_BOT_WEBHOOK}}
|
||||
with:
|
||||
msgtype: text
|
||||
content: 广州今日天气:29 度,大部分多云,降雨概率:60%
|
||||
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 字符串
|
||||
| 参数 | 必须 | 说明 |
|
||||
|-----------------------|-------|-------------------------------------------------------------------------------------------------------|
|
||||
| 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
|
||||
@@ -48,14 +48,14 @@ mentioned_mobile_list | false | 手机号列表,提醒手机号对应的群成
|
||||
> VIP用户反馈:<font color=\"comment\">15例</font>"
|
||||
```
|
||||
|
||||
参数 | 必须 | 说明
|
||||
------------ | ------------- | -------------
|
||||
msgtype | true | 消息类型,此时固定为 markdown
|
||||
content | true | markdown 内容,最长不超过 4096 个字节,必须是 utf8 编码 支持的格式详见 https://work.weixin.qq.com/api/doc/90000/90136/91770
|
||||
| 参数 | 必须 | 说明 |
|
||||
|---------|------|-----------------------------------------------------------------------------------------------------|
|
||||
| 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
|
||||
@@ -68,15 +68,15 @@ content | true | markdown 内容,最长不超过 4096 个字节,必须是 ut
|
||||
md5: 0582d8564cdee3187207666898f75205
|
||||
```
|
||||
|
||||
参数 | 必须 | 说明
|
||||
------------ | ------------- | -------------
|
||||
msgtype | true | 消息类型,此时固定为 image
|
||||
base64 | true | 图片内容的 base64 编码 注:图片(base64 编码前)最大不能超过 2 M,支持 JPG、PNG 格式
|
||||
md5 | true | 图片内容(base64 编码前)的 md5 值
|
||||
| 参数 | 必须 | 说明 |
|
||||
|---------|------|----------------------------------------------------------|
|
||||
| msgtype | true | 消息类型,此时固定为 image |
|
||||
| base64 | true | 图片内容的 base64 编码 注:图片(base64 编码前)最大不能超过 2 M,支持 JPG、PNG 格式 |
|
||||
| md5 | true | 图片内容(base64 编码前)的 md5 值 |
|
||||
|
||||
### 图文格式消息
|
||||
|
||||

|
||||

|
||||
|
||||
```yaml
|
||||
- name: WeChat Work notification by news
|
||||
@@ -85,20 +85,20 @@ md5 | true | 图片内容(base64 编码前)的 md5 值
|
||||
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"}]'
|
||||
articles: '[{"title":"中秋节礼品领取","description":"今年中秋节公司有豪礼相送","url":"URL","picurl":"https://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。
|
||||
| 参数 | 必须 | 说明 |
|
||||
|----------------------|-------|-------------------------------------------------------|
|
||||
| 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。 |
|
||||
|
||||
### 文件格式消息
|
||||
|
||||

|
||||

|
||||
|
||||
```yaml
|
||||
- name: WeChat Work notification by file
|
||||
@@ -110,10 +110,49 @@ articles.picurl | false | 图文消息的图片链接,支持 JPG、PNG 格式
|
||||
media_id: 3a8asd892asd8asd
|
||||
```
|
||||
|
||||
参数 | 必须 | 说明
|
||||
------------ | ------------- | -------------
|
||||
msgtype | true | 消息类型,此时固定为 file
|
||||
media_id | true | 文件 id,通过 [文件上传接口](https://work.weixin.qq.com/api/doc/90000/90136/91770) 获取
|
||||
| 参数 | 必须 | 说明 |
|
||||
|----------|------|----------------------------------------------------------------------------|
|
||||
| msgtype | true | 消息类型,此时固定为 file |
|
||||
| media_id | true | 文件 id,通过 [文件上传接口](https://work.weixin.qq.com/api/doc/90000/90136/91770) 获取 |
|
||||
|
||||
### 模版卡片类型消息 - 文本通知模版卡片
|
||||
|
||||

|
||||
|
||||
```yaml
|
||||
- name: WeChat Work notification by template_card.text_notice
|
||||
uses: chf007/action-wechat-work@master
|
||||
env:
|
||||
WECHAT_WORK_BOT_WEBHOOK: ${{secrets.WECHAT_WORK_BOT_WEBHOOK}}
|
||||
with:
|
||||
msgtype: template_card
|
||||
template_card: '{"card_type":"text_notice","source":{"icon_url":"https://wework.qpic.cn/wwpic/252813_jOfDHtcISzuodLa_1629280209/0","desc":"企业微信","desc_color":0},"main_title":{"title":"欢迎使用企业微信","desc":"您的好友正在邀请您加入企业微信"},"emphasis_content":{"title":"100","desc":"数据含义"},"quote_area":{"type":1,"url":"https://work.weixin.qq.com/?from=openApi","appid":"APPID","pagepath":"PAGEPATH","title":"引用文本标题","quote_text":"Jack:企业微信真的很好用~\nBalian:超级好的一款软件!"},"sub_title_text":"下载企业微信还能抢红包!","horizontal_content_list":[{"keyname":"邀请人","value":"张三"},{"keyname":"企微官网","value":"点击访问","type":1,"url":"https://work.weixin.qq.com/?from=openApi"},{"keyname":"企微下载","value":"企业微信.apk","type":2,"media_id":"MEDIAID"}],"jump_list":[{"type":1,"url":"https://work.weixin.qq.com/?from=openApi","title":"企业微信官网"},{"type":2,"appid":"APPID","pagepath":"PAGEPATH","title":"跳转小程序"}],"card_action":{"type":1,"url":"https://work.weixin.qq.com/?from=openApi","appid":"APPID","pagepath":"PAGEPATH"}}'
|
||||
```
|
||||
|
||||
| 参数 | 必须 | 说明 |
|
||||
|---------|------|-----------------------------------------------------------------------------------------------------|
|
||||
| msgtype | true | 消息类型,此时固定为 template_card |
|
||||
| template_card | true | 模版卡片参数,必须是序列化后的 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 |
|
||||
|
||||
### 模版卡片类型消息 - 图文展示模版卡片
|
||||
|
||||

|
||||
|
||||
```yaml
|
||||
- name: WeChat Work notification by template_card.news_notice
|
||||
uses: chf007/action-wechat-work@master
|
||||
env:
|
||||
WECHAT_WORK_BOT_WEBHOOK: ${{secrets.WECHAT_WORK_BOT_WEBHOOK}}
|
||||
with:
|
||||
msgtype: template_card
|
||||
template_card: '{"card_type":"news_notice","source":{"icon_url":"https://wework.qpic.cn/wwpic/252813_jOfDHtcISzuodLa_1629280209/0","desc":"企业微信","desc_color":0},"main_title":{"title":"欢迎使用企业微信","desc":"您的好友正在邀请您加入企业微信"},"card_image":{"url":"https://wework.qpic.cn/wwpic/354393_4zpkKXd7SrGMvfg_1629280616/0","aspect_ratio":2.25},"image_text_area":{"type":1,"url":"https://work.weixin.qq.com","title":"欢迎使用企业微信","desc":"您的好友正在邀请您加入企业微信","image_url":"https://wework.qpic.cn/wwpic/354393_4zpkKXd7SrGMvfg_1629280616/0"},"quote_area":{"type":1,"url":"https://work.weixin.qq.com/?from=openApi","appid":"APPID","pagepath":"PAGEPATH","title":"引用文本标题","quote_text":"Jack:企业微信真的很好用~\nBalian:超级好的一款软件!"},"vertical_content_list":[{"title":"惊喜红包等你来拿","desc":"下载企业微信还能抢红包!"}],"horizontal_content_list":[{"keyname":"邀请人","value":"张三"},{"keyname":"企微官网","value":"点击访问","type":1,"url":"https://work.weixin.qq.com/?from=openApi"},{"keyname":"企微下载","value":"企业微信.apk","type":2,"media_id":"MEDIAID"}],"jump_list":[{"type":1,"url":"https://work.weixin.qq.com/?from=openApi","title":"企业微信官网"},{"type":2,"appid":"APPID","pagepath":"PAGEPATH","title":"跳转小程序"}],"card_action":{"type":1,"url":"https://work.weixin.qq.com/?from=openApi","appid":"APPID","pagepath":"PAGEPATH"}}'
|
||||
|
||||
```
|
||||
|
||||
| 参数 | 必须 | 说明 |
|
||||
|---------|------|-----------------------------------------------------------------------------------------------------|
|
||||
| msgtype | true | 消息类型,此时固定为 template_card |
|
||||
| template_card | true | 模版卡片参数,必须是序列化后的 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 |
|
||||
|
||||
### WECHAT_WORK_BOT_WEBHOOK
|
||||
|
||||
|
||||
123
README.zh-CN.md
30
action.yml
@@ -8,9 +8,33 @@ branding:
|
||||
|
||||
inputs:
|
||||
msgtype:
|
||||
description: '消息类型'
|
||||
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: 'docker'
|
||||
image: 'Dockerfile'
|
||||
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 |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 9.7 KiB 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,99 +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,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
if (process.env.INPUT_MSGTYPE === 'file') {
|
||||
|
||||
payload.msgtype = process.env.INPUT_MSGTYPE;
|
||||
payload.file = {
|
||||
media_id: process.env.INPUT_MEDIA_ID,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
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 Success! Shutting down ...');
|
||||
process.exit(0);
|
||||
})()
|
||||
.catch((err) => {
|
||||
console.error(err.message);
|
||||
console.error('Message sent error:', err.response.data);
|
||||
process.exit(1);
|
||||
});
|
||||
139
package-lock.json
generated
@@ -1,139 +0,0 @@
|
||||
{
|
||||
"name": "action-wechat-work",
|
||||
"version": "1.0.4",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"ansi-regex": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz",
|
||||
"integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg=="
|
||||
},
|
||||
"ansi-styles": {
|
||||
"version": "4.3.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
|
||||
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
|
||||
"requires": {
|
||||
"color-convert": "^2.0.1"
|
||||
}
|
||||
},
|
||||
"axios": {
|
||||
"version": "0.21.1",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz",
|
||||
"integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==",
|
||||
"requires": {
|
||||
"follow-redirects": "^1.10.0"
|
||||
}
|
||||
},
|
||||
"cliui": {
|
||||
"version": "7.0.4",
|
||||
"resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz",
|
||||
"integrity": "sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==",
|
||||
"requires": {
|
||||
"string-width": "^4.2.0",
|
||||
"strip-ansi": "^6.0.0",
|
||||
"wrap-ansi": "^7.0.0"
|
||||
}
|
||||
},
|
||||
"color-convert": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
|
||||
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
|
||||
"requires": {
|
||||
"color-name": "~1.1.4"
|
||||
}
|
||||
},
|
||||
"color-name": {
|
||||
"version": "1.1.4",
|
||||
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
|
||||
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
|
||||
},
|
||||
"emoji-regex": {
|
||||
"version": "8.0.0",
|
||||
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
|
||||
"integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A=="
|
||||
},
|
||||
"escalade": {
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz",
|
||||
"integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw=="
|
||||
},
|
||||
"follow-redirects": {
|
||||
"version": "1.14.0",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.0.tgz",
|
||||
"integrity": "sha512-0vRwd7RKQBTt+mgu87mtYeofLFZpTas2S9zY+jIeuLJMNvudIgF52nr19q40HOwH5RrhWIPuj9puybzSJiRrVg=="
|
||||
},
|
||||
"get-caller-file": {
|
||||
"version": "2.0.5",
|
||||
"resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz",
|
||||
"integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg=="
|
||||
},
|
||||
"is-fullwidth-code-point": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
|
||||
"integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg=="
|
||||
},
|
||||
"lodash": {
|
||||
"version": "4.17.21",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
||||
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
|
||||
},
|
||||
"require-directory": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
|
||||
"integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I="
|
||||
},
|
||||
"string-width": {
|
||||
"version": "4.2.2",
|
||||
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.2.tgz",
|
||||
"integrity": "sha512-XBJbT3N4JhVumXE0eoLU9DCjcaF92KLNqTmFCnG1pf8duUxFGwtP6AD6nkjw9a3IdiRtL3E2w3JDiE/xi3vOeA==",
|
||||
"requires": {
|
||||
"emoji-regex": "^8.0.0",
|
||||
"is-fullwidth-code-point": "^3.0.0",
|
||||
"strip-ansi": "^6.0.0"
|
||||
}
|
||||
},
|
||||
"strip-ansi": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz",
|
||||
"integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==",
|
||||
"requires": {
|
||||
"ansi-regex": "^5.0.0"
|
||||
}
|
||||
},
|
||||
"wrap-ansi": {
|
||||
"version": "7.0.0",
|
||||
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz",
|
||||
"integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==",
|
||||
"requires": {
|
||||
"ansi-styles": "^4.0.0",
|
||||
"string-width": "^4.1.0",
|
||||
"strip-ansi": "^6.0.0"
|
||||
}
|
||||
},
|
||||
"y18n": {
|
||||
"version": "5.0.8",
|
||||
"resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz",
|
||||
"integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA=="
|
||||
},
|
||||
"yargs": {
|
||||
"version": "16.2.0",
|
||||
"resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz",
|
||||
"integrity": "sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==",
|
||||
"requires": {
|
||||
"cliui": "^7.0.2",
|
||||
"escalade": "^3.1.1",
|
||||
"get-caller-file": "^2.0.5",
|
||||
"require-directory": "^2.1.1",
|
||||
"string-width": "^4.2.0",
|
||||
"y18n": "^5.0.5",
|
||||
"yargs-parser": "^20.2.2"
|
||||
}
|
||||
},
|
||||
"yargs-parser": {
|
||||
"version": "20.2.7",
|
||||
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.7.tgz",
|
||||
"integrity": "sha512-FiNkvbeHzB/syOjIUxFDCnhSfzAL8R5vs40MgLFBorXACCOAEaWu0gRZl14vG8MR9AOJIZbmkjhusqBYZ3HTHw=="
|
||||
}
|
||||
}
|
||||
}
|
||||
12
package.json
@@ -1,10 +1,11 @@
|
||||
{
|
||||
"name": "action-wechat-work",
|
||||
"version": "1.0.4",
|
||||
"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.21.1",
|
||||
"lodash": "^4.17.21",
|
||||
"yargs": "^16.2.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);
|
||||
});
|
||||