Dynamic values on a Audiences?

We have a SaaS product where we have many companies and each company will have many projects.

We are playing with Audiences and Preferences and it looks like we need to create a Audience for each of the company in our system.

// Audiences ID = `company-CompanyOneID`
{
  "operator": "INCLUDES",
  "path": "company_ids",
  "value": "CompanyOneID"
}
await courier.send({
  message: {
    to: { audience_id: 'company-CompanyOneID' },
    template: '123456',
    data: req.body,
  },
  routing: { method: 'all', channels: ['direct_message', 'push', 'email'] },
});
// User Profiles
{
  "profile": {
    "id": "JoeID",
    "email": "joe@company-one.com",
    "company_ids": ["CompanyOneID"],
    "project_ids": ["project_1", "project_3", "project_7"]
  }
}
{
  "profile": {
    "id": "SamID",
    "email": "sam@company-one.com",
    "company_ids": ["CompanyOneID"],
    "project_ids": ["project_1", "project_200"]
  }
}

What I am struggling with is how should we send notifications to users when a project changes. On the profiles we will keep track of what projects the user wants to be notified on.

// Audiences ID = `user-projects-CompanyOneId`
{
  operator: 'AND',
  filters: [
    {
      operator: 'INCLUDES',
      path: 'company_ids',
      value: "CompanyOneID",
    },
    {
      operator: 'INCLUDES',
      path: 'project_ids',
      value: 'project_1', // <-- Could this be dynamic when a Audience is triggered
    },
  ],
}
await courier.send({
  message: {
    to: {
      audience_id: 'user-projects-CompanyOneId',
      // It would be nice to send a dynamic value with this Audience.
      // Or if we could send a dynamic Audience Operator.
    },
    template: 'abcdefg',
    data: req.body,
  },
  routing: { method: 'all', channels: ['direct_message', 'push', 'email'] },
});

There is two ways I can think of but there must be a better way?

  1. Create an Audience for every project that needs a notification or create a Audience for each profile and update it when the user adds/removes projects. (These seem like a bad ideas)
  2. Right before we call courier.send on the a Audience we call courier.audiences.put and update the value for the 'project_ids' and cross our fingers nothing gets out of sync.

I have #2 working as a Proof of Concept, but I think it is a bad idea to handle hundreds of projects that way. Please help me figure out a solution.

Hey there @robert - Since Audiences and Profiles work hand-in-hand, the profiles that make up part of an audience would need to include at least the CompanyOneID. Could you please elaborate a bit more by what you mean regarding a dynamic value in your audience? It’s possible this is a feature request since audience rules are there to filter user profiles based on specific values. If a user profile changes the values that once made it part of an audience, then it can automatically fall out of an audience, and at the same time, fall into another audience. Since the audience values are the source of truth, I’m curious by how you would want those to be dynamic. Looking forward to hearing back!

You’re right this sounds like a feature request and that is not what I really want. I just want to send notifications to users that have a specific project id in their profile. I thought the Audience API would be good for that but it seems I would have create an Audience for every project in our system which is not ideal because we will have hundreds or even thousand of projects.

I thought maybe I could use Bulk Messaging but realized there is no way to get a list of user profiles so I could filter on the data.


Too sum up what we want to do is to send a notification to users that have a certain project id in the project_ids property in their profile.

For a proof of concept I used the List API for users to subscribe/unsubscribe to a project. We will end up with hundreds of lists (one list per project) but I think this might be only way to do it in courier?

Hey @robert :wave: - I see this as a good possibility for your use case. You can have a list of users that are part of project x and invoke that list in your API /send call with the list_id.

It would be nicer if the filter values on audiences could be dynamic. This way I would only have one Audience, pass it the project id value for project_ids when I call send(). Then I only need to make sure the user profiles are update to date. Can I make this a feature request?

Thanks