Automate/trigger push notification

Hi there

I am looking to automate certain push notifications based on whether data is present in a data source for a specific user. In this example, once a document has been uploaded and added to the data source, I would like a notification to be sent (just once) to that individual user letting them know a document is ready for them to view.

Thanks,
Nathan

1 Like

SAME! - Let me know if someone can help with the scripting/coding

Hi Nathan and Chase

The easiest way to send a notification when a record is created in a data source is using a data source hook. They’re fairly easy to configure. https://developers.fliplet.com/Data-Source-Hooks.html#data-source-hooks

Let me know if this will work for you?

Alternatively you can use a form afterSubmit hook to send a notification using the Communication Javascript API Communicate JS APIs | Fliplet Developers Documentation

If you bave any other questions please reply.

Thanks Ian. Having gone with the data source hook method I came up with the following to add to the data source hooks field in the Settings:

  {
    "type": "email",
    "appId": [REMOVED],
    "runOn": [
      "insert"
    ],
    "payload": {
      "to": [
        {
          "name": "{{ Full name }}",
          "type": "to",
          "email": "{{ Email }}"
        }
      ],
      "html": "<h1>Your draft Will is ready for review, {{ First name }}.</h1><p>Head to the My Docs section of the app to access your Will.</p>",
      "subject": "A document is ready for your review"
    },
    "conditions": [
      {
        "Will": {
          "$exists": "true"
        }
      }
    ]
  }

The idea is to send an email to the user when a document has been uploaded to the datasource to the ‘Will’ column.

Still getting to grips with when to use ‘{{’, ‘{{{’ or '{{ ’ but tried with each method and couldn’t get it to work. I know I’ll be missing something but can’t see what. Any ideas?

Hi Nathan

Does everything work if you exclude the conditions section? If so we know which section of the hook is having issues.

It doesn’t. I’ve also tried adding in hard values to the email and name fields. Some further information that might help - the app’s aren’t live yet and the data is being submitted to the datasource from a form in a separate admin app (all to the same single datasource though).

Hi Nathan
When the column you are referencing has a space inside it then handlebars require you to wrap the string in square brackets i.e. {{[foo bar]}} if you are trying to access {“foo bar”: “baz”}. So in your case it’ll be “name”: “{{ [Full name] }}” and {{ [First name] }}.

1 Like

Thanks for clarifying that aspect Yuliia! Still no luck executing it.

Hi Nathan,

Can you try this? I have tested this hook and it is working as expected.

{
    "type": "email",
    "runOn": [
      "insert"
    ],
    "payload": {
      "to": [
        {
          "name": "{{ [Full name] }}",
          "type": "to",
          "email": "{{ [Email] }}"
        }
      ],
      "html": "<h1>Your draft Will is ready for review, {{ [First name] }}.</h1><p>Head to the My Docs section of the app to access your Will.</p>",
      "subject": "A document is ready for your review"
    },
    "conditions": [
      {
        "Will": {
          "$ne": null
        }
      }
    ]
  }

Also can I ask how you are writing the data to the DS? Are you using custom code to insert the data or using a form to enter the data?

Thanks,
Deb

Hi Deb - apologies for the delayed response. The data is written by an admin app (form component) to a datasource, this should then hopefully trigger the notification in the client-side mobile app. I will try the above code in the datasource and let you know.

Hi Deb - couldn’t get that working but think it must be my mistake somewhere. Is there any chance we could chat briefly over Zoom? Alternatively, would it help you looking at the app/datasource in question?

Hi Deb - thanks for your help with this. Your code worked but I had mistakenly left it as “runOn”: [“insert”] but from the screenshot you will see I was updating, not inserting. Works great!

Last minor point, the email in my inbox is from Fliplet - is there a way to change that name?

Screenshot 2022-05-20 at 11.45.04

Hi Nathan,

Glad to hear you got it working now.

If you want to change the name you need to use the

from_name: 'Hello'

property to set this.