I am integrating OneSignal
into my app built with Felgo
, when building my app for test purposes I am able to manually send notifications from my OneSignal dashboard, but obviously I want these to be automatic when an event happens in app.
I am truly struggling to understand how to get this working, I have read through both:
and I think combining these would be how I would go about it? Something along the lines of:
AppButton {
id: button
onClicked: {
//other onClicked actions,
HttpRequest
.post("https://onesignal.com/api/v1/notifications")
.set('Content-Type', 'application/json')
.send({ title: "post title", body: "post body" })
.then(function(res) {
console.log(res.status);
console.log(JSON.stringify(res.header, null, 4));
console.log(JSON.stringify(res.body, null, 4));
})
.catch(function(err) {
console.log(err.message)
console.log(err.response)
});
}
}
But how on earth would I go about sending to specific tags
for targeted notifications?
In the Felgo OneSignal
link above, they show that I can test push notifications with curl in the following way:
curl --include \
--request POST \
--header "Content-Type: application/json" \
--header "Authorization: Basic <ONESIGNAL-REST-API-KEY>" \
--data-binary '{
"app_id": "<ONESIGNAL-APP-ID>",
"contents": { "en": "Message" },
"tags": [{"key": "userId", "relation": "=", "value": "1"}]
}' \
https://onesignal.com/api/v1/notifications
But outside of test purposes, how would I go assigning the specific tags and trigger a notification on a button press (or other event) within my app?
I understand all the information I should need to implement the notifications is there - but I cannot begin to make sense of it! :(
Any help would be massively appreciated as even when reading through documentation I am struggling.