Skip to content

Commit

Permalink
Bepro 2251 add title of task and add deliverable proposal type to ema…
Browse files Browse the repository at this point in the history
…il (#237)

* add task title to emails

* refactor email subject and body get
  • Loading branch information
vhcsilva authored Aug 23, 2024
1 parent 320544c commit 21111f0
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 22 deletions.
3 changes: 2 additions & 1 deletion src/actions/get-proposal-created-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ export async function action(block: DecodedLog<BountyProposalCreatedEvent['retur
bountyId: dbBounty.id, bountyContractId: dbBounty.contractId,
deliverableId: dbDeliverable.id, deliverableContractId: dbDeliverable.prContractId,
proposalId: createProposal.id, proposalContractId: createProposal.contractId,
actor: proposal.creator
actor: proposal.creator,
title: dbBounty.title,
}
}

Expand Down
1 change: 1 addition & 0 deletions src/actions/get-pullrequest-ready-for-review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export async function action(block: DecodedLog<BountyPullRequestReadyForReviewEv
bountyId: dbBounty.id, bountyContractId: dbBounty.contractId,
deliverableId: dbDeliverable.id, deliverableContractId: pullRequestId,
actor: pullRequest.creator,
title: dbBounty.title,
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {EmailService} from "../email-service/email-service";
import {Templates} from "./templates";
import {EmailNotificationSubjects} from "./templates/email-info";
import {getEmailNotificationSubject} from "./templates/email-info";
import {EmailTemplate} from "../../../services/templating/email-template";
import {users} from "../../../db/models/users";
import {v4 as uuidv4} from "uuid";
import {format} from "node:util"
import {getEventTargets} from "../../../utils/get-event-targets";
import { CollectEventPayloadParams } from "src/services/analytics/types/analytics";
import { AnalyticEventName } from "src/services/analytics/types/events";
Expand All @@ -26,7 +25,7 @@ export class EmailNotification {
for (const [index, to] of recipients.filter(e => e).entries()) {
const uuid = uuidv4();
await EmailService.sendEmail(
format(EmailNotificationSubjects[this.type]!, (this.payload as any)?.network?.name ?? "BEPRO"),
getEmailNotificationSubject(this.type, this.payload),
[to],
new EmailTemplate().compile({...this.payload, type: this.type, template: templateName, uuid})
);
Expand Down
7 changes: 3 additions & 4 deletions src/integrations/send-grid/notifications/templater.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {readFileSync} from "node:fs";
import {join, resolve} from "node:path";
import process from "process";
import {EmailNotificationSubjects} from "./templates/email-info";
import {format} from "node:util";
import {getEmailNotificationBodyTitle, getEmailNotificationSubject} from "./templates/email-info";

export class Templater {

Expand All @@ -22,8 +21,8 @@ export class Templater {
compile(payload: any) {

const templateData = {
pageTitle: format(EmailNotificationSubjects[payload.template], payload.network.name),
notificationTitleHeading: format(EmailNotificationSubjects[payload.template], payload.network.name),
pageTitle: getEmailNotificationSubject(payload.type, payload),
notificationTitleHeading: getEmailNotificationBodyTitle(payload.type, payload),
taskTitleParagraph: payload.title,
actionHref: `https://app.bepro.network/${payload.network.name}/task/${payload.bountyId}/?fromEmail=${payload.uuid}`
};
Expand Down
51 changes: 44 additions & 7 deletions src/integrations/send-grid/notifications/templates/email-info.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,48 @@
import {Templates} from "./index";
import { format } from "node:util";
import { CollectEventPayloadParams } from "src/services/analytics/types/analytics";
import { AnalyticEventName } from "src/services/analytics/types/events";
import { Templates } from "./index";

export const EmailNotificationSubjects: { [k in keyof typeof Templates]: string } = {
BOUNTY_CREATED: "%s @ BEPRO | A task has been created!",
BOUNTY_CLOSED: "%s @ BEPRO | A task has been closed!",
FUNDING_REQUEST_CREATED: "%s @ BEPRO | A funding request has been created!",
PULL_REQUEST_OPEN: `%s @ BEPRO | A new deliverable has been created on "%s"!`,
PULL_REQUEST_READY: `%s @ BEPRO | A deliverable has been marked as ready for review on "%s"!`,
MERGE_PROPOSAL_OPEN: `%s @ BEPRO | A new proposal was created on "%s"!`,
MERGE_PROPOSAL_READY: `%s @ BEPRO | A deliverable is ready to be accepted on "%s"!`,
}

export const EmailNotificationBodyTitles: { [k in keyof typeof Templates]: string } = {
BOUNTY_CREATED: "A task has been created on %s!",
BOUNTY_CLOSED: "A task has bee closed!",
FUNDING_REQUEST_CREATED: "New funding request has been created on %s!",
PULL_REQUEST_OPEN: "A new deliverable has been created!",
PULL_REQUEST_READY: "A deliverable has been marked as \"ready for review\"!",
MERGE_PROPOSAL_OPEN: "A new proposal was created!",
MERGE_PROPOSAL_READY: "A deliverable is ready to be accepted!",
BOUNTY_CLOSED: "A task has been closed on %s!",
FUNDING_REQUEST_CREATED: "A funding request has been created on %s!",
PULL_REQUEST_OPEN: `A new deliverable has been created on "%s"!`,
PULL_REQUEST_READY: `A deliverable has been marked as ready for review on "%s"!`,
MERGE_PROPOSAL_OPEN: `A new proposal was created on "%s"!`,
MERGE_PROPOSAL_READY: `A deliverable is ready to be accepted on "%s"!`,
}

export function getEmailNotificationSubject(type: AnalyticEventName, payload: CollectEventPayloadParams) {
const marketplace = payload.network.name?.toUpperCase();
switch(type) {
case "BOUNTY_CREATED":
case "BOUNTY_CLOSED":
case "FUNDING_REQUEST_CREATED":
return format(EmailNotificationSubjects[type], marketplace);
default:
return format(EmailNotificationSubjects[type], marketplace, payload.title);
}
}

export function getEmailNotificationBodyTitle(type: AnalyticEventName, payload: CollectEventPayloadParams) {
const marketplace = payload.network.name?.toUpperCase();
switch(type) {
case "BOUNTY_CREATED":
case "BOUNTY_CLOSED":
case "FUNDING_REQUEST_CREATED":
return format(EmailNotificationBodyTitles[type], marketplace);
default:
return format(EmailNotificationBodyTitles[type], payload.title);
}
}
10 changes: 3 additions & 7 deletions src/services/templating/email-template.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {EmailNotificationSubjects} from "../../integrations/send-grid/notifications/templates/email-info";
import {format} from "node:util";
import {getEmailNotificationBodyTitle, getEmailNotificationSubject} from "../../integrations/send-grid/notifications/templates/email-info";
import Handlebars from "handlebars";
import {Template} from "./template";

Expand All @@ -10,12 +9,9 @@ export class EmailTemplate extends Template {
}

compile(payload: any) {

const title = format(EmailNotificationSubjects[payload.type], payload?.network?.name ?? "BEPRO");

const templateData = {
pageTitle: title,
notificationTitleHeading: title,
pageTitle: getEmailNotificationSubject(payload.type, payload),
notificationTitleHeading: getEmailNotificationBodyTitle(payload.type, payload),
taskTitleParagraph: payload.title,
actionHref: `https://app.bepro.network/${payload?.network?.name ?? "BEPRO"}/task/${payload.bountyId}/?fromEmail=${payload.uuid}`
};
Expand Down

0 comments on commit 21111f0

Please sign in to comment.