Software /
code /
prosody-modules
Comparison
mod_rest/example/app.py @ 3853:fb29d7cd698b
mod_rest: Add an examlpe Flask app
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 25 Jan 2020 00:37:06 +0100 |
child | 3854:25c34c9f755c |
comparison
equal
deleted
inserted
replaced
3852:66f96b98d219 | 3853:fb29d7cd698b |
---|---|
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 | |
47 return Response(status=501) | |
48 | |
49 | |
50 if __name__ == "__main__": | |
51 app.run() |