Friday, 9 June 2017

I am a beginner with node.js and API's - would the below code send a notification from user1 to user2?

I am a beginner with node.js and API's, I followed the getstream.io tutorials and came up with the below code

Would the below code send a notification from user1 to user2?

And how do I confirm that this successfully happens?

var stream = require('getstream');
// Instantiate a new client (server side)
client = stream.connect('key', 'secret', '25553');
// creates token so user1 can read and write
var token = client.feed('user', '1').token;
var user1 = client.feed('user', '1', token);

// Create a bit more complex activity
activity = {
    'name': 'Jack', 
    'location': {'type': 'point', 'coordinates': [37.769722,-122.476944]},
    'to' : ['notification:user2'] 
};

user1.addActivity(activity)
    .then(function(data) { /* on success */ })
    .catch(function(reason) { /* on failure */ });

// update the buyer status value for the activity
activity.name = 'James';

// send the update to the APIs
client.updateActivities([activity]);

//client side
//creates new client for reading
var client2 = stream.connect('key', null, '25553'); 

//creates read only token from sever client
var readonlyToken = client.feed('user', '1').getReadOnlyToken();

//user 2 gets read only token from user 1
var user2 = client2.feed('user', '1', readonlyToken);

//notification seen
user2.get({limit:5, mark_seen:true})
    .then(function(data) { /* on success */ })
    .catch(function(reason) { /* on failure */ });



via Davidson Otobo

No comments:

Post a Comment