9
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Difyのトリガーを使ってイベント駆動なワークフローを試してみた

Last updated at Posted at 2025-11-01

1. はじめに

Dify v1.10.0-rc1にてトリガー機能が追加されました。まだrcではありますが、Difyの可能性が広がる機能なので早速テストしてみました。

現状、トリガーとしては以下の2つが利用できるようなので、Webhookを試してみます。

image.png

Webhookでは以下の3つのパターンで受付可能なようです。

  • Query Parameters
    • URLで指定する
    • 例: curl "https://api.example.com/items?user_id={{user_id}}&limit=50"
  • Header Parameters
    • HTTPヘッダで指定する
    • 例: curl -H "Authorization: Bearer {{api_key}}" -H "X-Signature: {{hmac_signature}}" https://api.example.com/secure
  • Request Body Parameters
    • リクエスト本文のパラメーター
    • 例: curl -X POST https://api.example.com/events -H "Content-Type: application/json" -d '{ "user_id": "{{user_id}}", "action": "purchase", "items": {{items_json}} }'

今回はRequest Body Parametersで試してみます。

2. やりたいこと

テストとして以下のようなものを想定しました。
アプリでエラーが発生したとして、それをDifyに送りLLMが要約と対策を考え、Slackに投稿する、っというものです。

image.png

3. 検証開始!

3-1. curlでリクエスト送信のスクリプトを作成する

動作確認なので、ここではcurlを使ってリクエストを送ります。
メインはerror_messageの情報ですが、それに関連する情報としていくつかの変数も設定しました。

trigger-hpc.sh
#!/bin/sh

curl -X POST "http://localhost/triggers/webhook/HZcDjWAioBt7DyTP2pHupJM2" \
  -H "Content-Type: application/json" \
  -d '{
    "event": "slurm.job_failed",
    "job_id": 123456,
    "node": "cn002",
    "ts": "2025-11-01T12:00:00+09:00",
    "error_message": "NCCL WARN NET/IB: RDMA connect error Connection timed out\nncclCommWatchdog: comm 0x7f8c... failed: unhandled system error\nslurmstepd: error: Detected 1 oom-kill event(s) in step 123456.batch cgroup."
  }'

3-2. Difyワークフローの作成

至ってシンプルで、以下3つのブロックで構成しました。
image.png

3-3. Webhookトリガーブロック

curlコマンドの内容に合わせてRequest Body Parametersを設定します。
image.png

3-4. LLMブロック

Webhookトリガーブロックで受け付けた変数とともにプロンプトを設定します。
image.png

3-5. Slackブロック

SlackプラグインにてcontentにLLMの出力変数を設定します。
image.png

4. 動作確認

テスト実行をクリックする。
image.png

以下のようにトリガーからのイベントを待機中...となります。
image.png

準備したcurlスクリプトを実行します。正常に動作すればsuccessと返ってきます。

$ ./trigger-hpc.sh
{"status":"success","message":"Webhook processed successfully"}

少し待つとSlackに通知が来います。
LLMブロックのSystemプロンプトにより処理された内容であることが確認できます。
image.png

5. 最後に

Difyにトリガー機能がリリースされたのでシンプルな動作確認を行い、無事に動作することが確認できました。
実はかなり久しぶりにDifyを触ったのですが、このような新機能でも1時間ほど考えて手を動かして実現できてしまうのはDifyの魅力だなと改めて思いました。

9
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?