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

21 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

3 Likes

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

4 Likes

Hi and thanks for this nice turturial. I do have some questions though.
I dont get the answers from Thunkable so hope you can help me out.
I now have tryed to publish on Apple 5 to 6 times with no luck.
I found out that the 2-3 first mail was going to a mail I didnt check. So that I know now.
But the last times i didnt get the mail at all. When I found the first mails it was an error on the Notification and maybe that is why it wont go thru the last times, so I like to know some things from you please.

  1. Do I have to use the Web API if I use OneSignal. If yes can you help with better pictures of the variable block you use in your picture.
  2. If I use the Web API can I make scheduled notifications also?
  3. Do I have to use firebase to make the notification ID?
  4. In your tutorial you write " In the Property Field add “Authorization” and in the value field “Basic” & YOUR_AUTHORISATION_CODE which you can find here " BUT Where can I put in the code???
  5. Maybe a short explanation on how the notification work.

I have send the app to Android but it dont seems that the notification works. I have only used the get Notification ID block and uploaded it to airtable and not firebase. Is that why it wont work?
When i tested the app the notification arrived in the Thunkable Live app and not in the real App

Hi Funhall Viborg

Please see below answers to your questions:

1- Yes in order to send to one user only you need to use a WEB-API
2 - Yes you can schedule notifications straight from the one signal dashboard
3 - I use Firebase in this example but you don’t need to you just need to store the notification ID so you can get it again
4 - You put this in the header field of your WEB-API
5 - if you wanted to share the project I can assist further

Did you have time to help me. I have send you PM

I tried 50 times and I figured it out.

Just use Headers input.

First write to Property inputbox : “Authorization”
to Value inputbox: “YOUR_AUTHORISATION_CODE” which you can find here
and press ADD;

Secondly write to Property inputbox : “Content-Type”
to Value inputbox: “application/json”

to Body input paste the code show below:

  1. if you want to send your notification everybody use this:

{
“app_id”: “05a1a9c5-xxxx-xxxx-xxxxx-aad3xx5071f2”,
“included_segments”: [“All”],
“data”: {“foo”: “bar”},
“contents”: {“en”: “English Message”}
}

  1. If you want to send your message to a spesicif person use this:
    {
    “app_id”: “05a1a9c5-xxxx-xxxx-xxxxx-aad3xx5071f2”,
    “include_player_ids”: [“8c08f556-xxxx-xxxx-xxxx-2513x6x64x51”],
    “data”: {“foo”: “bar”},
    “contents”: {“en”: “English Message”}

Or you can use block like this.

wola!

5 Likes

Thanks for all the posts. I will try and get this working tomorrow in my app. I would like to notify specific users when event occurs within the app.

2 Likes

I do already have a question. Acording to the Doc’s you can only test IOS notifications after its been uploaded to the app store? is that still true? I was hoping by downloading and installing the app they might work?

Hi Jeffrey,

I’ve found them to work by just downloading the app through thunkable - it may be because the above utilises the API call rather than the pushnotification component,

Jacob

2 Likes