-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNotifySlackChannel.ts
34 lines (27 loc) · 1021 Bytes
/
NotifySlackChannel.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { SubscriberController } from '../../../../shared/core/SubscriberController';
import { ISlackService } from '../../services/slack';
import { Request, Response } from './NotifySlackChannelDTOs';
import { ControllerResult } from '../../../../shared/core/ControllerResult';
type UserCreatedDTO = {
email: string;
username: string;
};
export class NotifySlackChannel extends SubscriberController<Request, Response> {
private slackService: ISlackService;
public constructor(slackService: ISlackService) {
super();
this.slackService = slackService;
}
private static craftSlackMessage(user: UserCreatedDTO): string {
return `Hey! Guess who just joined us? => ${user.username}\n
Need to reach 'em? Their email is ${user.email}.`;
}
protected async executeImpl(event: Request): ControllerResult<Response> {
const { user } = event;
await this.slackService.sendMessage(
NotifySlackChannel.craftSlackMessage(user),
'growth'
);
return { status: 200 };
}
}