Hi Nathan,
That seems possible but maybe a screen recording will help me give you the best possible answer.
Thanks,
Deb
Hi Nathan,
That seems possible but maybe a screen recording will help me give you the best possible answer.
Thanks,
Deb
Hi Deb
Screen recording here: https://www.loom.com/share/0d454033f9a8406485eb61ac9c003f3c - hope that helps.
Give me a shout if anything is unclear.
Best,
Nathan
Hi Nathan,
I have a suggested snippet but can show me the following pieces of information:
Thanks,
Deb
Hi Deb
"payload": {
"to": [
{
"name": "{{ [Full name] }}",
"type": "to",
"email": "{{ [Email] }}"
}
],
"html": "<h1>Hi, {{ [First name] }}.</h1><p>Your Will is ready for review.</p>",
"subject": "Your Will is ready for review",
"from_name": "Humber Law"
},
"conditions": [
{
"Will": {
"$ne": null
}
}
]
},
{
"type": "email",
"runOn": [
"update"
],
"payload": {
"to": [
{
"name": "{{ [Full name] }}",
"type": "to",
"email": "{{ [Email] }}"
}
],
"html": "<h1>Hi, {{ [First name] }}.</h1><p>Your documents have been posted and are on the way.</p>",
"subject": "Your documents have been posted to you",
"from_name": "Humber Law"
},
"conditions": [
{
"Documents posted?": {
"$eq": "Yes"
}
}
]
},
Best,
Nathan
Hi Nathan,
Here is a snippet that sets the notificationSentWill field to “Yes” if the field already contains some value. You might need to add more conditions to the IF statement depending on what is stored in the DS.
//The will only run when form is editing an entry
if (query.dataSourceEntryId) {
//Change DS ID below
Fliplet.DataSources.connect(123).then(function (connection) {
return connection.findById(query.dataSourceEntryId).then(function (record) {
return Fliplet.FormBuilder.get().then(function (form) {
//More falsey conditions might be needed based on what is stored in the DS.
if (record.notificationSentWill) {
form.field('notificationSentWill').set('Yes');
}
//Add more If statement's for all the form fields needed.
});
});
});
}
Hope this helps,
Deb
Hi Deb
This app is now live and in the app stores which means testing of push notifications is a lot easier!
Can I check two things, firstly, when updating Data Source Hooks in a data source, do you need to publish the app update for it to take affect?
Secondly, does the below trigger a push notification when the Documents Posted field is updated to ‘yes’?
{
"type": "push",
"appId": -----,
"runOn": [ "update" ],
"payload": {
"title": "Documents posted",
"body": "Your documents have been posted and are on their way to you."
},
"filter": {
"match": { "documentsPosted": "Yes" },
"dataSourceId": ------
}
},
I understand I need the Push subscription ID so have created the empty field in the data source, will simply adding the below (where 123 and 456 are set to the Data source ID) to the Home screen JS set this?
Fliplet.User.getSubscriptionId().then(function (id) {
// Save id to the user's data source entry under the "flPushSubscriptionId" key
Fliplet.DataSources.connect(123).then(function (connection) {
return connection.update(456, { flPushSubscriptionId: id });
});
});
Thanks!
Nathan
Hi Nathan,
When updating a hook you do not need to publish for it to take affect. it will go live immediately.
Yes that hook should fire when the field is updated to Yes.
In order to get the subscription ID you first need ask the user to subscribe and then query the data source for that users data and then you can update their record with the subscription ID. For e.g.
Fliplet.Widget.get('PushNotifications')
.ask()
.then(function(subscriptionId) {
return Fliplet.Session.get().then(function(session) {
var user = _.get(session, 'entries.dataSource.data');
if (!user) {
return; // user is not logged in
}
if (!user.flPushSubscriptionId) {
return Fliplet.DataSources.connectByName(DS.users).then(function(c) {
return c
.findOne({
where: { Email: user.Email }
})
.then(function(r) {
if (r) {
return c.update(r.id, { Email: user.Email, flPushSubscriptionId: subscriptionId });
}
});
});
}
});
})
.catch(function(error) {
// here you can present the error to the user if necessary
console.error(error);
});
Hope that helps,
Deb
Hi Deb
The user has already subscribed to push notifications on the first screen so is that all still relevant? There is a snippet on this page Data Source Hooks | Fliplet Developers Documentation that suggests this:
Fliplet.User.getSubscriptionId().then(function (id) {
// Save id to the user's data source entry under the "flPushSubscriptionId" key
Fliplet.DataSources.connect(123).then(function (connection) {
return connection.update(456, { flPushSubscriptionId: id });
});
});
But I couldn’t get it to add the subscription id to the field in the DS. I did change 123 and 456 to what I think are the relevant IDs but maybe not!
Thanks,
Nathan
Hi Nathan,
Yes, you need to first the the entry ID of the users record in the data source hence you need to do everything I mentioned.
Even if the user is already subscribed this code will check and if they are then not take any action i.e. make any changes to the data source.
Thanks,
Deb
Ah ok thanks for the explanation Deb. Just to confirm, I add your code to the JS of the Home screen for example? Can’t get it to populate the ID in the datasource field.
Hey Deb - I assume I’m missing something but I can’t get the flPushSubscriptionId field to populate on the live app.
Hi Nathan,
Yes, you need to add my code to the Home screen.
It will be hard for me to tell what is wrong without looking at your app. I suggest maybe checking the security rules in the data source and see if it allows updating.
Thanks,
Deb
Hi Deb - added the code to the Home screen last week but can’t seem to get it to populate the DS field.
Have also checked the DS rules and update is allowed. It is the same DS from where we send the email notifications too.
Shall I send over a screen recording or have a 5-min Zoom call?
Hi Nathan,
Feel free to send over a zoom recording showing me the code and the Data source + security rules.
Thanks,
Deb
Hi , I have the same issue, but with mine, I wanted that everyone will receive a notification once someone added a post or a newsfeed, what the changes would be if I wanted to send to everyone?