Start a new topic

Where can I find the semantics for push.sendMessage(users, message)?

Where can I find the semantics for push.sendMessage(users, message)?



The reason I am asking is I'm wondering why if it says: ... users is either an array of Kinvey User documents or a single user document.



Why can't the call be this: push.sendMessage(userColl, request.body.message);



Rather than like this, as shown in your sample (slightly modified):



userColl.forEach(function (user) {

push.sendMessage(user, request.body.message);

});



From this page: http://devcenter.kinvey.com/rest/reference/business-logic/reference.html#push-module



And I want to better understand what's going on.


Are you running into a specific problem with the API or just want to make a suggestion of an improvement?



If you're running into a specific issue. Can you please articulate the specific problem you're running into and what you expect to have happen instead?
Gary,



You can use either a single user document, or an array of user documents. It doesn't matter if it's a single entity such as what is returned with findOne, or an array such as is returned by find.



So suppose you have a variable `userEntity` that contains the following:



```

{_id:"1234", _push: { ... push data ... }, username: "johndoe"}

```



Then you can call



```

push.sendMessage(user, "Hello");

```



That will send a push notification to the user that is contained in the userEntity variable.



You could also have userColl, which is an array of users, such as



```

[{_id:"1234", _push: {... push data ... }, username: "johndoe"}, {_id: "1235", _push: {... push data...}, username: "janesmith"}]

```



Then



```

push.sendMessage(userColl, "Hello!");

```



would send a message "Hello" to all users contained in sendMessage.



Note that the message in sendMessage is static and doesn't allow for tokenization at the current time. You can, however, use the forEach example (although we'd recommend using async.each instead) to iterate through and send a different message to each recipient.



Hope this answers your question!
Login or Signup to post a comment