When working with OneSignal, you sometimes receive an API response telling you that the notification you've sent does not have any recipients ("All players are not subscribed"). This can either mean that the notifications you've setup are not working like intended (e.g. you're using wrong filters) or that a former active user of yours became inactive and cannot be addressed any longer. In case you are targeting users using tags this can happen quite frequently.
To avoid the cost of creating a OneSignalException
in that case there is an option now to prevent vertx-push-onesignal
from creating these exceptions in case that response is received from the OneSignal API.
To enable it, just use one of the new factory methods in PushClient
that take a PushClientOptions
parameter like so:
PushClient.create(Vertx.vertx(), new PushClientOptions()
.setAppId("YOUR_APP_ID")
.setRestApiKey("YOUR_API_KEY")
.setIgnoreAllPlayersAreNotSubscribed(true) //
).
//setup a template on the OneSignal-Dashboard and use it here
withTemplate("someTemplateId").
//all users should receive this
targetBySegments(Segments.ALL).
sendNow(
h -> {
if (h.succeeded()) {
System.err.println(h.result().encodePrettily());
} else {
h.cause().printStackTrace();
}
System.exit(0);
});