webhook_notify.lua

 1-- webhook_notify.lua
 2-- Posts a JSON payload to a webhook URL when an email is received.
 3
 4local matcha = require("matcha")
 5
 6local WEBHOOK_URL = "https://example.com/webhook"
 7
 8matcha.on("email_received", function(email)
 9    local payload = '{"from":"' .. email.from .. '","subject":"' .. email.subject .. '"}'
10
11    local res, err = matcha.http({
12        url = WEBHOOK_URL,
13        method = "POST",
14        headers = { ["Content-Type"] = "application/json" },
15        body = payload,
16    })
17
18    if err then
19        matcha.log("webhook error: " .. err)
20        return
21    end
22
23    if res.status >= 400 then
24        matcha.log("webhook returned status " .. res.status)
25    end
26end)