caronc / apprise-api

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

Can I customize or map [title] and [body] these two request parameters? #183

Closed jkoor closed 1 month ago

jkoor commented 3 months ago

:question: Question

Usually, apprise need title and body parameters to send message.

{
    "title": "xxx",
    "body": "xxx"
}

However, the webhook from some websites or applications change these two request parameters. for example:

{
    "title": "xxx",
    "content": "xxx"
}

So is there an easy way to map title and body these two request parameters? For example, use https://localhost/notify?title=title&body=content to map title and body parameters.

caronc commented 3 months ago

Sure you can. You probably want json:// or jsons:// if using SSL.

You're Apprise URL might look something like (see here - specifically here):

The JSON payload uses title already like you're expecting. It doesn't use body, but does use message which still isn't what you want. So the above maps it to content like you're looking for.

There are a few more entries on the JSON payload. If you want to turn them off plus the mapping, you're URL could look like:

jkoor commented 3 months ago

Thanks, maybe I didn't express myself clearly.

I use apprise to monitor my server and when the server provider detects a problem with the server, it sends me a message via appprise.

The route is probably like this: Server provider ①→ apprise-api ②→ telegram://xxx ③→ me

My problem is in ①, The server provider only supports use title and content to send post request to a webhook url,I use apprise-api as the webhook url to receive the message.

After checking the log, I found that apprise-api will show error if the request parameter missing body. So it can't reach ② stage.

My native language is not English, So maybe the expression is not very clear, Sorry.

caronc commented 3 months ago

I see what you're saying, at this time that isn't supported. But what is the name of the servce you're using. Perhaps i could add a /service/notify/ so it formats it the way the upstream service expects it?

Perhaps you can show me it's API as to how it ships the payload?

caronc commented 3 months ago

Also, i wonder if there would be value in making it so the apprise:// also supports the ?:key=value mapping to help you out with your post. Hence everything i said above would still apply, except you would set your apprise URL to be:

That would map content entry found in the payload to body

Would that work for you?

jkoor commented 3 months ago

I see what you're saying, at this time that isn't supported. But what is the name of the servce you're using. Perhaps i could add a /service/notify/ so it formats it the way the upstream service expects it?

Perhaps you can show me it's API as to how it ships the payload?

I see what you're saying, at this time that isn't supported. But what is the name of the servce you're using. Perhaps i could add a /service/notify/ so it formats it the way the upstream service expects it?

Perhaps you can show me it's API as to how it ships the payload?

Thanks, the server provider is just an example. Because it seems that different websites have different request parameters.

Maybe Website A send post request:

{
    "title": "xxx",
    "content": "xxx"
}

Website B send post request:

{
    "title": "xxx",
    "message": "xxx"
}

So I think this way which adding a /service/notify/ to adapt the Website A is not elegant.

Maybe chaning the way to map parameter is a better choice. I'm tring to modify the part of django to identify ?:key=value.

Thanks!

caronc commented 2 months ago

You closed this off. Did you want me to implement the :key=value mapping?

jkoor commented 2 months ago

You closed this off. Did you want me to implement the :key=value mapping?

If that's possible, that would be great!

I'm trying to modify the code in api/views.py:738-739

        if not content.get('title') and 'title' in request.GET:
            content['title'] = request.POST[request.GET['title']]
        if not content.get('body') and 'body' in request.GET:
            content['body'] = request.POST[request.GET['body']]

This method destroys the original logic and robustness of the code though it works successfully.

So If that's possible, that would be great! Thanks!

caronc commented 1 month ago

Closing this ticket off, as this feature has now been implemented.