46 lines
1.7 KiB
JavaScript
46 lines
1.7 KiB
JavaScript
// import Notifier from '../src/notify.js'
|
|
import Notifier from '@uci-utils/notify'
|
|
|
|
;(async () => {
|
|
const notify = await Notifier.create({
|
|
// one could read a file for these environment variables or hard code them here.
|
|
services:{
|
|
pushsafer:{
|
|
module: '@uci-utils/notify-pushsafer-plugin',
|
|
k: process.env.PS_API_KEY,
|
|
d: process.env.PS_DEVICE_ID // device or group id
|
|
},
|
|
email:{
|
|
module: '@uci-utils/notify-email-plugin',
|
|
credentials:
|
|
{ user: process.env.GMAIL_SMTP_USER,
|
|
pass:process.env.GMAIL_SMTP_PW
|
|
},
|
|
to: process.env.NOTIFY_EMAIL_RECIPIENTS.split(','),
|
|
subject:'uci notification'
|
|
}
|
|
}
|
|
})
|
|
|
|
console.log('registered services\n',notify.getServicesList())
|
|
console.log('registered services\n',notify.getService())
|
|
// console.log (notify._services.pushsafer._req)
|
|
// notify.disableService('pushsafer')
|
|
// notify.enableService('pushsafer')
|
|
console.log('pushsafter only', await notify.send('a pushsafter only message','pushsafer'))
|
|
console.log('not email', await notify.send('all but email message','!email'))
|
|
console.log('email only', await notify.send('email only message','email'))
|
|
let res = await notify.send('simple message to all services')
|
|
// let res = await notify.send({subject:'subject as message',text:'this details'})
|
|
// if (res.error) console.log('errors',res)
|
|
// else console.log(res)
|
|
// res = await notify.send({subject:'object message',otherprop:'some object in body'})
|
|
if (res.error) console.log('errors',res)
|
|
// else console.log(res)
|
|
|
|
})().catch(err => {
|
|
console.log('FATAL: UNABLE TO START NOTIFER! \n',err)
|
|
process.exitCode = 1
|
|
process.kill(process.pid, 'SIGINT')
|
|
})
|