mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-18 03:56:36 +00:00
Feat(workflow): support dingding and slack in webhook notification (#2213)
This commit is contained in:
@@ -1,67 +0,0 @@
|
||||
# Code generated by KubeVela templates. DO NOT EDIT. Please edit the original cue file.
|
||||
# Definition source cue file: vela-templates/definitions/internal/dingtalk.cue
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: WorkflowStepDefinition
|
||||
metadata:
|
||||
annotations:
|
||||
definition.oam.dev/description: Send message with DingTalk robot
|
||||
name: dingtalk
|
||||
namespace: {{.Values.systemDefinitionNamespace}}
|
||||
spec:
|
||||
schematic:
|
||||
cue:
|
||||
template: |
|
||||
import (
|
||||
"vela/op"
|
||||
)
|
||||
|
||||
// apply remaining components and traits
|
||||
ding: op.#DingTalk & {
|
||||
parameter
|
||||
}
|
||||
parameter: {
|
||||
// +usage=Declare the token of the DingTalk robot
|
||||
token: string
|
||||
message: {
|
||||
text?: *null | {
|
||||
content: string
|
||||
}
|
||||
// +usage=msgType can be text, link, mardown, actionCard, feedCard
|
||||
msgtype: string
|
||||
link?: *null | {
|
||||
text?: string
|
||||
title?: string
|
||||
messageUrl?: string
|
||||
picUrl?: string
|
||||
}
|
||||
markdown?: *null | {
|
||||
text: string
|
||||
title: string
|
||||
}
|
||||
at?: *null | {
|
||||
atMobiles?: *null | [...string]
|
||||
isAtAll?: bool
|
||||
}
|
||||
actionCard?: *null | {
|
||||
text: string
|
||||
title: string
|
||||
hideAvatar: string
|
||||
btnOrientation: string
|
||||
singleTitle: string
|
||||
singleURL: string
|
||||
btns: *null | [...*null | {
|
||||
title: string
|
||||
actionURL: string
|
||||
}]
|
||||
}
|
||||
feedCard?: *null | {
|
||||
links: *null | [...*null | {
|
||||
text?: string
|
||||
title?: string
|
||||
messageUrl?: string
|
||||
picUrl?: string
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
# Code generated by KubeVela templates. DO NOT EDIT. Please edit the original cue file.
|
||||
# Definition source cue file: vela-templates/definitions/internal/webhook-notification.cue
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: WorkflowStepDefinition
|
||||
metadata:
|
||||
annotations:
|
||||
definition.oam.dev/description: Send message to webhook
|
||||
name: webhook-notification
|
||||
namespace: {{.Values.systemDefinitionNamespace}}
|
||||
spec:
|
||||
schematic:
|
||||
cue:
|
||||
template: |
|
||||
import (
|
||||
"vela/op"
|
||||
)
|
||||
|
||||
parameter: {
|
||||
dingding?: {
|
||||
url: string
|
||||
message: {
|
||||
text?: *null | {
|
||||
content: string
|
||||
}
|
||||
// +usage=msgType can be text, link, mardown, actionCard, feedCard
|
||||
msgtype: string
|
||||
link?: *null | {
|
||||
text?: string
|
||||
title?: string
|
||||
messageUrl?: string
|
||||
picUrl?: string
|
||||
}
|
||||
markdown?: *null | {
|
||||
text: string
|
||||
title: string
|
||||
}
|
||||
at?: *null | {
|
||||
atMobiles?: *null | [...string]
|
||||
isAtAll?: bool
|
||||
}
|
||||
actionCard?: *null | {
|
||||
text: string
|
||||
title: string
|
||||
hideAvatar: string
|
||||
btnOrientation: string
|
||||
singleTitle: string
|
||||
singleURL: string
|
||||
btns: *null | [...*null | {
|
||||
title: string
|
||||
actionURL: string
|
||||
}]
|
||||
}
|
||||
feedCard?: *null | {
|
||||
links: *null | [...*null | {
|
||||
text?: string
|
||||
title?: string
|
||||
messageUrl?: string
|
||||
picUrl?: string
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
slack?: {
|
||||
url: string
|
||||
message: {
|
||||
text: string
|
||||
blocks?: *null | [...block]
|
||||
attachments?: *null | {
|
||||
blocks?: *null | [...block]
|
||||
color?: string
|
||||
}
|
||||
thread_ts?: string
|
||||
mrkdwn?: *true | bool
|
||||
}
|
||||
}
|
||||
}
|
||||
block: {
|
||||
type: string
|
||||
block_id?: string
|
||||
elements?: [...{
|
||||
type: string
|
||||
action_id?: string
|
||||
url?: string
|
||||
value?: string
|
||||
style?: string
|
||||
text?: text
|
||||
confirm?: {
|
||||
title: text
|
||||
text: text
|
||||
confirm: text
|
||||
deny: text
|
||||
style?: string
|
||||
}
|
||||
options?: [...option]
|
||||
initial_options?: [...option]
|
||||
placeholder?: text
|
||||
initial_date?: string
|
||||
image_url?: string
|
||||
alt_text?: string
|
||||
option_groups?: [...option]
|
||||
max_selected_items?: int
|
||||
initial_value?: string
|
||||
multiline?: bool
|
||||
min_length?: int
|
||||
max_length?: int
|
||||
dispatch_action_config?: trigger_actions_on?: [...string]
|
||||
initial_time?: string
|
||||
}]
|
||||
}
|
||||
text: {
|
||||
type: string
|
||||
text: string
|
||||
emoji?: bool
|
||||
verbatim?: bool
|
||||
}
|
||||
option: {
|
||||
text: text
|
||||
value: string
|
||||
description?: text
|
||||
url?: string
|
||||
}
|
||||
// send webhook notification
|
||||
ding: {
|
||||
if parameter.dingding != _|_ {
|
||||
op.#DingTalk & {
|
||||
message: parameter.dingding.message
|
||||
dingUrl: parameter.dingding.url
|
||||
}
|
||||
}
|
||||
}
|
||||
slack: {
|
||||
if parameter.slack != _|_ {
|
||||
op.#Slack & {
|
||||
message: parameter.slack.message
|
||||
slackUrl: parameter.slack.url
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: Application
|
||||
metadata:
|
||||
name: first-vela-workflow
|
||||
namespace: default
|
||||
spec:
|
||||
components:
|
||||
- name: express-server
|
||||
type: webservice
|
||||
properties:
|
||||
image: crccheck/hello-world
|
||||
port: 8000
|
||||
traits:
|
||||
- type: ingress
|
||||
properties:
|
||||
domain: testsvc.example.com
|
||||
http:
|
||||
/: 8000
|
||||
workflow:
|
||||
steps:
|
||||
- name: notification
|
||||
type: webhook-notification
|
||||
properties:
|
||||
dingding:
|
||||
url: ding url
|
||||
message:
|
||||
msgtype: text
|
||||
text:
|
||||
content: Hello KubeVela
|
||||
slack:
|
||||
url: slack url
|
||||
message:
|
||||
text: Hello KubeVela
|
||||
- name: first-server
|
||||
type: apply-application
|
||||
+17
-5
@@ -93,14 +93,26 @@ import (
|
||||
}
|
||||
|
||||
#DingTalk: #Steps & {
|
||||
message: dingDing.#Message
|
||||
_message: json.Marshal(message)
|
||||
token: string
|
||||
message: dingDing.#DingMessage
|
||||
dingUrl: string
|
||||
do: http.#Do & {
|
||||
method: "POST"
|
||||
url: "https://oapi.dingtalk.com/robot/send?access_token=\(token)"
|
||||
url: dingUrl
|
||||
request: {
|
||||
body: _message
|
||||
body: json.Marshal(message)
|
||||
header: "Content-Type": "application/json"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Slack: #Steps & {
|
||||
message: slack.#SlackMessage
|
||||
slackUrl: string
|
||||
do: http.#Do & {
|
||||
method: "POST"
|
||||
url: slackUrl
|
||||
request: {
|
||||
body: json.Marshal(message)
|
||||
header: "Content-Type": "application/json"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#Message: {
|
||||
#DingMessage: {
|
||||
text?: *null | {
|
||||
content: string
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
#SlackMessage: {
|
||||
text: string
|
||||
blocks?: *null | [...#block]
|
||||
attachments?: *null | {
|
||||
blocks?: *null | [...#block]
|
||||
color?: string
|
||||
}
|
||||
thread_ts?: string
|
||||
mrkdwn?: *true | bool
|
||||
}
|
||||
|
||||
#block: {
|
||||
type: string
|
||||
block_id?: string
|
||||
elements?: [...{
|
||||
type: string
|
||||
action_id?: string
|
||||
url?: string
|
||||
value?: string
|
||||
style?: string
|
||||
text?: #text
|
||||
confirm?: {
|
||||
title: #text
|
||||
text: #text
|
||||
confirm: #text
|
||||
deny: #text
|
||||
style?: string
|
||||
}
|
||||
options?: [...#option]
|
||||
initial_options?: [...#option]
|
||||
placeholder?: #text
|
||||
initial_date?: string
|
||||
image_url?: string
|
||||
alt_text?: string
|
||||
option_groups?: [...#option]
|
||||
max_selected_items?: int
|
||||
initial_value?: string
|
||||
multiline?: bool
|
||||
min_length?: int
|
||||
max_length?: int
|
||||
dispatch_action_config?: {
|
||||
trigger_actions_on?: [...string]
|
||||
}
|
||||
initial_time?: string
|
||||
}]
|
||||
}
|
||||
|
||||
#text: {
|
||||
type: string
|
||||
text: string
|
||||
emoji?: bool
|
||||
verbatim?: bool
|
||||
}
|
||||
|
||||
#option: {
|
||||
text: text
|
||||
value: string
|
||||
description?: text
|
||||
url?: string
|
||||
}
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
import (
|
||||
"vela/op"
|
||||
)
|
||||
|
||||
"dingtalk": {
|
||||
type: "workflow-step"
|
||||
annotations: {}
|
||||
labels: {}
|
||||
description: "Send message with DingTalk robot"
|
||||
}
|
||||
template: {
|
||||
// apply remaining components and traits
|
||||
ding: op.#DingTalk & {
|
||||
parameter
|
||||
}
|
||||
|
||||
parameter: {
|
||||
// +usage=Declare the token of the DingTalk robot
|
||||
token: string
|
||||
message: {
|
||||
text?: *null | {
|
||||
content: string
|
||||
}
|
||||
// +usage=msgType can be text, link, mardown, actionCard, feedCard
|
||||
msgtype: string
|
||||
link?: *null | {
|
||||
text?: string
|
||||
title?: string
|
||||
messageUrl?: string
|
||||
picUrl?: string
|
||||
}
|
||||
markdown?: *null | {
|
||||
text: string
|
||||
title: string
|
||||
}
|
||||
at?: *null | {
|
||||
atMobiles?: *null | [...string]
|
||||
isAtAll?: bool
|
||||
}
|
||||
actionCard?: *null | {
|
||||
text: string
|
||||
title: string
|
||||
hideAvatar: string
|
||||
btnOrientation: string
|
||||
singleTitle: string
|
||||
singleURL: string
|
||||
btns: *null | [...*null | {
|
||||
title: string
|
||||
actionURL: string
|
||||
}]
|
||||
}
|
||||
feedCard?: *null | {
|
||||
links: *null | [...*null | {
|
||||
text?: string
|
||||
title?: string
|
||||
messageUrl?: string
|
||||
picUrl?: string
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
import (
|
||||
"vela/op"
|
||||
)
|
||||
|
||||
"webhook-notification": {
|
||||
type: "workflow-step"
|
||||
annotations: {}
|
||||
labels: {}
|
||||
description: "Send message to webhook"
|
||||
}
|
||||
template: {
|
||||
|
||||
parameter: {
|
||||
dingding?: {
|
||||
url: string
|
||||
message: {
|
||||
text?: *null | {
|
||||
content: string
|
||||
}
|
||||
// +usage=msgType can be text, link, mardown, actionCard, feedCard
|
||||
msgtype: string
|
||||
link?: *null | {
|
||||
text?: string
|
||||
title?: string
|
||||
messageUrl?: string
|
||||
picUrl?: string
|
||||
}
|
||||
markdown?: *null | {
|
||||
text: string
|
||||
title: string
|
||||
}
|
||||
at?: *null | {
|
||||
atMobiles?: *null | [...string]
|
||||
isAtAll?: bool
|
||||
}
|
||||
actionCard?: *null | {
|
||||
text: string
|
||||
title: string
|
||||
hideAvatar: string
|
||||
btnOrientation: string
|
||||
singleTitle: string
|
||||
singleURL: string
|
||||
btns: *null | [...*null | {
|
||||
title: string
|
||||
actionURL: string
|
||||
}]
|
||||
}
|
||||
feedCard?: *null | {
|
||||
links: *null | [...*null | {
|
||||
text?: string
|
||||
title?: string
|
||||
messageUrl?: string
|
||||
picUrl?: string
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
slack?: {
|
||||
url: string
|
||||
message: {
|
||||
text: string
|
||||
blocks?: *null | [...block]
|
||||
attachments?: *null | {
|
||||
blocks?: *null | [...block]
|
||||
color?: string
|
||||
}
|
||||
thread_ts?: string
|
||||
mrkdwn?: *true | bool
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
block: {
|
||||
type: string
|
||||
block_id?: string
|
||||
elements?: [...{
|
||||
type: string
|
||||
action_id?: string
|
||||
url?: string
|
||||
value?: string
|
||||
style?: string
|
||||
text?: text
|
||||
confirm?: {
|
||||
title: text
|
||||
text: text
|
||||
confirm: text
|
||||
deny: text
|
||||
style?: string
|
||||
}
|
||||
options?: [...option]
|
||||
initial_options?: [...option]
|
||||
placeholder?: text
|
||||
initial_date?: string
|
||||
image_url?: string
|
||||
alt_text?: string
|
||||
option_groups?: [...option]
|
||||
max_selected_items?: int
|
||||
initial_value?: string
|
||||
multiline?: bool
|
||||
min_length?: int
|
||||
max_length?: int
|
||||
dispatch_action_config?: {
|
||||
trigger_actions_on?: [...string]
|
||||
}
|
||||
initial_time?: string
|
||||
}]
|
||||
}
|
||||
|
||||
text: {
|
||||
type: string
|
||||
text: string
|
||||
emoji?: bool
|
||||
verbatim?: bool
|
||||
}
|
||||
|
||||
option: {
|
||||
text: text
|
||||
value: string
|
||||
description?: text
|
||||
url?: string
|
||||
}
|
||||
|
||||
// send webhook notification
|
||||
ding: {
|
||||
if parameter.dingding != _|_ {
|
||||
op.#DingTalk & {
|
||||
message: parameter.dingding.message
|
||||
dingUrl: parameter.dingding.url
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
slack: {
|
||||
if parameter.slack != _|_ {
|
||||
op.#Slack & {
|
||||
message: parameter.slack.message
|
||||
slackUrl: parameter.slack.url
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user