Skip to content

Commit

Permalink
Added testing functions
Browse files Browse the repository at this point in the history
  • Loading branch information
cjbatin committed Feb 27, 2019
1 parent 446116a commit eb44aa6
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,67 @@ app.get('/auth', function (req, res) {
}
});
});

app.get('/push/device', function (req, res) {
var recipient = {
deviceId: 'YOUR_DEVICE_ID'
};
var notification = {
notification: {
title: 'Hello from Ably!'
}
};
realtime.push.publish(recipient, notification, function(err) {
if (err) {
console.log('Unable to publish push notification; err = ' + err.message);
return;
}
console.log('Push notification published');
res.send("Push Sent");
});
})

app.get('/push/client', function (req, res) {
var recipient = {
clientId: 'iosPushClient'
};
var notification = {
notification: {
title: 'Hello from Ably!'
}
};
realtime.push.publish(recipient, notification, function(err) {
if (err) {
console.log('Unable to publish push notification; err = ' + err.message);
return;
}
console.log('Push notification published');
res.send("Push Sent");
});
})

app.get('/push/channel', function (req, res) {
var extras = {
push: {
notification: {
title: 'Hello from Ably!',
body: 'Example push notification from Ably.'
},
data: {
foo: 'bar',
baz: 'qux'
}
}
};

var channel = realtime.channels.get('push');
channel.publish({ name: 'example', data: 'data', extras: extras }, function(err) {
if (err) {
console.log('Unable to publish message with push notification; err = ' + err.message);
return;
}
console.log('Message with push notification published');
res.send("Push Sent");
});
})

0 comments on commit eb44aa6

Please sign in to comment.