agateblue / tempo

Your personal diary and mood tracker
GNU Affero General Public License v3.0
106 stars 12 forks source link

Fix #51: POST entry content in webhook #52

Closed agateblue closed 1 year ago

agateblue commented 1 year ago

Fix #51, Instead of an empty body, we now post an event type and the associated entry. A typical webhook payload looks like this:

{
    "event": "entry.created",
    "entry": {
        "text": "Test",
        "tags": [],
        "mood": 0,
        "type": "entry",
        "data": null,
        "favorite": false,
        "thread": null,
        "replies": [],
        "form": null,
        "date": "2023-02-16T14:18:40.669Z",
        "_id": "2023-02-16T14:18:40.669Z",
        "_rev": "1-3d6a4c5e599d4817d0db25231d01fc8a"
    }
}

Event can be one of entry.created, entry.updated or entry.deleted. The entry key will contain the data of the corresponding entry. The structure of the entry data should remain stable but is currently a dump of the internal object used by Tempo and might be subject to change over time. Once I'm confident webhooks work as expected, I will freeze the changes so that webhooks handler don't break.

A note about CORS

Note that since the webhook is sent from a web browser, the browser will likely issue a preflight CORS request before the actual POST request is sent. Your webhook handler will need to answer this request with the appropriate headers, typically:

Access-Control-Allow-Origin: https://yourtemposerver
Access-Control-Allow-Methods: POST, OPTIONS
Access-Control-Allow-Headers: content-type

Otherwise, the webhook won't be sent.