Mercurial > prosody-modules
view mod_rest/example/app.py @ 3955:017f60608fc8
mod_smacks: also count outgoing MAM messages
mod_smacks doesn't count outgoing MAM messages, which causes warnings in Prosody such as:
> The client says it handled 41 new stanzas, but we only sent 2
It seems mod_smacks is in the wrong here and that it's too strict in trying to determine what is a valid stanza to count.
In RFC6120:
> Definition of XML Stanza: An XML stanza is the basic unit of meaning
> in XMPP. A stanza is a first-level element (at depth=1 of the stream)
> whose element name is "message", "presence", or "iq" and whose
> qualifying namespace is 'jabber:client' or 'jabber:server'.
author | JC Brand <jc@opkode.com> |
---|---|
date | Thu, 26 Mar 2020 11:57:02 +0100 |
parents | 45b04f05d624 |
children | 53ae1df31950 |
line wrap: on
line source
from flask import Flask, Response, request, jsonify app = Flask("echobot") @app.route("/api", methods=["OPTIONS"]) def options(): """ Startup check. Return an appropriate Accept header to confirm the data type to use. """ return Response(status=200, headers={"accept": "application/json"}) @app.route("/api", methods=["POST"]) def hello(): """ Example RESTful JSON format stanza handler. """ print(request.data) if request.is_json: data = request.get_json() if "kind" not in data: return Response(status=400) if data["kind"] == "message" and "body" in data: # Reply to a message return jsonify({"body": "Yes this is flask app"}) elif data["kind"] == "iq" and data["type"] == "get": if "ping" in data: # Respond to ping return Response(status=204) elif "disco" in data: # Return supported features return jsonify( { "disco": { "identities": [ { "category": "component", "type": "generic", "name": "Flask app", } ], "features": [ "http://jabber.org/protocol/disco#info", "http://jabber.org/protocol/disco#items", "urn:xmpp:ping", ], } } ) elif "items" in data: # Disco items return jsonify( {"items": [{"jid": "example.org", "name": "Example Dot Org"}]} ) elif "version" in data: # Version info return jsonify({"version": {"name": "app.py", "version": "0"}}) return Response(status=501) if __name__ == "__main__": app.run()