Sending Notification to Specific User with Onesignal

Hi All,

The Thunkable X documentation only shows you the possibility of using OneSignal to send notifications on bulk to your list of subscribed or active users. However many applications require the ability to send a notification to a specific user based on an action that occurs within the app.

For example when I request an Uber, a notification is sent directly to me when my Uber is one minute away. We can do similar with OneSignal and Thunkable by doing the below (Note: you can’t live test Push Notifications - I suggest you make this the last thing you build into your app)

1 - Follow the documentation for setting up your OneSignal account here

2 - Paste your API key into the Onesignal on your app

3 - In order to send Push Notifications on a triggered event we are going to use OneSignals REST API, place a WEB API component into your app and fill in the details as shown below:

URL: https://onesignal.com/api/v1/notifications

In the Property Field add “Authorization” and in the value field “Basic” & YOUR_AUTHORISATION_CODE which you can find here

Then repeat the Process with “Content-Type” in the property field and “application/json” in the value field. These will be your Headers for the API call.

4 - When a user signs up for the app we capture some details in Firebase - we store their PushID against their data so we can reuse this to send notifications in our app:

5 - Now we are ready to trigger an event and send a notification to the user, we use the WEB API we created and update the BODY of the API call below:

{ “app_id”: “FIND_YOUR_APP_ID_HERE”, “contents”: {“en”: “ADD_YOUR_NOTIFICATION_MESSAGE”}, “headings”: {“en”: “ADD_NOTIFICATION_HEADING”}, “url”: “”, “include_player_ids”: [“ADD_USERS_PUSHID”] }

Edit the above to reflect what your notification says and include your APP ID and the users PUSH ID that we saved earlier when they created an account, then you create a post call and the user will receive a notification when this particular action occurs,

Please reach out if you have any questions

Jacob

6 Likes

So presently we cannot get sounds to play when we get a push notification using the OneSignal blocks. Using the REST API are we able to do that yet or is that just to get a single user push?

Hi Sam,

This seems doable, you would just need to include in your body of the API call the “iOS_sound” parameter as below:

{ “app_id”: “FIND_YOUR_APP_ID_HERE”, “contents”: {“en”: “ADD_YOUR_NOTIFICATION_MESSAGE”}, “headings”: {“en”: “ADD_TICKET_HEADING”}, “url”: “”, “ios_sound”: “EXAMPLE_SOUND.WAV”,“include_player_ids”: [“ADD_USERS_PUSHID”] }

I haven’t tested this so let me know if it works, the full range of parameters you can use in this call are available here

1 Like

Good to know. Thank you.

And in classic? How can we do It? :kissing_smiling_eyes:

1 Like

this is amazing, thank you , do you know if i can do this with the airtable spreadsheet
?

i already checked your nswer thanks

Hi Alan,

So you understand how to?

yeah brother thanks

Why did you obscure the object fields?

Hi Max,

Because it didn’t directly relate to the tutorial and I didn’t want to confuse readers - do you require the child nodes?

The firebase part is just not useful for the notification purpose, right?

This link says missing app_ID so I can’t understand the rest that’s writtten after

Also; do you know anything about opening an app specific screen when the notification is pressed?
It should be app_url but we don’t have those in thunkable, right?

from the onesignl official site:

data
object
All
A custom map of data that is passed back to your app.
Example: {"abc": "123", "foo": "bar"}
url
string
All
The URL to open in the browser when a user clicks on the notification.
Example: http://www.google.com
Note: iOS needs https or updated NSAppTransportSecurity in plist
This field supports inline substitutions.
Omit if including web_url or app_url
web_url
string
All Browsers
Same as url but only sent to web push platforms.
Including Chrome, Firefox, Safari, Opera, etc.
app_url
string
All Apps
Same as url but only sent to app platforms.
Including iOS, Android, macOS, Windows, ChromeApps, etc.

Hi, can you share this to remix and for better understanding

1 Like