diff --git a/Lua-Examples.md b/Lua-Examples.md index ebf3a21..47d86b1 100644 --- a/Lua-Examples.md +++ b/Lua-Examples.md @@ -2,8 +2,9 @@ By default Inbucket will load `inbucket.lua`, but you may use the `INBUCKET_LUA_ ## Event trigger: after message stored +Prints metadata of stored messages to STDOUT. + ```lua --- Prints metadata of stored messages to STDOUT. function inbucket.after.message_stored(msg) print("\n## message_stored ##") @@ -19,4 +20,25 @@ function inbucket.after.message_stored(msg) print(string.format("date: %s", os.date("%c", msg.date))) print(string.format("subject: %s", msg.subject)) end +``` + +Makes a JSON encoded POST to a web service. + +```lua +local http = require("http") +local json = require("json") + +BASE_URL = "https://myapi.example.com" + +function inbucket.after.message_stored(msg) + local request = json.encode { + subject = string.format("Mail from %q", msg.from.address), + body = msg.subject + } + + assert(http.post(BASE_URL .. "/notify/text", { + headers = { ["Content-Type"] = "application/json" }, + body = request, + })) +end ``` \ No newline at end of file