Skip to content

Commit

Permalink
feat: 支持模板卡片类型消息;升级依赖;异常处理优化;
Browse files Browse the repository at this point in the history
  • Loading branch information
guanhongfu committed Sep 14, 2022
1 parent 46370aa commit 07415b7
Show file tree
Hide file tree
Showing 11 changed files with 493 additions and 510 deletions.
20 changes: 19 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,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类型
Expand Down Expand Up @@ -57,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"}}'
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
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"]'
```
Expand Down Expand Up @@ -115,6 +115,45 @@
| msgtype | true | 消息类型,此时固定为 file |
| media_id | true | 文件 id,通过 [文件上传接口](https://work.weixin.qq.com/api/doc/90000/90136/91770) 获取 |
### 模版卡片类型消息 - 文本通知模版卡片
![WeChat Work message](./docs/wechat-work-msg-text-notice.webp "WeChat Work message")
```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 |
### 模版卡片类型消息 - 图文展示模版卡片
![WeChat Work message](./docs/wechat-work-msg-news-notice.webp "WeChat Work message")
```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

* **`WECHAT_WORK_BOT_WEBHOOK`**: 企业微信 Webhook URL (**required**)
Expand Down
123 changes: 0 additions & 123 deletions README.zh-CN.md

This file was deleted.

5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ branding:

inputs:
msgtype:
description: '消息类型,当前支持 text markdown image news file'
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'
Expand All @@ -31,6 +31,9 @@ inputs:
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'
Expand Down
Loading

0 comments on commit 07415b7

Please sign in to comment.