OneSignal / onesignal-expo-plugin

The OneSignal Expo plugin allows you to use OneSignal without leaving the managed workflow. Developed in collaboration with SweetGreen.
Other
142 stars 46 forks source link

Unable to make android notifications appear as a banner #218

Closed sanaddfffrnt closed 1 week ago

sanaddfffrnt commented 5 months ago

Hello, I'm working on displaying Android notifications as banners/bubbles instead of just in the notification drawer. I attempted to set the android_channel_id in our REST API to the OneSignal dashboard's Channel Id value, but it caused issues with notifications appearing in the drawer.

Drawer: image

Banner/bubble: image

Could someone please provide a clear example of how to configure this in the REST API? The documentation isn't providing enough clarity.

Here is the sendPushNotification function

const axios = require('axios');

const sendPushNotification = async (messages) => {
  for (let i = 0; i < messages.length; i++) {
    const message = messages[i];
    const options = {
      method: 'POST',
      url: 'https://onesignal.com/api/v1/notifications',
      headers: {
        accept: 'application/json',
        Authorization: 'Basic ' + process.env.ONESIGNAL_API,
        'content-type': 'application/json',
      },
      data: {
        app_id: '1234',
        android_channel_id: '1234',
        include_external_user_ids: [message.to],
        contents: {
          en: message.body,
        },
        headings: {
          en: message.title,
        },
      },
    };

    await axios.request(options);
  }
  try {
  } catch (error) {
    console.error('Error sending push notification:', error);
  }
};

module.exports = { sendPushNotification };
rgomezp commented 1 week ago

Hello, see https://documentation.onesignal.com/docs/android-notification-categories#from-the-rest-api

and

https://documentation.onesignal.com/reference/push-channel-properties#appearance

Note that it may not work depending on the device + 0S you're testing on (see https://github.com/OneSignal/OneSignal-Android-SDK/issues/878#issuecomment-546139084)