From 73fed0e15ec5fc4d44e4b61d6a58adbe33fd0276 Mon Sep 17 00:00:00 2001 From: zcong1993 Date: Thu, 29 Aug 2019 16:48:20 +0800 Subject: [PATCH 1/4] more flexiable --- action.yml | 4 ++-- entrypoint.sh | 18 +++++------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/action.yml b/action.yml index 432d553..1994b9a 100644 --- a/action.yml +++ b/action.yml @@ -8,8 +8,8 @@ inputs: dingToken: description: 'DingDing bot token' required: true - message: - description: 'Message to send' + body: + description: 'Post Body to send' required: true runs: diff --git a/entrypoint.sh b/entrypoint.sh index 57bbf5a..e061bcf 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -6,24 +6,16 @@ then exit 1 fi -if [ -z "${INPUT_MESSAGE}" ] +if [ -z "${INPUT_BODY}" ] then - echo "message is required!" + echo "body is required!" exit 1 fi -url="https://oapi.dingtalk.com/robot/send?access_token=${INPUT_DINGTOKEN}" +echo "body: $INPUT_BODY" -body=$(cat < Date: Thu, 29 Aug 2019 17:12:34 +0800 Subject: [PATCH 2/4] use -s --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index e061bcf..b55ee5c 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -16,6 +16,6 @@ echo "body: $INPUT_BODY" url="https://oapi.dingtalk.com/robot/send?access_token=${INPUT_DINGTOKEN}" -curl "$url" \ +curl -s "$url" \ -H 'Content-Type: application/json' \ -d "${INPUT_BODY}" From 5dccd96f347a637ca779eb06e86d77e78910a0f7 Mon Sep 17 00:00:00 2001 From: zcong1993 Date: Thu, 29 Aug 2019 17:30:31 +0800 Subject: [PATCH 3/4] expect response --- entrypoint.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index b55ee5c..199e60a 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -16,6 +16,14 @@ echo "body: $INPUT_BODY" url="https://oapi.dingtalk.com/robot/send?access_token=${INPUT_DINGTOKEN}" -curl -s "$url" \ +HTTP_RESPONSE=$(curl -s --write-out "HTTPSTATUS:%{http_code}" "$url" \ -H 'Content-Type: application/json' \ - -d "${INPUT_BODY}" + -d "${INPUT_BODY}") + +# extract the body +HTTP_BODY=$(echo "$HTTP_RESPONSE" | sed -e 's/HTTPSTATUS\:.*//g') + +if [ ! "$HTTP_BODY" = '{"errcode":0,"errmsg":"ok"}' ]; then + echo "Error Response: ${HTTP_RESPONSE}" + exit 1 +fi From 6a608c2c247048c869fff516114b0fcd8c6f8a52 Mon Sep 17 00:00:00 2001 From: zcong1993 Date: Thu, 29 Aug 2019 17:50:47 +0800 Subject: [PATCH 4/4] update README.md --- .editorconfig | 12 ++++++++++++ README.md | 13 ++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..4a7ea30 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false diff --git a/README.md b/README.md index c971d6f..0410905 100644 --- a/README.md +++ b/README.md @@ -7,5 +7,16 @@ Send dingding simple notify message. uses: zcong1993/actions-ding@master with: dingToken: ${{ secrets.DING_TOKEN }} - message: test message + body: | + { + "msgtype": "link", + "link": { + "text": "这个即将发布的新版本,创始人陈航(花名“无招”)称它为“红树林”。而在此之前,每当面临重大升级,产品经理们都会取一个应景的代号,这一次,为什么是“红树林”?", + "title": "时代的火车向前开", + "picUrl": "", + "messageUrl": "https://www.dingtalk.com/s?__biz=MzA4NjMwMTA2Ng==&mid=2650316842&idx=1&sn=60da3ea2b29f1dcc43a7c8e4a7c97a16&scene=2&srcid=09189AnRJEdIiWVaKltFzNTw&from=timeline&isappinstalled=0&key=&ascene=2&uin=&devicetype=android-23&version=26031933&nettype=WIFI" + } + } ``` + +put any kind of message body [dingding](https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq) support into `body` field.