apprise-api icon indicating copy to clipboard operation
apprise-api copied to clipboard

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

Open jkoor opened this issue 1 year ago • 7 comments

: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.

jkoor avatar Apr 07 '24 08:04 jkoor

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

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

  • json://host/?:message=content

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:

  • json://host/?:message=content&:version&:type

caronc avatar Apr 07 '24 11:04 caronc

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.

jkoor avatar Apr 07 '24 15:04 jkoor

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 avatar Apr 07 '24 17:04 caronc

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:

  • apprise://host/?:content=body

That would map content entry found in the payload to body

Would that work for you?

caronc avatar Apr 07 '24 21:04 caronc

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!

jkoor avatar Apr 08 '24 13:04 jkoor

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

caronc avatar Apr 09 '24 10:04 caronc

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!

jkoor avatar Apr 09 '24 11:04 jkoor

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

caronc avatar May 12 '24 12:05 caronc