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?
- 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)
- Right before we call
courier.send
on the a Audience we callcourier.audiences.put
and update thevalue
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.