Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom fields in custom notifications #842

Closed
schklom opened this issue Feb 27, 2023 · 8 comments
Closed

Custom fields in custom notifications #842

schklom opened this issue Feb 27, 2023 · 8 comments

Comments

@schklom
Copy link

schklom commented Feb 27, 2023

馃挕 The Idea
From https://github.com/caronc/apprise/wiki/Notify_Custom_JSON, the important fields title and message are fixed.
Some services support different fields. For example, #652 only supports msg instead of message.
Ideally, being able to redirect title and message to other variables would be great, but at least being able to rename these fields would be a great start.
Currently, I don't see how to do #652 with the Custom JSON without this.

馃敤 Breaking Feature
None

@caronc
Copy link
Owner

caronc commented Mar 17, 2023

Hmm... not sure the best way to do this.

Perhaps if you use the payload over-ride keywords on one of the system ones, it just renames it? For example:
?:title=subject would rename the payload item title to subject?

This would allow me to re-use the existing payload over-ride tokens. This would work with for version, title, message, and type). All other over-rides would act as normal and introduce a new value.

Would that work?

@schklom
Copy link
Author

schklom commented Mar 18, 2023

It turns out that this does not solve #652 as I thought it would, as the server does not accept JSON data :/
Feel free to close this issue if you think it is not worth it.

I will try your idea when I can and report here anyway, it may help in the future.

Edit: ignore this message.

@caronc
Copy link
Owner

caronc commented Mar 18, 2023

You want to use the form:// Apprise service then with this same enhancement perhaps?

@schklom
Copy link
Author

schklom commented Mar 18, 2023

Ok, ignore my last message. It turns out that the server accepts JSON data but I was missing the header Content-Type: application/json in my tests :P

I need to change message into msg, and add a constant user and pass. The following

{
"user" : "...",
"pass" : "...",
"msg" : "..."
}

needs to be passed. Any additional field is ignored.

Here is what I tried, it doesn't seem to work well :/

# Sends the word "message"
www-data@apprise:/opt/apprise$ apprise -vvv -b "BODY" \
"jsons://smsapi.free-mobile.fr/sendmsg?:user=ABC&:pass=DEF&:msg=message"
2023-03-19 00:20:19,883 - DEBUG - Loaded JSON URL: jsons://smsapi.free-mobile.fr/sendmsg?method=POST&format=text&overflow=upstream&rto=4.0&cto=4.0&verify=yes&%3Auser=ABC&%3Apass=DEF&%3Amsg=message
2023-03-19 00:20:19,884 - DEBUG - Using selector: EpollSelector
2023-03-19 00:20:19,885 - INFO - Notifying 1 service(s) asynchronously.
2023-03-19 00:20:19,891 - DEBUG - JSON POST URL: https://smsapi.free-mobile.fr/sendmsg (cert_verify=True)
2023-03-19 00:20:19,892 - DEBUG - JSON Payload: {'version': '1.0', 'title': '', 'message': 'BODY', 'attachments': [], 'type': 'info', 'user': 'ABC', 'pass': 'DEF', 'msg': 'message'}
2023-03-19 00:20:20,149 - INFO - Sent JSON POST notification.

# Sends the word ":message"
www-data@apprise:/opt/apprise$ apprise -vvv -b "BODY" \
"jsons://smsapi.free-mobile.fr/sendmsg?:user=ABC&:pass=DEF&:msg=:message"
2023-03-19 00:20:19,883 - DEBUG - Loaded JSON URL: jsons://smsapi.free-mobile.fr/sendmsg?method=POST&format=text&overflow=upstream&rto=4.0&cto=4.0&verify=yes&%3Auser=ABC&%3Apass=DEF&%3Amsg=%3Amessage
2023-03-19 00:20:19,884 - DEBUG - Using selector: EpollSelector
2023-03-19 00:20:19,885 - INFO - Notifying 1 service(s) asynchronously.
2023-03-19 00:20:19,891 - DEBUG - JSON POST URL: https://smsapi.free-mobile.fr/sendmsg (cert_verify=True)
2023-03-19 00:20:19,892 - DEBUG - JSON Payload: {'version': '1.0', 'title': '', 'message': 'BODY', 'attachments': [], 'type': 'info', 'user': 'ABC', 'pass': 'DEF', 'msg': ':message'}
2023-03-19 00:20:20,149 - INFO - Sent JSON POST notification.

# Fails to send anything because the field "msg" is missing
$ www-data@apprise:/opt/apprise$ apprise -vvv -b "BODY" \
"jsons://smsapi.free-mobile.fr/sendmsg?:user=ABC&:pass=DEF&:message=msg"
2023-03-19 00:33:02,268 - DEBUG - Loaded JSON URL: jsons://smsapi.free-mobile.fr/sendmsg?method=POST&format=text&overflow=upstream&rto=4.0&cto=4.0&verify=yes&%3Auser=ABC&%3Apass=DEF&%3Amessage=msg
2023-03-19 00:33:02,269 - DEBUG - Using selector: EpollSelector
2023-03-19 00:33:02,270 - INFO - Notifying 1 service(s) asynchronously.
2023-03-19 00:33:02,276 - DEBUG - JSON POST URL: https://smsapi.free-mobile.fr/sendmsg (cert_verify=True)
2023-03-19 00:33:02,277 - DEBUG - JSON Payload: {'version': '1.0', 'title': '', 'message': 'msg', 'attachments': [], 'type': 'info', 'user': 'ABC', 'pass': 'DEF'}
2023-03-19 00:33:02,506 - WARNING - Failed to send JSON POST notification: Bad Request - Unsupported Parameters., error=400.
2023-03-19 00:33:02,507 - DEBUG - Response Details:
b''

# Same thing when setting ":message=:msg"

@caronc
Copy link
Owner

caronc commented May 13, 2023

Have a look at the latest Pull request (attached to this ticket); this will solve your problem going forward. In your case, you're URL would just need to look like:

  • jsons://smsapi.free-mobile.fr/sendmsg?:user=ABC&:pass=DEF&:message=msg&:version=&:title=&:type=

The above would:

  • remove version, type, and title from the payload
  • add "user": "ABC", and "pass": "DEF" to the payload
  • remap message to msg

Giving you the output:

{
"user" : "...",
"pass" : "...",
"msg" : "..."
}

@caronc
Copy link
Owner

caronc commented May 13, 2023

Closing off this ticket as it works great for me (added test cases too)! 馃檪 馃殌

@caronc caronc closed this as completed May 13, 2023
@schklom
Copy link
Author

schklom commented May 13, 2023

Thank you so much 馃殌
I will comment if I see any issue :)

@dgtlmoon
Copy link
Contributor

dgtlmoon commented Jul 7, 2023

jsons://smsapi.free-mobile.fr/sendmsg?:user=ABC&:pass=DEF&:message=msg&:version=&:title=&:type=

that's very cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants