2023年9月23日 星期六

Line Notify API Webhook 實驗

 本實驗是使用 https://github.com/adnanh/webhook 提供現成的 webhook  程式而來.

因為是直接使用在 AlmaLinux release 9.2 (Turquoise Kodkod)


所需撰寫檔案可參考如下:

[root@AlmaLinux92 webhook-linux-amd64]# pwd
/root/webhook-linux-amd64
[root@AlmaLinux92 webhook-linux-amd64]# ll
total 10352
-rw-r--r-- 1 root root      789 Sep 23 13:55 hooks.json
-rwxrwxr-x 1 1001 1001 10593221 May 23 03:06 webhook
[root@AlmaLinux92 webhook-linux-amd64]# cat hooks.json 
[
  {
    "id": "simple",
    "execute-command": "/tmp/app.sh",
    "include-command-output-in-response":true,
    "include-command-output-in-response-on-error":true,
    "command-working-directory":"/tmp",
    "pass-arguments-to-command":,
    "pass-environment-to-command":
   [
    {
     "envname": "TOKEN",
     "source": "url",
     "name": "token"
    },
    {
     "envname": "SUBJECT",
     "source": "payload",
     "name": "subject"
    },
    {
     "envname": "BODY",
     "source": "payload",
     "name": "body"
    }

   ],
    "trigger-rule":
    {
      "match":
      {
        "type": "value",
        "value": "qhkv2x54TXXXXXXXXXXXXXXXXXXXXXXXXXXXXP1N6",
        "parameter":
       {
         "source": "url",
         "name": "token"
       }
      }
    }
  }
[root@AlmaLinux92 webhook-linux-amd64]# 




[root@AlmaLinux92 tmp]# cat /tmp/app.sh 
#!/bin/bash

curl -X POST -H  "Authorization: Bearer $TOKEN" -F "message= $SUBJECT ---- $BODY" https://notify-api.line.me/api/notify

echo "$BODY" | mailx -r "WEBHOOK <webhook@simple.com>" -s "$SUBJECT" root


[root@AlmaLinux92 tmp]# 


執行方式

[root@AlmaLinux92 webhook-linux-amd64]# ./webhook -hooks hooks.json -verbose


測試方法

#curl -X POST   -H "Content-Type: application/json" \
'http://localhost:9000/hooks/simple?token=qhkv2x54TXXXXXXXXXXXXXXXP1N6'  \
-d '{"subject":"Test from AlmaLinux WEBHOOK Subject","body":"Test from AlmaLinux  WEBHOOK Body"}'


程式執行畫面






測試執行畫面






實驗結果





沒有留言:

張貼留言