Skip to content

Commit b53217a

Browse files
chore(event-email): event email notification now contains link to a particular repetition (#499) (#502)
* Add repetitionId to event notification flow Introduces the repetitionId field to event notification data structures and templates, allowing emails and notifications to reference specific event repetitions. Updates TypeScript interfaces, worker logic, and email templates to support and display repetitionId where applicable. * fix grouper test Co-authored-by: Peter <specc.dev@gmail.com>
1 parent 8160eee commit b53217a

9 files changed

Lines changed: 34 additions & 3 deletions

File tree

workers/email/src/templates/emails/event/html.twig

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
{% set utmParams = 'utm_source=email&utm_medium=transactional&utm_campaign=event' %}
99

1010
{% set event = events[0].event %}
11+
{% set repetitionId = events[0].repetitionId %}
1112
{% set daysRepeated = events[0].daysRepeated %}
1213
{% set newCount = events[0].newCount %}
1314
{% set usersAffected = events[0].usersAffected %}
@@ -56,7 +57,11 @@
5657

5758
<tr>
5859
<td style="padding-top: 30px;padding-right: 20px;padding-left: 20px;padding-bottom: 40px;">
59-
{% set eventURL = host ~ '/project/' ~ project._id ~ '/event/' ~ event._id ~ '?' ~ utmParams %}
60+
{% if repetitionId %}
61+
{% set eventURL = host ~ '/project/' ~ project._id ~ '/event/' ~ event._id ~ '/' ~ repetitionId ~ '/overview?' ~ utmParams %}
62+
{% else %}
63+
{% set eventURL = host ~ '/project/' ~ project._id ~ '/event/' ~ event._id ~ '?' ~ utmParams %}
64+
{% endif %}
6065
{% include '../../components/button.twig' with {href: eventURL, label: 'Смотреть детали'} %}
6166
</td>
6267
</tr>

workers/email/src/templates/emails/event/text.twig

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{% set event = events[0].event %}
2+
{% set repetitionId = events[0].repetitionId %}
23
{% set daysRepeated = events[0].daysRepeated %}
34
{% set newCount = events[0].newCount %}
45
{% set usersAffected = events[0].usersAffected %}
@@ -25,7 +26,11 @@
2526

2627
Это событие произошло {{ event.totalCount }} {{ pluralize_ru(event.totalCount, ['раз', 'раза', 'раз']) }} за {{ daysRepeated }} {{ pluralize_ru(daysRepeated, ['день', 'дня', 'дней']) }}.
2728

28-
Смотреть детали: {{ host }}/project/{{ project._id }}/event/{{ event._id }}?{{ utmParams }}
29+
{% if repetitionId %}
30+
Смотреть детали: {{ host }}/project/{{ project._id }}/event/{{ event._id }}/{{ repetitionId }}/overview?{{ utmParams }}
31+
{% else %}
32+
Смотреть детали: {{ host }}/project/{{ project._id }}/event/{{ event._id }}/overview?{{ utmParams }}
33+
{% endif %}
2934

3035
***
3136

workers/grouper/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ export default class GrouperWorker extends Worker {
265265
title: task.payload.title,
266266
groupHash: uniqueEventHash,
267267
isNew: isFirstOccurrence,
268+
repetitionId: repetitionId ? repetitionId.toString() : null,
268269
},
269270
});
270271
}

workers/grouper/tests/index.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,7 @@ describe('GrouperWorker', () => {
734734
title: task.payload.title,
735735
groupHash: expect.any(String),
736736
isNew: true,
737+
repetitionId: null,
737738
},
738739
});
739740

workers/notifier/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ export default class NotifierWorker extends Worker {
160160
await this.sendToSenderWorker(channelKey, [ {
161161
key: event.groupHash,
162162
count: 1,
163+
repetitionId: event.repetitionId,
163164
} ]);
164165
}
165166
}

workers/notifier/types/channel.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ export interface SenderData {
3535
* Number of events received
3636
*/
3737
count: number;
38+
39+
/**
40+
* ID of the repetition that triggered this notification
41+
* null for first occurrence, ObjectId string for repetitions
42+
*/
43+
repetitionId: string | null;
3844
}
3945

4046
/**

workers/notifier/types/notifier-task.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ export type NotifierEvent = Pick<EventData<EventAddons>, 'title'> & {
1414
* Flag to show if event is received first time
1515
*/
1616
isNew: boolean;
17+
18+
/**
19+
* ID of the repetition that triggered this notification
20+
* null for first occurrence, string for repetitions
21+
*/
22+
repetitionId: string | null;
1723
};
1824

1925
/**

workers/sender/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,14 @@ export default abstract class SenderWorker extends Worker {
171171

172172
const eventsData = await Promise.all(
173173
events.map(
174-
async ({ key: groupHash, count }: { key: string; count: number }): Promise<TemplateEventData> => {
174+
async ({ key: groupHash, count, repetitionId }: { key: string; count: number; repetitionId?: string | null }): Promise<TemplateEventData> => {
175175
const [event, daysRepeated] = await this.getEventDataByGroupHash(projectId, groupHash);
176176

177177
return {
178178
event,
179179
newCount: count,
180180
daysRepeated,
181+
repetitionId: repetitionId ?? null,
181182
};
182183
}
183184
)

workers/sender/types/template-variables/event.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ export interface TemplateEventData {
2525
* Number of affected users for this event
2626
*/
2727
usersAffected?: number;
28+
29+
/**
30+
* ID of the particular repetition of occurred event
31+
*/
32+
repetitionId?: string | null;
2833
}
2934

3035
/**

0 commit comments

Comments
 (0)