Skip to content

Commit

Permalink
Merge pull request #217 from alkem-io/develop
Browse files Browse the repository at this point in the history
Release: Notification images
  • Loading branch information
valentinyanakiev authored Jun 12, 2023
2 parents bfa328a + 3b17fab commit a29fbf4
Show file tree
Hide file tree
Showing 21 changed files with 223 additions and 29 deletions.
4 changes: 2 additions & 2 deletions lib/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@alkemio/notifications-lib",
"version": "0.4.1",
"version": "0.4.2",
"description": "Library for interacting with Alkemio notifications service",
"author": "Alkemio Foundation",
"private": false,
Expand Down
6 changes: 6 additions & 0 deletions lib/src/dto/community.invitation.created.event.payload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { JourneyBaseEventPayload } from './journey.base.event.payload';

export interface CommunityInvitationCreatedEventPayload
extends JourneyBaseEventPayload {
inviteeID: string;
}
1 change: 1 addition & 0 deletions lib/src/dto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export * from './communication.user.mention.event.payload';
export * from './communication.organization.mention.event.payload';
export * from './community.application.created.event.payload';
export * from './community.new.member.payload';
export * from './community.invitation.created.event.payload';
export * from './collaboration.interest.payload';
export * from './collaboration.canvas.created.event.payload';
export * from './collaboration.card.created.event.payload';
Expand Down
1 change: 1 addition & 0 deletions lib/src/notification.event.type.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export enum NotificationEventType {
COMMUNITY_APPLICATION_CREATED = 'communityApplicationCreated',
COMMUNITY_NEW_MEMBER = 'communityNewMember',
COMMUNITY_INVITATION_CREATED = 'communityInvitationCreated',
COMMUNICATION_COMMENT_SENT = 'communicationCommentSent',
COMMUNICATION_UPDATE_SENT = 'communicationUpdateSent',
COMMUNICATION_USER_MESSAGE = 'communicationUserMessage',
Expand Down
6 changes: 6 additions & 0 deletions service/notifications.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ recipients:
- rule:
type: USER_SELF_MANAGEMENT
resource_id: <memberID>
community_invitation_created:
- name: invitee
rules:
- rule:
type: USER_SELF_MANAGEMENT
resource_id: <inviteeID>
communication_update_sent:
- name: admin
rules:
Expand Down
32 changes: 16 additions & 16 deletions service/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions service/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "alkemio-notifications",
"version": "0.10.0",
"version": "0.10.1",
"description": "Alkemio notifications service",
"author": "Alkemio Foundation",
"private": false,
Expand Down Expand Up @@ -35,8 +35,8 @@
"validate-connection": "ts-node src/utils/validate-connection.ts"
},
"dependencies": {
"@alkemio/client-lib": "^0.18.6",
"@alkemio/notifications-lib": "^0.4.1",
"@alkemio/client-lib": "^0.19.3",
"@alkemio/notifications-lib": "^0.4.2",
"@nestjs/common": "^8.0.5",
"@nestjs/config": "^1.0.1",
"@nestjs/core": "^8.0.5",
Expand Down
15 changes: 15 additions & 0 deletions service/src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
CollaborationCanvasCreatedEventPayload,
CollaborationDiscussionCommentEventPayload,
PlatformForumDiscussionCommentEventPayload,
CommunityInvitationCreatedEventPayload,
} from '@alkemio/notifications-lib';
import { NotificationService } from './services/domain/notification/notification.service';
import { ALKEMIO_CLIENT_ADAPTER, LogContext } from './common/enums';
Expand Down Expand Up @@ -62,6 +63,20 @@ export class AppController {
);
}

@EventPattern(NotificationEventType.COMMUNITY_INVITATION_CREATED)
async sendInvitationNotification(
// todo is auto validation possible
@Payload() eventPayload: CommunityInvitationCreatedEventPayload,
@Ctx() context: RmqContext
) {
this.sendNotifications(
eventPayload,
context,
this.notificationService.sendInvitationCreatedNotifications(eventPayload),
NotificationEventType.COMMUNITY_INVITATION_CREATED
);
}

@EventPattern(NotificationEventType.COMMUNITY_NEW_MEMBER)
async sendCommunityNewMemberNotification(
// todo is auto validation possible
Expand Down
2 changes: 2 additions & 0 deletions service/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
} from './services/application';
import { CollaborationCanvasCreatedNotificationBuilder } from './services/domain/builders/collaboration-canvas-created/collaboration.canvas.created.notification.builder';
import { CollaborationDiscussionCommentNotificationBuilder } from './services/domain/builders/collaboration-discussion-comment/collaboration.discussion.comment.notification.builder';
import { CommunityInvitationCreatedNotificationBuilder } from './services/domain/builders/community-invitation-created/community.invitation.created.notification.builder';

@Module({
imports: [
Expand All @@ -61,6 +62,7 @@ import { CollaborationDiscussionCommentNotificationBuilder } from './services/do
},
NotificationBuilder,
CommunityApplicationCreatedNotificationBuilder,
CommunityInvitationCreatedNotificationBuilder,
PlatformUserRegisteredNotificationBuilder,
PlatformUserRemovedNotificationBuilder,
PlatformForumDiscussionCommentNotificationBuilder,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { BaseJourneyEmailPayload } from './base.journey.email.payload';

export interface CommunityInvitationCreatedEmailPayload
extends BaseJourneyEmailPayload {
inviter: {
name: string;
firstName: string;
email: string;
profile: string;
};
journeyAdminURL: string;
}
1 change: 1 addition & 0 deletions service/src/common/email-template-payload/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './base.email.payload';
export * from './base.journey.email.payload';
export * from './community.application.created.email.payload';
export * from './community.invitation.created.email.payload';
export * from './community.new.member.email.payload';
export * from './collaboration.canvas.created.email.payload';
export * from './collaboration.card.comment.email.payload';
Expand Down
3 changes: 3 additions & 0 deletions service/src/common/enums/email.template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ export enum EmailTemplate {
COMMUNITY_NEW_MEMBER_MEMBER = 'community.new.member.member',
COMMUNITY_USER_APPLICATION_APPLICANT = 'community.user.application.applicant',
COMMUNITY_USER_APPLICATION_ADMIN = 'community.user.application.admin',
COMMUNITY_INVITATION_ADMIN = 'community.invitation.created.admin',
COMMUNITY_INVITATION_INVITEE = 'community.invitation.created.invitee',
COMMUNITY_INVITATION_INVITER = 'community.invitation.created.inviter',
COMMUNICATION_UPDATE_ADMIN = 'communication.update.admin',
COMMUNICATION_UPDATE_MEMBER = 'communication.update.member',
COMMUNICATION_USER_MESSAGE_SENDER = 'communication.user.message.sender',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type TemplateRuleSet = {

export type TemplateConfig = {
community_application_created?: TemplateRuleSet[];
community_invitation_created?: TemplateRuleSet[];
community_new_member?: TemplateRuleSet[];
communication_update_sent?: TemplateRuleSet[];
platform_forum_discussion_created?: TemplateRuleSet[];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { Injectable, Inject } from '@nestjs/common';
import { NotificationEventType } from '@alkemio/notifications-lib';
import { INotificationBuilder } from '@core/contracts';
import { User } from '@core/models';
import { CommunityInvitationCreatedEventPayload } from '@alkemio/notifications-lib';
import {
AlkemioUrlGenerator,
NotificationBuilder,
RoleConfig,
} from '../../../application';
import { NotificationTemplateType } from '@src/types';
import { EmailTemplate } from '@common/enums/email.template';
import { CommunityInvitationCreatedEmailPayload } from '@common/email-template-payload';
import { ALKEMIO_URL_GENERATOR } from '@src/common/enums/providers';
import { UserPreferenceType } from '@alkemio/client-lib';

@Injectable()
export class CommunityInvitationCreatedNotificationBuilder
implements INotificationBuilder
{
constructor(
@Inject(ALKEMIO_URL_GENERATOR)
private readonly alkemioUrlGenerator: AlkemioUrlGenerator,
private readonly notificationBuilder: NotificationBuilder<
CommunityInvitationCreatedEventPayload,
CommunityInvitationCreatedEmailPayload
>
) {}

build(
payload: CommunityInvitationCreatedEventPayload
): Promise<NotificationTemplateType[]> {
const roleConfig: RoleConfig[] = [
{
role: 'invitee',
emailTemplate: EmailTemplate.COMMUNITY_INVITATION_INVITEE,
preferenceType: UserPreferenceType.NotificationCommunityInvitationUser,
},
];

const templateVariables = {
inviterID: payload.triggeredBy,
inviteeID: payload.inviteeID,
hubID: payload.journey.hubID,
challengeID: payload.journey.challenge?.id ?? '',
opportunityID: payload.journey.challenge?.opportunity?.id ?? '',
};

return this.notificationBuilder.build({
payload,
eventUserId: payload.triggeredBy,
roleConfig,
templateType: 'community_invitation_created',
templateVariables,
templatePayloadBuilderFn: this.createTemplatePayload.bind(this),
});
}

private createTemplatePayload(
eventPayload: CommunityInvitationCreatedEventPayload,
recipient: User,
inviter?: User
): CommunityInvitationCreatedEmailPayload {
if (!inviter) {
throw Error(
`Invitee not provided for '${NotificationEventType.COMMUNITY_INVITATION_CREATED} event'`
);
}
const inviterProfileURL = this.alkemioUrlGenerator.createUserURL(
inviter.nameID
);
const communityURL = this.alkemioUrlGenerator.createJourneyURL(
eventPayload.journey
);
const communityAdminURL =
this.alkemioUrlGenerator.createJourneyAdminCommunityURL(
eventPayload.journey
);
const notificationPreferenceURL =
this.alkemioUrlGenerator.createUserNotificationPreferencesURL(
recipient.nameID
);
const alkemioURL = this.alkemioUrlGenerator.createPlatformURL();
return {
emailFrom: '[email protected]',
inviter: {
firstName: inviter.firstName,
name: inviter.profile.displayName,
email: inviter.email,
profile: inviterProfileURL,
},
journeyAdminURL: communityAdminURL,
recipient: {
firstName: recipient.profile.displayName,
email: recipient.email,
notificationPreferences: notificationPreferenceURL,
},
journey: {
displayName: eventPayload.journey.displayName,
type: eventPayload.journey.type,
url: communityURL,
},
platform: {
url: alkemioURL,
},
};
}
}
1 change: 1 addition & 0 deletions service/src/services/domain/builders/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './community-application-created/community.application.created.notification.builder';
export * from './community-invitation-created/community.invitation.created.notification.builder';
export * from './communication-update-created/communication.update.created.notification.builder';
export * from './communication-user-message/communication.user.message.notification.builder';
export * from './communication-organization-message/communication.organization.message.notification.builder';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
CollaborationCalloutPublishedNotificationBuilder,
PlatformUserRemovedNotificationBuilder,
PlatformForumDiscussionCommentNotificationBuilder,
CommunityInvitationCreatedNotificationBuilder,
} from '../builders';
import { AlkemioUrlGenerator } from '@src/services/application/alkemio-url-generator';
import {
Expand Down Expand Up @@ -71,6 +72,7 @@ describe('NotificationService', () => {
NotificationRecipientsYmlAdapter,
NotificationService,
CommunityApplicationCreatedNotificationBuilder,
CommunityInvitationCreatedNotificationBuilder,
PlatformUserRegisteredNotificationBuilder,
PlatformForumDiscussionCommentNotificationBuilder,
PlatformUserRemovedNotificationBuilder,
Expand Down
Loading

0 comments on commit a29fbf4

Please sign in to comment.