caronc / apprise-api

A lightweight REST framework that wraps the Apprise Notification Library
https://hub.docker.com/r/caronc/apprise
MIT License
638 stars 56 forks source link

Added payload mapper #189

Closed caronc closed 4 months ago

caronc commented 5 months ago

Description:

Related issue (if applicable): refs #183

Added the ability to remap fields during a notification submission by using : (colon) in the GET args of the post.

For example, consider a situation where your server posts the following:

{
    "content": "Message body",
    "subject": "Message title",
}

These fields can be mapped to what the Apprise API expects with the following URL:

curl -X POST   \
   -F "body=Test Message" \
   -F "tags=all"  \
   "http://localhost:8000/notify/apprise-api-key?:content=body&:subject=title"

The above identifies :content=body which tells the Apprise API to map the content entry to body, and :subject tells it to map subject to title. Effectively, your payload looks like this now which is exactly what Apprise needed! :rocket: :

{
    "body": "Message body",
    "title": "Message title",
}

The colon : prefix is the switch that starts the rule engine. You can do 3 possible things with the rule engine:

  1. :existing_key=new_key: Rename an existing key to one apprise wants
  2. :existing_key=: By setting no value, the existing key is simply removed from the payload entirely
  3. :apprise_key=A value to give it: You can also set an expected apprise key to a pre-generated string value.

Checklist