github.com/oam-dev/kubevela@v1.9.11/vela-templates/definitions/internal/workflowstep/notification.cue (about)

     1  import (
     2  	"vela/op"
     3  	"encoding/base64"
     4  )
     5  
     6  "notification": {
     7  	type: "workflow-step"
     8  	annotations: {
     9  		"category": "External Integration"
    10  	}
    11  	labels: {}
    12  	description: "Send notifications to Email, DingTalk, Slack, Lark or webhook in your workflow."
    13  }
    14  template: {
    15  
    16  	parameter: {
    17  		// +usage=Please fulfill its url and message if you want to send Lark messages
    18  		lark?: {
    19  			// +usage=Specify the the lark url, you can either sepcify it in value or use secretRef
    20  			url: close({
    21  				// +usage=the url address content in string
    22  				value: string
    23  			}) | close({
    24  				secretRef: {
    25  					// +usage=name is the name of the secret
    26  					name: string
    27  					// +usage=key is the key in the secret
    28  					key: string
    29  				}
    30  			})
    31  			// +usage=Specify the message that you want to sent, refer to [Lark messaging](https://open.feishu.cn/document/ukTMukTMukTM/ucTM5YjL3ETO24yNxkjN#8b0f2a1b).
    32  			message: {
    33  				// +usage=msg_type can be text, post, image, interactive, share_chat, share_user, audio, media, file, sticker
    34  				msg_type: string
    35  				// +usage=content should be json encode string
    36  				content: string
    37  			}
    38  		}
    39  		// +usage=Please fulfill its url and message if you want to send DingTalk messages
    40  		dingding?: {
    41  			// +usage=Specify the the dingding url, you can either sepcify it in value or use secretRef
    42  			url: close({
    43  				// +usage=the url address content in string
    44  				value: string
    45  			}) | close({
    46  				secretRef: {
    47  					// +usage=name is the name of the secret
    48  					name: string
    49  					// +usage=key is the key in the secret
    50  					key: string
    51  				}
    52  			})
    53  			// +usage=Specify the message that you want to sent, refer to [dingtalk messaging](https://developers.dingtalk.com/document/robots/custom-robot-access/title-72m-8ag-pqw)
    54  			message: {
    55  				// +usage=Specify the message content of dingtalk notification
    56  				text?: close({
    57  					content: string
    58  				})
    59  				// +usage=msgType can be text, link, mardown, actionCard, feedCard
    60  				msgtype: *"text" | "link" | "markdown" | "actionCard" | "feedCard"
    61  				#link: {
    62  					text?:       string
    63  					title?:      string
    64  					messageUrl?: string
    65  					picUrl?:     string
    66  				}
    67  
    68  				link?:     #link
    69  				markdown?: close({
    70  					text:  string
    71  					title: string
    72  				})
    73  				at?: close({
    74  					atMobiles?: [...string]
    75  					isAtAll?: bool
    76  				})
    77  				actionCard?: close({
    78  					text:           string
    79  					title:          string
    80  					hideAvatar:     string
    81  					btnOrientation: string
    82  					singleTitle:    string
    83  					singleURL:      string
    84  					btns?: [...close({
    85  						title:     string
    86  						actionURL: string
    87  					})]
    88  				})
    89  				feedCard?: close({
    90  					links: [...#link]
    91  				})
    92  			}
    93  		}
    94  		// +usage=Please fulfill its url and message if you want to send Slack messages
    95  		slack?: {
    96  			// +usage=Specify the the slack url, you can either sepcify it in value or use secretRef
    97  			url: close({
    98  				// +usage=the url address content in string
    99  				value: string
   100  			}) | close({
   101  				secretRef: {
   102  					// +usage=name is the name of the secret
   103  					name: string
   104  					// +usage=key is the key in the secret
   105  					key: string
   106  				}
   107  			})
   108  			// +usage=Specify the message that you want to sent, refer to [slack messaging](https://api.slack.com/reference/messaging/payload)
   109  			message: {
   110  				// +usage=Specify the message text for slack notification
   111  				text: string
   112  				blocks?: [...block]
   113  				attachments?: close({
   114  					blocks?: [...block]
   115  					color?: string
   116  				})
   117  				thread_ts?: string
   118  				// +usage=Specify the message text format in markdown for slack notification
   119  				mrkdwn?: *true | bool
   120  			}
   121  		}
   122  		// +usage=Please fulfill its from, to and content if you want to send email
   123  		email?: {
   124  			// +usage=Specify the email info that you want to send from
   125  			from: {
   126  				// +usage=Specify the email address that you want to send from
   127  				address: string
   128  				// +usage=The alias is the email alias to show after sending the email
   129  				alias?: string
   130  				// +usage=Specify the password of the email, you can either sepcify it in value or use secretRef
   131  				password: close({
   132  					// +usage=the password content in string
   133  					value: string
   134  				}) | close({
   135  					secretRef: {
   136  						// +usage=name is the name of the secret
   137  						name: string
   138  						// +usage=key is the key in the secret
   139  						key: string
   140  					}
   141  				})
   142  				// +usage=Specify the host of your email
   143  				host: string
   144  				// +usage=Specify the port of the email host, default to 587
   145  				port: *587 | int
   146  			}
   147  			// +usage=Specify the email address that you want to send to
   148  			to: [...string]
   149  			// +usage=Specify the content of the email
   150  			content: {
   151  				// +usage=Specify the subject of the email
   152  				subject: string
   153  				// +usage=Specify the context body of the email
   154  				body: string
   155  			}
   156  		}
   157  	}
   158  
   159  	block: {
   160  		type:      string
   161  		block_id?: string
   162  		elements?: [...{
   163  			type:       string
   164  			action_id?: string
   165  			url?:       string
   166  			value?:     string
   167  			style?:     string
   168  			text?:      textType
   169  			confirm?: {
   170  				title:   textType
   171  				text:    textType
   172  				confirm: textType
   173  				deny:    textType
   174  				style?:  string
   175  			}
   176  			options?: [...option]
   177  			initial_options?: [...option]
   178  			placeholder?:  textType
   179  			initial_date?: string
   180  			image_url?:    string
   181  			alt_text?:     string
   182  			option_groups?: [...option]
   183  			max_selected_items?: int
   184  			initial_value?:      string
   185  			multiline?:          bool
   186  			min_length?:         int
   187  			max_length?:         int
   188  			dispatch_action_config?: {
   189  				trigger_actions_on?: [...string]
   190  			}
   191  			initial_time?: string
   192  		}]
   193  	}
   194  
   195  	textType: {
   196  		type:      string
   197  		text:      string
   198  		emoji?:    bool
   199  		verbatim?: bool
   200  	}
   201  
   202  	option: {
   203  		text:         textType
   204  		value:        string
   205  		description?: textType
   206  		url?:         string
   207  	}
   208  
   209  	// send webhook notification
   210  	ding: op.#Steps & {
   211  		if parameter.dingding != _|_ {
   212  			if parameter.dingding.url.value != _|_ {
   213  				ding1: op.#DingTalk & {
   214  					message: parameter.dingding.message
   215  					dingUrl: parameter.dingding.url.value
   216  				}
   217  			}
   218  			if parameter.dingding.url.secretRef != _|_ && parameter.dingding.url.value == _|_ {
   219  				read: op.#Read & {
   220  					value: {
   221  						apiVersion: "v1"
   222  						kind:       "Secret"
   223  						metadata: {
   224  							name:      parameter.dingding.url.secretRef.name
   225  							namespace: context.namespace
   226  						}
   227  					}
   228  				}
   229  
   230  				stringValue: op.#ConvertString & {bt: base64.Decode(null, read.value.data[parameter.dingding.url.secretRef.key])}
   231  				ding2:       op.#DingTalk & {
   232  					message: parameter.dingding.message
   233  					dingUrl: stringValue.str
   234  				}
   235  			}
   236  		}
   237  	}
   238  
   239  	lark: op.#Steps & {
   240  		if parameter.lark != _|_ {
   241  			if parameter.lark.url.value != _|_ {
   242  				lark1: op.#Lark & {
   243  					message: parameter.lark.message
   244  					larkUrl: parameter.lark.url.value
   245  				}
   246  			}
   247  			if parameter.lark.url.secretRef != _|_ && parameter.lark.url.value == _|_ {
   248  				read: op.#Read & {
   249  					value: {
   250  						apiVersion: "v1"
   251  						kind:       "Secret"
   252  						metadata: {
   253  							name:      parameter.lark.url.secretRef.name
   254  							namespace: context.namespace
   255  						}
   256  					}
   257  				}
   258  
   259  				stringValue: op.#ConvertString & {bt: base64.Decode(null, read.value.data[parameter.lark.url.secretRef.key])}
   260  				lark2:       op.#Lark & {
   261  					message: parameter.lark.message
   262  					larkUrl: stringValue.str
   263  				}
   264  			}
   265  		}
   266  	}
   267  
   268  	slack: op.#Steps & {
   269  		if parameter.slack != _|_ {
   270  			if parameter.slack.url.value != _|_ {
   271  				slack1: op.#Slack & {
   272  					message:  parameter.slack.message
   273  					slackUrl: parameter.slack.url.value
   274  				}
   275  			}
   276  			if parameter.slack.url.secretRef != _|_ && parameter.slack.url.value == _|_ {
   277  				read: op.#Read & {
   278  					value: {
   279  						kind:       "Secret"
   280  						apiVersion: "v1"
   281  						metadata: {
   282  							name:      parameter.slack.url.secretRef.name
   283  							namespace: context.namespace
   284  						}
   285  					}
   286  				}
   287  
   288  				stringValue: op.#ConvertString & {bt: base64.Decode(null, read.value.data[parameter.slack.url.secretRef.key])}
   289  				slack2:      op.#Slack & {
   290  					message:  parameter.slack.message
   291  					slackUrl: stringValue.str
   292  				}
   293  			}
   294  		}
   295  	}
   296  
   297  	email: op.#Steps & {
   298  		if parameter.email != _|_ {
   299  			if parameter.email.from.password.value != _|_ {
   300  				email1: op.#SendEmail & {
   301  					from: {
   302  						address: parameter.email.from.address
   303  						if parameter.email.from.alias != _|_ {
   304  							alias: parameter.email.from.alias
   305  						}
   306  						password: parameter.email.from.password.value
   307  						host:     parameter.email.from.host
   308  						port:     parameter.email.from.port
   309  					}
   310  					to:      parameter.email.to
   311  					content: parameter.email.content
   312  				}
   313  			}
   314  
   315  			if parameter.email.from.password.secretRef != _|_ && parameter.email.from.password.value == _|_ {
   316  				read: op.#Read & {
   317  					value: {
   318  						kind:       "Secret"
   319  						apiVersion: "v1"
   320  						metadata: {
   321  							name:      parameter.email.from.password.secretRef.name
   322  							namespace: context.namespace
   323  						}
   324  					}
   325  				}
   326  
   327  				stringValue: op.#ConvertString & {bt: base64.Decode(null, read.value.data[parameter.email.from.password.secretRef.key])}
   328  				email2:      op.#SendEmail & {
   329  					from: {
   330  						address: parameter.email.from.address
   331  						if parameter.email.from.alias != _|_ {
   332  							alias: parameter.email.from.alias
   333  						}
   334  						password: stringValue.str
   335  						host:     parameter.email.from.host
   336  						port:     parameter.email.from.port
   337  					}
   338  					to:      parameter.email.to
   339  					content: parameter.email.content
   340  				}
   341  			}
   342  		}
   343  	}
   344  }