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 #219

Closed sanaddfffrnt closed 5 months 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

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 };