Software /
code /
prosody-modules
Comparison
mod_post_msg/mod_post_msg.lua @ 2989:926aaaeb0d21
mod_post_msg: Add support for a JSON based format similar to what mod_component_http uses
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 04 Apr 2018 15:55:09 +0200 |
parent | 1418:a0375f84d65a |
comparison
equal
deleted
inserted
replaced
2988:3cc78e6a8758 | 2989:926aaaeb0d21 |
---|---|
5 local msg = require "util.stanza".message; | 5 local msg = require "util.stanza".message; |
6 local test_password = require "core.usermanager".test_password; | 6 local test_password = require "core.usermanager".test_password; |
7 local b64_decode = require "util.encodings".base64.decode; | 7 local b64_decode = require "util.encodings".base64.decode; |
8 local formdecode = require "net.http".formdecode; | 8 local formdecode = require "net.http".formdecode; |
9 local xml = require"util.xml"; | 9 local xml = require"util.xml"; |
10 local json = require "util.json"; | |
10 | 11 |
11 local function require_valid_user(f) | 12 local function require_valid_user(f) |
12 return function(event, path) | 13 return function(event, path) |
13 local request = event.request; | 14 local request = event.request; |
14 local response = event.response; | 15 local response = event.response; |
55 module:log("warn", "mod_post_msg: invalid XML: %s", err); | 56 module:log("warn", "mod_post_msg: invalid XML: %s", err); |
56 return 400; | 57 return 400; |
57 end | 58 end |
58 message:tag("html", {xmlns="http://jabber.org/protocol/xhtml-im"}):add_child(html):up(); | 59 message:tag("html", {xmlns="http://jabber.org/protocol/xhtml-im"}):add_child(html):up(); |
59 end | 60 end |
61 elseif body_type == "application/json" then | |
62 local post_body = json.decode(request.body); | |
63 if not post_body then return 400; end | |
64 message = msg({ to = post_body.to or to, from = authed_user, | |
65 type = post_body.type or "chat"}, post_body.body); | |
60 else | 66 else |
61 return 415; | 67 return 415; |
62 end | 68 end |
63 if message and message.attr.to then | 69 if message and message.attr.to then |
64 module:log("debug", "Sending %s", tostring(message)); | 70 module:log("debug", "Sending %s", tostring(message)); |