Push Notification Icon

I’m proud to say I’ve got the push notifications working from this thread

I am still trying to figure out how to adjust the small_icon in Thunkable. Here’s the notes on that currently from OneSignal - Android: Notification Icons

Does anyone know off hand how to do this? I imagine it’s simple now that everything is setup. I’ve tried a few variations to no avail.

2 Likes

Thunkable is using React Native and therefore you need to get the APK and edit it with an APK editor then update the following paths and then recompile

This will not work for iOS.

2 Likes

Is there a way to set the push notification delay for send_after to be set as seconds since 1970?

That would help because I won’t have to convert the time units to a normal date format, plus the trouble of what happens toward the end of a month for example… If I want to send 14 days before April 2, 2022 then I have to convert the month April into March because you can’t subtract 14 days from 2.

Same goes for every other unit of time, hours, minutes, seconds, years and so on.

Would be nice if I could just easily do seconds since 1970.

Thanks

Also wondering if a push notification can send a user to a certain screen or something within the app. I need to re title this thread to ‘all things push notifications’ I guess ha

And also how to cancel a scheduled push notification.
I need to allow users to cancel appointments and of course the scheduled push notifications reminders that go along with it

I decided to use a Unix rest API for the 1970 issue because OneSignal doesn’t accept Unix times it seems, I’m creating multiple reminders, so I have to convert the original appointment date to Unix, then subtract the seconds for each reminder and make a list of those.
Then, that list of seconds subtracted Unix times is used to convert back into normal date/time and a 2nd list is created of those. Then I run that list through OneSignal with the send_after parameter.

1 Like

You could easily pass the following to a JavaScript code which will give you the future date you want

new Date(2022, 3 - 1, 6 + 14).toUTCString()

The Date constructor takes the following arguments

  • first argument, year in 4 digit
  • second argument, month in 0 based so March is 2
  • third argument is days ( in the example I am passing todays date “6” + 14 days from today
  • the toUTCString() is required by OneSignal because it recognizes GMT only.

The command is case sensitive so you need to supply it in proper case.

In the third argument you can supply the day with the number of days required using + to move to the future or - to move to the past.

I actually need to move back in time though, because the appointment date is set for example April 1st.
I want a push reminder for the day before on March 31.

But also, in what block do you enter this?

Thanks again

1 Like

image
This is what you will supply the JavaScript code and the result is shown in the screen. It will give you the correct date whether forward or backward.

See my demo project
https://x.thunkable.com/projectPage/621c9b6c73ba2500119d10ef

2 Likes

Thank you for this, one last one… is there a quick and easy way to get a list of all scheduled notifications and a way to delete any or all of those scheduled notifications?

1 Like

Yes, try this API end points

curl --include \
     --header "Authorization: Basic YOUR_REST_API_KEY" \
     "https://onesignal.com/api/v1/notifications?app_id=YOUR_APP_ID"

sample output

200 OK

Sample output
{
    "total_count": 553,
    "offset": 0,
    "limit": 1,
    "notifications": [
        {
            ...
            "app_id": "3beb3078-e0f1-4629-af17-fde833b9f716",
            ...
            "chrome_web_icon": "https://img.onesignal.com/t/73b9b966-f19e-4410-8b5d-51ebdef4652e.png",
            ...
            "ios_interruption_level":"active",
                    "ios_relevance_score": 0.0,
            "name": "Campaign: New Shoe Releases", 
            "contents": {
                "en": "Come by and check out our new Jordan's!!! (Shoes) 🎃🙊👻"
            },
            "converted": 0,
            "data": {
                "your_data_key": "your_data_value"
            },
            ...,
            "errored": 1,
            "excluded_segments": [
                "3 Days Inactive"
            ],
            "failed": 0,
            ...
            "headings": {
                "en": "Thomas' Greatest Site in the World!! 😜😁"
            },
            "id": "e664a747-324c-406a-bafb-ab51db71c960",
            ...
            "included_segments": [
                "all"
            ],
            ...
            "queued_at": 1557946677,
            "remaining": 0,
            "send_after": 1557946620,
            "completed_at": 1557946677,
            "successful": 386,
            ...
            "url": "https://mysite.com",
            ...
            "platform_delivery_stats": {
                "edge_web_push": {
                    "successful": 2,
                    "failed": 0,
                    "errored": 0,
                    "converted": 2,
                    "received": 2

                },
                "chrome_web_push": {
                    "successful": 26,
                    "failed": 0,
                    "errored": 0,
                    "converted": 26,
                    "received": 26
                },
                "firefox_web_push": {
                    "successful": 1,
                    "failed": 0,
                    "errored": 0,
                    "converted": 1,
                    "received": 1
                },
                "android": {
                    "successful": 198,
                    "errored": 1,
                    "failed": 0,
                    "converted": 198,
                    "received": 198
                },
                "safari_web_push": {
                    "successful": 3,
                    "failed": 0,
                    "errored": 0,
                    "converted": 3,
                    "received": 3
                },
                "ios": {
                    "successful": 2,
                    "errored": 3,
                    "failed": 0,
                    "converted": 2,
                    "received": 2
                }
            },
            "ios_attachments": {
                "id": "https://img.onesignal.com/n/44843933-68d4-450c-af5c-5e5c1a9d946e.jpg"
            }
        }
    ]
}
2 Likes

I’m not sure what to do with curl and include.

And how do I delete them?

1 Like

This is what you require (according to documentation)

https://onesignal.com/api/v1/notifications?app_id=YOUR_APP_ID&limit=:limit&offset=:offset&kind=:kind

Parameters are:

  • limit is the max number of notifications to poll. Max is 50
  • offset is the page number to start in case you have more than 50 entries
  • kind should be set to 1 to get notifications set by API not by dashboard

To delete use:

https://onesignal.com/api/v1/notifications/:id?app_id=:app_id

You will need to supply the notification ID in place of :id along with App ID.

I’ve tried using Delete and Post here but I get an error both ways. I’m manually entering the notification ID & my App_ID and getting a 500 error if I do Delete, and a 404 if I do Post

Am I supposed to use a generate JSON from object in the WebAPI body somewhere?

EDIT: Turns out it was delete, I was just dealing with quite a long delay between loading my new blocks for the app to load. Getting 200 now! Thanks

1 Like

Glad you’re making progress in it.

This is what I’m getting when I try to make a list of all notifications with those parameters.
It’s a 200 but there’s tons of information I don’t want/need right now

1 Like

Trying a combination of the following is not giving me a result I can use so far


a

1 Like

notifications is an array (a list) so you need to use the list component to retrieve the information in it.

If I put it in a for each item j, I get object Object

1 Like

Notification is a list of objects so if you want to loop through it you should also use the object properties blocks to extract information from the entries of the list.

Example

Gives me
image

1 Like