mirror of
https://github.com/langgenius/dify.git
synced 2025-11-19 14:33:13 +00:00
Signed-off-by: lyzno1 <yuanyouhuilyz@gmail.com> Co-authored-by: Stream <Stream_2@qq.com> Co-authored-by: lyzno1 <92089059+lyzno1@users.noreply.github.com> Co-authored-by: zhsama <torvalds@linux.do> Co-authored-by: Harry <xh001x@hotmail.com> Co-authored-by: lyzno1 <yuanyouhuilyz@gmail.com> Co-authored-by: yessenia <yessenia.contact@gmail.com> Co-authored-by: hjlarry <hjlarry@163.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: WTW0313 <twwu@dify.ai> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
65 lines
1.7 KiB
TypeScript
65 lines
1.7 KiB
TypeScript
import { BlockEnum } from '../../types'
|
|
import type { NodeDefault } from '../../types'
|
|
import { genNodeMetaData } from '../../utils'
|
|
import type { WebhookTriggerNodeType } from './types'
|
|
import { isValidParameterType } from './utils/parameter-type-utils'
|
|
import { createWebhookRawVariable } from './utils/raw-variable'
|
|
|
|
const metaData = genNodeMetaData({
|
|
sort: 3,
|
|
type: BlockEnum.TriggerWebhook,
|
|
helpLinkUri: 'webhook-trigger',
|
|
isStart: true,
|
|
})
|
|
|
|
const nodeDefault: NodeDefault<WebhookTriggerNodeType> = {
|
|
metaData,
|
|
defaultValue: {
|
|
webhook_url: '',
|
|
method: 'POST',
|
|
content_type: 'application/json',
|
|
headers: [],
|
|
params: [],
|
|
body: [],
|
|
async_mode: true,
|
|
status_code: 200,
|
|
response_body: '',
|
|
variables: [createWebhookRawVariable()],
|
|
},
|
|
checkValid(payload: WebhookTriggerNodeType, t: any) {
|
|
// Require webhook_url to be configured
|
|
if (!payload.webhook_url || payload.webhook_url.trim() === '') {
|
|
return {
|
|
isValid: false,
|
|
errorMessage: t('workflow.nodes.triggerWebhook.validation.webhookUrlRequired'),
|
|
}
|
|
}
|
|
|
|
// Validate parameter types for params and body
|
|
const parametersWithTypes = [
|
|
...(payload.params || []),
|
|
...(payload.body || []),
|
|
]
|
|
|
|
for (const param of parametersWithTypes) {
|
|
// Validate parameter type is valid
|
|
if (!isValidParameterType(param.type)) {
|
|
return {
|
|
isValid: false,
|
|
errorMessage: t('workflow.nodes.triggerWebhook.validation.invalidParameterType', {
|
|
name: param.name,
|
|
type: param.type,
|
|
}),
|
|
}
|
|
}
|
|
}
|
|
|
|
return {
|
|
isValid: true,
|
|
errorMessage: '',
|
|
}
|
|
},
|
|
}
|
|
|
|
export default nodeDefault
|