improve: add profile to notifications templates eg {{profile.email}}
This commit is contained in:
@@ -13,6 +13,7 @@ import type {
|
|||||||
IServiceCreateEventPayload,
|
IServiceCreateEventPayload,
|
||||||
IServiceEvent,
|
IServiceEvent,
|
||||||
} from './event.service';
|
} from './event.service';
|
||||||
|
import { getProfileById, getProfileByIdCached } from './profile.service';
|
||||||
import { getProjectByIdCached } from './project.service';
|
import { getProjectByIdCached } from './project.service';
|
||||||
|
|
||||||
type ICreateNotification = Pick<
|
type ICreateNotification = Pick<
|
||||||
@@ -220,7 +221,10 @@ function notificationTemplateEvent({
|
|||||||
const value = pathOr('', path.split('.'), payload);
|
const value = pathOr('', path.split('.'), payload);
|
||||||
|
|
||||||
if (value) {
|
if (value) {
|
||||||
template = template.replaceAll(match, JSON.stringify(value));
|
template = template.replaceAll(
|
||||||
|
match,
|
||||||
|
typeof value === 'object' ? JSON.stringify(value) : value,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,6 +249,22 @@ export async function checkNotificationRulesForEvent(
|
|||||||
) {
|
) {
|
||||||
const project = await getProjectByIdCached(payload.projectId);
|
const project = await getProjectByIdCached(payload.projectId);
|
||||||
const rules = await getNotificationRulesByProjectId(payload.projectId);
|
const rules = await getNotificationRulesByProjectId(payload.projectId);
|
||||||
|
|
||||||
|
// If profile is present in the template, add it to the payload (event)
|
||||||
|
// so we can use it in the template
|
||||||
|
if (
|
||||||
|
payload.profileId &&
|
||||||
|
rules.some((rule) => rule.template?.match(/{{profile\.[^}]*}}/))
|
||||||
|
) {
|
||||||
|
const profile = await getProfileByIdCached(
|
||||||
|
payload.profileId,
|
||||||
|
payload.projectId,
|
||||||
|
);
|
||||||
|
if (profile) {
|
||||||
|
(payload as any).profile = profile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
rules.flatMap((rule) => {
|
rules.flatMap((rule) => {
|
||||||
if (rule.config.type === 'events') {
|
if (rule.config.type === 'events') {
|
||||||
|
|||||||
Reference in New Issue
Block a user