mirror of
https://github.com/langgenius/dify.git
synced 2026-05-03 08:58:09 +08:00
feat: when add/delete webhook trigger call the API (#24755)
This commit is contained in:
@ -94,6 +94,7 @@ const Panel: FC<NodePanelProps<WebhookTriggerNodeType>> = ({
|
||||
</div>
|
||||
</div>
|
||||
</Field>
|
||||
<span>{inputs.webhook_debug_url || ''}</span>
|
||||
|
||||
<Split />
|
||||
|
||||
|
||||
@ -19,6 +19,7 @@ export type WebhookHeader = {
|
||||
|
||||
export type WebhookTriggerNodeType = CommonNodeType & {
|
||||
'webhook_url'?: string
|
||||
'webhook_debug_url'?: string
|
||||
'method': HttpMethod
|
||||
'content-type': string
|
||||
'headers': WebhookHeader[]
|
||||
|
||||
@ -76,43 +76,29 @@ const useConfig = (id: string, payload: WebhookTriggerNodeType) => {
|
||||
const generateWebhookUrl = useCallback(async () => {
|
||||
// Idempotency: if we already have a URL, just return it.
|
||||
if (inputs.webhook_url && inputs.webhook_url.length > 0)
|
||||
return inputs.webhook_url
|
||||
return
|
||||
|
||||
// Helper to build a deterministic mock URL for local/dev usage.
|
||||
const buildMockUrl = () => `https://mock.dify.local/webhook/${appId ?? 'app'}/${id}`
|
||||
|
||||
if (!appId) {
|
||||
// No appId available yet (e.g. during creation): use mock URL.
|
||||
const mockUrl = buildMockUrl()
|
||||
const newInputs = produce(inputs, (draft) => {
|
||||
draft.webhook_url = mockUrl
|
||||
})
|
||||
setInputs(newInputs)
|
||||
return mockUrl
|
||||
}
|
||||
if (!appId)
|
||||
return
|
||||
|
||||
try {
|
||||
// Call backend to generate or fetch webhook url for this node
|
||||
const response = await fetchWebhookUrl({ appId, nodeId: id })
|
||||
const url = response.serverUrl
|
||||
|
||||
const newInputs = produce(inputs, (draft) => {
|
||||
draft.webhook_url = url
|
||||
draft.webhook_url = response.webhook_url
|
||||
draft.webhook_debug_url = response.webhook_debug_url
|
||||
})
|
||||
setInputs(newInputs)
|
||||
|
||||
return url
|
||||
}
|
||||
catch (error: unknown) {
|
||||
// Fallback to mock URL when API is not ready or request fails
|
||||
// Keep the UI unblocked and allow users to proceed in local/dev environments.
|
||||
console.error('Failed to generate webhook URL:', error)
|
||||
const mockUrl = buildMockUrl()
|
||||
const newInputs = produce(inputs, (draft) => {
|
||||
draft.webhook_url = mockUrl
|
||||
draft.webhook_url = ''
|
||||
})
|
||||
setInputs(newInputs)
|
||||
return mockUrl
|
||||
}
|
||||
}, [appId, id, inputs, setInputs])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user