caronc/apprise

Onesignal notifications do not work with a template, but without a body (+custom_data support)

Closed this issue ยท 4 comments

๐Ÿ“ฃ Notification Service(s) Impacted
Onesignal

๐Ÿž Describe the bug
Apprise does not send Onesignal notifications without a body and does not support custom arguments.
Some services, like Onesignal, support sending notifications with templates. When a template ID is provided - it is not required (and even not recommended) to pass message body. The message is taken from the template body message, and is then templated using custom data provided in the request (see Onesignal documentation, search for "custom_data"). Currently, Apprise refuses for work in this framework (it both does not accept None as body and does not accept custom_data in Onesignal requests). It also should not override title with "Apprise Notifications".

๐Ÿ’ก Screenshots and Logs

import apprise

apobj = apprise.Apprise()
apobj.add("onesignal://template_id:app_id@api_key/player_id")
res = apobj.notify(body=None)
print(res)

The code above returns False indicating an internal error, and notifications are sent. It should return True, and result in a successful notification with template's message body and title. Also, it should accept a custom_data object.

๐Ÿ’ป Your System Details:

  • OS: MacOs 14.5 (23F79)
  • Python Version: Python 3.9.12
  • Apprise version: 1.8.0

this is a bit of a one off; i can update the title to be blank if nothing is provided if the upstream server will accept this. If i recall testing this in the past, the fields had to be populated (but i could be wrong).

Apprise has only 1 global requirement: either a body is provided at minimum, or an attachment is provided (to which case a body is not needed). But i do not see value in a use-case to not support a body, title, and attachment all missing. Even in the case for OneSignal.

I don't mind adding support for custom data, but all fields would be 'text' {'key': 'value'} and they would need to be provided into the Apprise URL (e.g. onesignal://credentials/:key=value&:key2=custom_value2)

would that work?

this is a bit of a one off; i can update the title to be blank if nothing is provided if the upstream server will accept this. If i recall testing this in the past, the fields had to be populated (but i could be wrong).

Apprise has only 1 global requirement: either a body is provided at minimum, or an attachment is provided (to which case a body is not needed). But i do not see value in a use-case to not support a body, title, and attachment all missing. Even in the case for OneSignal.

I don't mind adding support for custom data, but all fields would be 'text' {'key': 'value'} and they would need to be provided into the Apprise URL (e.g. onesignal://credentials/:key=value&:key2=custom_value2)

would that work?

Hey @caronc
So body, title or attachment are actually not required either when using a template, because these are defined inside the template, and the only thing left is to pass custom arguments inside the notification request. Then the body defined in the template is Jinja-templated by Onesignal on their server-side. This is an immensely powerful feature that removes the need to store the body of the notification on the sending side, which we are currently plan on utilizing (and are utilizing for Sendgrid).
That said, I have already started my work on adding support for all of this here, and I hope I will submit a PR for this change in the coming days. Does that work for you?

I'll entertain your PR, my concern is just altering the default logic of Apprise to accept a use without any input. This may get your template feature to work, but it could also break the other 106 plugins (that can't handle nothing passed).

My recommendation would be to support the template through url arguments and if a template is provided, just ignore the body provided (but still expect one). ifttt:// has some logic like this i believe too.

I don't see an issue where the body is just even set to ignored in your case.

Either way, if you have something in mind, i can still at least entertain it ๐Ÿ‘

Completed in #1164 and #1158