MCPcopy
hub / github.com/web-push-libs/web-push / sendNotification

Function sendNotification

src/cli.js:62–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60};
61
62const sendNotification = args => {
63 if (process.env.GCM_API_KEY) {
64 webPush.setGCMAPIKey(process.env.GCM_API_KEY);
65 }
66
67 const subscription = {
68 endpoint: args.endpoint,
69 keys: {
70 p256dh: args.key || null,
71 auth: args.auth || null
72 }
73 };
74
75 const payload = args.payload || null;
76
77 const options = {};
78
79 if (args.ttl) {
80 options.TTL = args.ttl;
81 }
82
83 if (argv['vapid-subject'] || argv['vapid-pubkey'] || argv['vapid-pvtkey']) {
84 options.vapidDetails = {
85 subject: args['vapid-subject'] || null,
86 publicKey: args['vapid-pubkey'] || null,
87 privateKey: args['vapid-pvtkey'] || null
88 };
89 }
90
91 if (args.proxy) {
92 options.proxy = args.proxy;
93 }
94
95 if (args['gcm-api-key']) {
96 options.gcmAPIKey = args['gcm-api-key'];
97 }
98
99 if (args.encoding) {
100 options.contentEncoding = args.encoding;
101 }
102
103 webPush.sendNotification(subscription, payload, options)
104 .then(() => {
105 console.log('Push message sent.');
106 }, err => {
107 console.log('Error sending push message: ');
108 console.log(err);
109 })
110 .then(() => {
111 process.exit(0);
112 });
113};
114
115const action = process.argv[2];
116const argv = require('minimist')(process.argv.slice(3));

Callers 2

cli.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected