Open Darrow8 opened 2 years ago
Whenever I try to send a notification it is sent twice although on the console it is only logged as once.
Here is my code:
const OneSignal = require('onesignal-node'); const client = new OneSignal.Client('****', '****'); // private keys async function sendNotification(notification) { try { const response = await client.createNotification(notification); console.log(response.body.id); } catch (e) { if (e instanceof OneSignal.HTTPError) { // When status code of HTTP response is not 2xx, HTTPError is thrown. console.log(e.statusCode); console.log(e.body); } } // or you can use promise style: client.createNotification(notification) .then(response => { console.log('sent notification') console.log(response); }) .catch(e => { console.log('problem w notification sending') console.log(e) }); } sendNotification({ contents: { 'en': 'test 3!', }, include_player_ids: ['****'] // my phone's ID });
Here is the response from the console:
And I am getting the notification twice on my test device (IOS 14,2). I have looked on the duplicated notifications one signal page and it has been no help: https://documentation.onesignal.com/docs/duplicated-notifications.
@Darrow8 you are triggering client.createNotification(notification) twice, choose the async await solution OR the promise based one
client.createNotification(notification)
Whenever I try to send a notification it is sent twice although on the console it is only logged as once.
Here is my code:
Here is the response from the console:
And I am getting the notification twice on my test device (IOS 14,2). I have looked on the duplicated notifications one signal page and it has been no help: https://documentation.onesignal.com/docs/duplicated-notifications.