0
0

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でLINEプラグインを使わずWebhookトリガーでLINE Botを作ってみた

Last updated at Posted at 2025-12-25

Webhookトリガーが使えるようになったので外部のプラグインを使わずにLINE Botのリプライが作れそうですね。

こんな感じでトリガーと適当なノードを用意してまずはテストランをします。

CleanShot 2025-12-25 at 12.36.11.png

ページ下部の変数検査_webhook_rowというキーが表示されているので、こちらをみてみます。

CleanShot 2025-12-25 at 13.39.53.png

以下は省略版。

bodyの中を見ると良さそうですね。

{
//省略

  "body": {
    "destination": "U123e6ec1fe70658b2de7f8d1d1823006",
    "events": [
      {
        "type": "message",
        "message": {
          "type": "text",
          "id": "593588425774071895",
          "quoteToken": "LRkHUlHjkhgbk...",
          "markAsReadToken": "Xmr5b6J8kB1Yy1IHJhholXbJKESJLcDsvSNb...",
          "text": "aaa"
        },
        "webhookEventId": "01KD9WW8YQ8ZBGGE00H1XPE05D",
        "deliveryContext": {
          "isRedelivery": false
        },
        "timestamp": 1766637576666,
        "source": {
          "type": "user",
          "userId": "Ud267f...."
        },
        "replyToken": "740258f39e7e48a2b0199f3a8ef3927a",
        "mode": "active"
      }
    ]
  },
  "files": {}
}

シンプルなリプライを作ってみる

環境変数にトークンを入れておく

今回の例だと署名検証してないのでアクセストークンだけでOKですがシークレットとアクセストークン両方セットしておきました。

CleanShot 2025-12-25 at 12.55.54.png

CleanShot 2025-12-25 at 12.56.31.png

変数の処理

コード実行でreplyTokenとユーザーから送られてきたメッセージを取得します。

function main({webhook_row}) {
    const webhook_body = webhook_row.body;
    const event = webhook_body.events[0];

    return {
        webhook_body: webhook_body,
        replay_token: event.replyToken,
        userMessage: event.message.text
    }
}

設定はこんな感じ

CleanShot 2025-12-25 at 13.42.54.png

HTTPノードでリプライをする

  • APIエンドポイント: https://api.line.me/v2/bot/message/reply
  • ヘッダー
    • Authorization: Bearer
    • Content-Type: application/json

CleanShot 2025-12-25 at 13.43.44.png

リクエスト本体はJSONを指定して以下のよう(画面スクショも参照)に書きます。

{
"replyToken": "{{#1766636742410.replay_token#}}",
 "messages":  [{
        type: 'text',
        text: "{{#1766636742410.userMessage#}}"
  }]
}

おうむ返し

これで無事におうむ返しができました。

CleanShot 2025-12-25 at 13.47.32.png

公開時とテスト時でWebhookのURLを変更

  • 公開時のトリガーURL: https://trigger.ai-plugin.io/triggers/webhook/~~~~~
  • テスト時のトリガーURL: https://trigger.ai-plugin.io/triggers/webhook-debug/~~~~~

CleanShot 2025-12-25 at 14.07.14.png

という形でURLが分かれてるので最後に公開する際には公開時のURLに切り替えましょう。

CleanShot 2025-12-25 at 14.13.57.png

所感

変数検証の機能が便利ですね...!

CleanShot 2025-12-25 at 14.06.36.png

HTTPリクエスト後んbodyの中身などもみれてデバッグがやりやすくなりました。

CleanShot 2025-12-25 at 14.21.07.png

DSLはこちらに置いておきます。

https://gist.githubusercontent.com/n0bisuke/f401e969559b8e27034d0eb55efc95e1/raw/1dfe2bd83e8f703968e2171d6c3e038cb8c9b758/line-dify-reply.yml

署名検証はトライしたけどちょっと厳しそうだったのでその話はまた別記事で。

とはいえWebhookトリガー便利!色々なサービスと繋げられそうな雰囲気です。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?