-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmxpush.py
More file actions
25 lines (20 loc) · 776 Bytes
/
mxpush.py
File metadata and controls
25 lines (20 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import json, requests
from flask import Flask, jsonify, request
import ConfigParser
from matrix_client.api import MatrixHttpApi
app = Flask(__name__)
config = ConfigParser.ConfigParser()
config.read('/etc/mxpush.conf')
TOKEN = config.get("Matrix", "token")
HOMESERVER = config.get("Matrix", "homeserver")
ROOMID = config.get("Matrix", "room_id")
@app.route("/", methods=["POST"])
def handleNotification():
req = request.get_json()
print(req)
matrix = MatrixHttpApi(HOMESERVER, token=req['notification']['devices'][0]['pushkey'])
print(matrix.send_message_event(room_id=ROOMID, event_type='net.terracrypt.matrix.push', content=req))
return jsonify({})
if __name__ == "__main__":
app.config['TRAP_BAD_REQUEST_ERRORS'] = True
app.run(host='0.0.0.0')