Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to make android notifications appear as a banner #218

Open
sanaddfffrnt opened this issue Jan 8, 2024 · 0 comments
Open

Unable to make android notifications appear as a banner #218

sanaddfffrnt opened this issue Jan 8, 2024 · 0 comments

Comments

@sanaddfffrnt
Copy link

sanaddfffrnt commented Jan 8, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant