Please.. help.. Thanks a lot!
Hi,
Can you share the code for onPreSave hook which doesn't work?
Is this issue happening for both Android and iOS devices?
Regards,
Wani
Kinvey Support
function onPreSave(request, response, modules) {
//recupera l'accesso alle collections
var collectionAccess = modules.collectionAccess;
//recupera il gestore per la collection 'user'
var userCollection = collectionAccess.collection('PharmacyUsers');
//utils ci servirà per il render template
var utils = modules.utils;
//push lo useremo per inviare le notifiche
var push = modules.push;
//template per il messaggio che invieremo nella notifica.
//i valori tra parentesi {{}} verranno sostituite con i valori
//di un json object
var template = '{{name}}, la farmacia {{farmacia}} ti dice {{messaggio}}';
//numero di notifiche inviate
var pushedMessageCount = 0;
//numero di utenti
var userCount;
var logger = modules.logger;
logger.info("Pharmacy:"+ request.body.pharmacy); //====================================== LOG ==========>>>>
logger.info("Sex:"+ request.body.sex); //====================================== LOG ==========>>>>
logger.info("Age From:"+ request.body.age_from);//====================================== LOG ==========>>>>
logger.info("Age To:"+ request.body.age_to);//====================================== LOG ==========>>>>
logger.info("Messaggio:"+ request.body.text);//====================================== LOG ==========>>>>
// Cerca tutti gli utenti che hanno la proprietà sex uguale al valore passato dal client
userCollection.find(
//criterio di filtro
// {"sex": request.body.sex},
{"sex":"M"},
// {
// "sex": request.body.sex,
// "pharmacy": request.body.pharmacy,
// "$and": [{ "ageusr": { "$gte": request.body.age_from } }, { "ageusr": { "$lte": request.body.age_to } }]
// },
//quando i dati sono sytati recuperati, invoca questa callback
function(err, userDocs){
// Total number of messages to send
userCount = userDocs.length;
logger.info("SendPush to num User ="+ userCount);//====================================== LOG ==========>>>>
if (userCount === 0){
response.continue(200);
return;
}
//inviamo i messaggi personalizzandoli uno per uno
userDocs.forEach(function(doc){
var values = {
name: doc.username,
farmacia: doc.pharmacy,
messaggio: request.body.text
};
// Render the message to send
var message = utils.renderTemplate(template, values);
// Send the push
push.send(doc, message);
logger.info("SendPush txt ="+ message);//====================================== LOG ==========>>>>
// Keep track of how many pushes we've sent
pushedMessageCount++;
// reduce the number of users left to push to
userCount--;
if (userCount <= 0){
// We've pushed to all users, complete the request
//response.body.message = "Attempted to push " + pushedMessageCount + " messages.";
response.continue(200);
}
});
});
}
Hi Wani,
Premise: with the “App A”, I create a table like the photo
that I’ll attach in next post. .
As you can see, i test this code .. and the query work fine… but… The push notification seams not work…
seams that can’t find the device that insert the record …
Please.. help.. Thanks a lot!
Hi Wani,
Premise: with the “App A”, I create a table like the photo
that I’ll attach in next post. .
As you can see, i test this code .. and the query work fine… but… The push notification seams not work…
seams that can’t find the device that insert the record …
Hi,
I lloked at your onPreSave hook code:
Hi Wani , thanks for your answer!
Yes.. I try to send push notification to PharmacyUsers… (deive who insert the record....)
because I think that I lack a concept … :-(
In my idea … I want create a APP (with embarcadero) … that at the first
time running… ask to the App user some data…(Age, sex, and so on. )
Than the data are posted by App to
Kinvey Tabe “PharmacyUsers”… I do like,
in the same time that The data are linked with the user App device UID…
Than… in a next time, when I’ll use another App … I can interrogate “PharmacyUser” table and send notification to the device that insert the funded record (by business logic query)…
Is that possible ? How can I do ?
BR.
In your example...
What do you mean ? Do you mean that there is a collencion named "user" that have fiel like "firstName" ?
Don't you do the same things that i have do for PahrmacyUsers ?
Thanks for your attenction
BR.
Enrico
var push = modules.push, collectionAccess = modules.collectionAccess;
collectionAccess.collection('user').find({"firstName": request.body.firstName}, function (err, userColl) {
if (err) {
logger.error('Query failed: '+ err);
} else {
userColl.forEach(function (user) {
logger.info('Pushing message to ' + user);
push.sendMessage(user, "People who are named " + user.firstName + " are awesome!", function(err, result) { }); }); } });
Bassignana Enrico
Good morning . we are trying to send push notification by your Kinvey provider but we
find some problem about send notification only to some device …
At this time We develop 2 Application develop by Embarcadero Xe10 platform:
>> APP “A ”<<<
1) The APP : Insert a record on a Kinvey table named :“UserApp”
2) the APP : waiting push notification and memorize it on a listBox.. .
>> APP “B ”<<< Sender of Push notification
1) The APP : Insert a record on a Kinvey table named :“Messages”
2) On Kinvey Business Logic we set a “OnPresave ” Hook in “Messages” table
And … on it … we write some code that do a query on “UserApp” table
and try to send notification to the device that corresponding on the query result ..
===> We try the query … and it work fine …
But the notification doesn’t Work !! by method : >>>>push.send(doc, message); <<<< Why ??
- if in business Logic… we use method : push.broadcastMessage(request.body.message, function(err, result) IT WORK FINE!
Why ?
Why the broadcast work fine ?
How can I see the “device id” that insert the record on table “UserApp” ?
Where can I see in Kynvwey all device registered ?
Please, can you help us ?
BR