Mercurial > prosody-modules
annotate mod_rest/example/app.py @ 3854:25c34c9f755c
mod_rest: Add mapping of XEP-0092: Software Version
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 25 Jan 2020 00:40:38 +0100 |
parents | fb29d7cd698b |
children | ede3d1724dd1 |
rev | line source |
---|---|
3853 | 1 from flask import Flask, Response, request, jsonify |
2 | |
3 app = Flask("echobot") | |
4 | |
5 | |
6 @app.route("/api", methods=["POST"]) | |
7 def hello(): | |
8 print(request.data) | |
9 if request.is_json: | |
10 data = request.get_json() | |
11 | |
12 if "kind" not in data: | |
13 return Response(status=400) | |
14 | |
15 if data["kind"] == "message" and "body" in data: | |
16 return jsonify({"body": "Yes this is flask app"}) | |
17 | |
18 elif data["kind"] == "iq" and data["type"] == "get": | |
19 if "ping" in data: | |
20 return Response(status=204) | |
21 | |
22 elif "disco" in data: | |
23 return jsonify( | |
24 { | |
25 "disco": { | |
26 "identities": [ | |
27 { | |
28 "category": "component", | |
29 "type": "generic", | |
30 "name": "Flask app", | |
31 } | |
32 ], | |
33 "features": [ | |
34 "http://jabber.org/protocol/disco#info", | |
35 "http://jabber.org/protocol/disco#items", | |
36 "urn:xmpp:ping", | |
37 ], | |
38 } | |
39 } | |
40 ) | |
41 | |
42 elif "items" in data: | |
43 return jsonify( | |
44 {"items": [{"jid": "example.org", "name": "Example Dot Org"}]} | |
45 ) | |
46 | |
3854
25c34c9f755c
mod_rest: Add mapping of XEP-0092: Software Version
Kim Alvefur <zash@zash.se>
parents:
3853
diff
changeset
|
47 elif "version" in data: |
25c34c9f755c
mod_rest: Add mapping of XEP-0092: Software Version
Kim Alvefur <zash@zash.se>
parents:
3853
diff
changeset
|
48 return jsonify({"version": {"name": "app.py", "version": "0"}}) |
25c34c9f755c
mod_rest: Add mapping of XEP-0092: Software Version
Kim Alvefur <zash@zash.se>
parents:
3853
diff
changeset
|
49 |
3853 | 50 return Response(status=501) |
51 | |
52 | |
53 if __name__ == "__main__": | |
54 app.run() |