Skip to content

Commit 908d568

Browse files
feat: Added the Email send to all team members in case of a webhook r… (#953)
**This MR Adds the Following change** - When A webhook data send gets failed then all the team members of the project gets informed via email.
2 parents 47e05da + 1414fad commit 908d568

File tree

4 files changed

+15419
-11238
lines changed

4 files changed

+15419
-11238
lines changed

apps/queue-manager/src/consumers/send-import-job-data.consumer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ export class SendImportJobDataConsumer extends BaseConsumer {
173173
multiSelectHeadings,
174174
extra: userJob.extra,
175175
name: templateData.name,
176+
projectId: templateData._projectId,
176177
_templateId: userJob._templateId,
177178
authHeaderValue: userJob.authHeaderValue,
178179
callbackUrl: webhookDestination?.callbackUrl,

apps/queue-manager/src/consumers/send-webhook-data.consumer.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
WebhookLogRepository,
2121
WebhookDestinationRepository,
2222
FailedWebhookRetryRequestsRepository,
23+
EnvironmentRepository,
2324
} from '@impler/dal';
2425

2526
import { BaseConsumer } from './base.consumer';
@@ -40,6 +41,7 @@ export class SendWebhookDataConsumer extends BaseConsumer {
4041
private emailService: EmailService = getEmailServiceClass();
4142
private failedWebhookRetryRequestsRepository: FailedWebhookRetryRequestsRepository =
4243
new FailedWebhookRetryRequestsRepository();
44+
private environmentRepository: EnvironmentRepository = new EnvironmentRepository();
4345

4446
async message(message: { content: string }) {
4547
const data = JSON.parse(message.content) as SendWebhookData;
@@ -91,9 +93,9 @@ export class SendWebhookDataConsumer extends BaseConsumer {
9193

9294
await this.makeResponseEntry({
9395
data: response,
96+
projectId: cachedData.projectId,
9497
importName: cachedData.name,
9598
url: cachedData.callbackUrl,
96-
userEmail: cachedData.email,
9799
retryInterval: cachedData.retryInterval,
98100
retryCount: cachedData.retryCount,
99101
allData,
@@ -207,6 +209,7 @@ export class SendWebhookDataConsumer extends BaseConsumer {
207209

208210
return {
209211
_templateId: uploadata._templateId,
212+
projectId: templateData._projectId,
210213
callbackUrl: webhookDestination?.callbackUrl,
211214
chunkSize: webhookDestination?.chunkSize,
212215
name: templateData.name,
@@ -230,22 +233,26 @@ export class SendWebhookDataConsumer extends BaseConsumer {
230233
private async makeResponseEntry({
231234
data,
232235
importName,
236+
projectId,
233237
url,
234238
allData,
235-
userEmail,
236239
retryInterval,
237240
retryCount,
238241
}: {
239242
data: Partial<WebhookLogEntity>;
240243
importName: string;
244+
projectId: string;
241245
url: string;
242-
userEmail: string;
243246
retryCount?: number;
244247
retryInterval?: number;
245248
allData: Record<string, any>;
246249
}) {
247250
const webhookLog = await this.webhookLogRepository.create(data);
248251
if (data.status === StatusEnum.FAILED) {
252+
const environment = await this.environmentRepository.getProjectTeamMembers(projectId);
253+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
254+
// @ts-ignore
255+
const teamMemberEmails = environment.map((teamMember) => teamMember._userId.email);
249256
const emailContents = this.emailService.getEmailContent({
250257
type: 'ERROR_SENDING_WEBHOOK_DATA',
251258
data: {
@@ -256,13 +263,14 @@ export class SendWebhookDataConsumer extends BaseConsumer {
256263
importId: data._uploadId,
257264
},
258265
});
259-
260-
await this.emailService.sendEmail({
261-
to: userEmail,
262-
subject: `${EMAIL_SUBJECT.ERROR_SENDING_WEBHOOK_DATA} ${importName}`,
263-
html: emailContents,
264-
from: process.env.ALERT_EMAIL_FROM,
265-
senderName: process.env.EMAIL_FROM_NAME,
266+
teamMemberEmails.forEach(async (email) => {
267+
await this.emailService.sendEmail({
268+
to: email,
269+
subject: `${EMAIL_SUBJECT.ERROR_SENDING_WEBHOOK_DATA} ${importName}`,
270+
html: emailContents,
271+
from: process.env.ALERT_EMAIL_FROM,
272+
senderName: process.env.EMAIL_FROM_NAME,
273+
});
266274
});
267275

268276
if (retryCount && retryInterval) {

libs/shared/src/types/upload/upload.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export type CommonCachedData = {
6262
authHeaderValue: string;
6363
retryInterval?: number;
6464
retryCount?: number;
65+
projectId: string;
6566
_templateId: string;
6667
allDataFilePath?: string;
6768
recordFormat?: string;

0 commit comments

Comments
 (0)