Yanndroid / Notifer

Notification transfer to HTTP servers
MIT License
17 stars 4 forks source link

Server side Example #1

Closed eVk2012 closed 3 months ago

eVk2012 commented 3 months ago

Great app!! But is there any simple example in the server side to receive the messages? Thanks for your time

Yanndroid commented 3 months ago

Hey there, sorry for the late reply. The server isn't anything special. It's just a simple http server which receives json data in post requests.

Here's a python example, which prints the received data:

import http.server

class RequestHandler(http.server.BaseHTTPRequestHandler):
    def do_POST(self):
        print(self.rfile.read(int(self.headers["Content-Length"])).decode("utf-8"))
        self.send_response(200)
        self.end_headers()

if __name__ == "__main__":
    http.server.HTTPServer(("", 8000), RequestHandler).serve_forever()

And here's what the payload looks like:

{
  "color": {
    "hex": "#FFFF00",
    "rgb": "[255, 255, 0]",
    "hsv": "[60.0, 1.0, 1.0]",
    "int": -256
  },
  "label": "Notifer",
  "package": "de.dlyt.yanndroid.notifer",
  "id": 0,
  "time": 1719851309270,
  "ongoing": false,
  "removed": false,
  "title": "Test Notification",
  "text": "This is a test notification",
  "progress_indeterminate": false,
  "progress_max": 0,
  "progress": 0,
  "dnd": 1
}
eVk2012 commented 3 months ago

Perfect, I'll try it