diff options
author | Vitaly Takmazov | 2023-01-13 10:28:31 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2023-01-14 10:06:45 +0300 |
commit | e3c378cbf1d502263c61d3b9c31cd270bc3ae239 (patch) | |
tree | 9e038f42349671407e6f5906681de6448565f8eb /vnext/server/sender.js | |
parent | d94eec89b104e5c839d76c74ce94e83960d49c31 (diff) |
vnext: Telegram bot (WIP)
Diffstat (limited to 'vnext/server/sender.js')
-rw-r--r-- | vnext/server/sender.js | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/vnext/server/sender.js b/vnext/server/sender.js index 6ece8eaa..f33eadcf 100644 --- a/vnext/server/sender.js +++ b/vnext/server/sender.js @@ -1,5 +1,6 @@ import PushNotifications from 'node-pushnotifications'; -var debug = require('debug')('sender'); +import debug from 'debug'; +const log = debug('sender'); import { deleteSubscribers } from './http'; import { formatMessage, formatTitle, formatQuote } from './common/MessageUtils'; import config from 'config'; @@ -51,7 +52,7 @@ export function sendNotification(productionIds, sandboxIds, data) { sender.send(registrationIds, data) .then((results) => { results.forEach(result => { - debug(`${result.method}: ${result.success} success, ${result.failure} failure`); + log(`${result.method}: ${result.success} success, ${result.failure} failure`); if (result.failure) { console.error(`${result.method} failure: ${JSON.stringify(result)}`); console.error(`Failed data: ${JSON.stringify(data)}`); @@ -59,13 +60,13 @@ export function sendNotification(productionIds, sandboxIds, data) { }); results.filter(r => r.method === 'apn') .forEach(async r => { - debug(`Response message: ${JSON.stringify(r.message)}`); + log(`Response message: ${JSON.stringify(r.message)}`); let badTokens = r.message.filter(m => m.errorMsg === 'BadDeviceToken').map(m => { return { 'type': 'apns', 'token': m.regId }; }); if (badTokens.length > 0) { await deleteSubscribers(badTokens); - debug(`${badTokens.length} APNS tokens deleted`); + log(`${badTokens.length} APNS tokens deleted`); } }); results.filter(r => r.method === 'gcm') @@ -75,7 +76,7 @@ export function sendNotification(productionIds, sandboxIds, data) { }); if (badTokens.length > 0) { await deleteSubscribers(badTokens); - debug(`${badTokens.length} GCM tokens deleted`); + log(`${badTokens.length} GCM tokens deleted`); } }); results.filter(r => r.method === 'mpns') @@ -85,7 +86,7 @@ export function sendNotification(productionIds, sandboxIds, data) { }); if (badTokens.length > 0) { await deleteSubscribers(badTokens); - debug(`${badTokens.length} MPNS tokens deleted`); + log(`${badTokens.length} MPNS tokens deleted`); } }); }) @@ -136,7 +137,5 @@ export function buildNotification(user, msg) { template.tag = `${tag}`; template.android_channel_id = 'default'; } - // FIXME: wrong type definition in node-pushnotifications: title and body and not required for silent pushes - // @ts-ignore return template; } |