-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b211266
commit 8d18135
Showing
21 changed files
with
378 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
export type SlackChannel = 'growth' | 'support'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
import "./subscribers"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
import { SlackService } from "./slack"; | ||
|
||
const slackService = new SlackService(); | ||
|
||
export { | ||
slackService | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
import axios from 'axios' | ||
import { SlackChannel } from '../../domain/slackChannel'; | ||
|
||
export interface ISlackService { | ||
sendMessage (text: string, channel: SlackChannel): Promise<any> | ||
} | ||
|
||
export class SlackService implements ISlackService { | ||
private growthChannelHookUrl: string = 'https://hooks.slack.com/services/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'; | ||
private supportChannelHookUrl: string = 'https://hooks.slack.com/services/THKgeessd/Beese26CQ/mI66effeggeJCNa8bFVOwyAS'; | ||
|
||
constructor () { | ||
|
||
} | ||
|
||
private getWebookUrl (channel: SlackChannel): string { | ||
switch (channel) { | ||
case 'growth': | ||
return this.growthChannelHookUrl; | ||
case 'support': | ||
return this.supportChannelHookUrl; | ||
default: | ||
return ""; | ||
} | ||
} | ||
|
||
sendMessage (text: string, channel: SlackChannel): Promise<any> { | ||
const url: string = this.getWebookUrl(channel); | ||
return axios.post(url, { text }); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
import { IHandle } from "../../../core/domain/events/IHandle"; | ||
import { DomainEvents } from "../../../core/domain/events/DomainEvents"; | ||
import { UserCreatedEvent } from "../../users/domain/events/userCreatedEvent"; | ||
import { NotifySlackChannel } from "../useCases/notifySlackChannel/NotifySlackChannel"; | ||
import { User } from "../../users/domain/user"; | ||
|
||
export class AfterUserCreated implements IHandle<UserCreatedEvent> { | ||
private notifySlackChannel: NotifySlackChannel; | ||
|
||
constructor (notifySlackChannel: NotifySlackChannel) { | ||
this.setupSubscriptions(); | ||
this.notifySlackChannel = notifySlackChannel; | ||
} | ||
|
||
setupSubscriptions(): void { | ||
DomainEvents.register(this.onUserCreatedEvent.bind(this), UserCreatedEvent.name); | ||
} | ||
|
||
private craftSlackMessage (user: User): string { | ||
return `Hey! Guess who just joined us? => ${user.firstName} ${user.lastName}\n | ||
Need to reach 'em? Their email is ${user.email}.` | ||
} | ||
|
||
private async onUserCreatedEvent (event: UserCreatedEvent): Promise<void> { | ||
const { user } = event; | ||
|
||
try { | ||
await this.notifySlackChannel.execute({ | ||
channel: 'growth', | ||
message: this.craftSlackMessage(user) | ||
}) | ||
} catch (err) { | ||
|
||
} | ||
} | ||
} |
10 changes: 5 additions & 5 deletions
10
.../subscription/vinylCreatedSubscription.ts → ...fication/subscribers/AfterVinylCreated.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
import { AfterUserCreated } from "./AfterUserCreated"; | ||
import { notifySlackChannel } from "../useCases/notifySlackChannel"; | ||
import { AfterVinylCreated } from "./AfterVinylCreated"; | ||
|
||
// Subscribers | ||
new AfterUserCreated(notifySlackChannel); | ||
new AfterVinylCreated(); |
22 changes: 22 additions & 0 deletions
22
src/modules/notification/useCases/notifySlackChannel/NotifySlackChannel.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
import { UseCase } from "../../../../core/domain/UseCase"; | ||
import { SlackChannel } from "../../domain/slackChannel"; | ||
import { ISlackService } from "../../services/slack"; | ||
|
||
interface Request { | ||
channel: SlackChannel; | ||
message: string; | ||
} | ||
|
||
export class NotifySlackChannel implements UseCase<Request, Promise<void>> { | ||
private slackService: ISlackService; | ||
|
||
constructor (slackService: ISlackService) { | ||
this.slackService = slackService; | ||
} | ||
|
||
async execute (req: Request): Promise<void> { | ||
await this.slackService.sendMessage(req.message, req.channel); | ||
} | ||
} | ||
|
9 changes: 9 additions & 0 deletions
9
src/modules/notification/useCases/notifySlackChannel/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
import { NotifySlackChannel } from "./NotifySlackChannel"; | ||
import { slackService } from "../../services"; | ||
|
||
const notifySlackChannel = new NotifySlackChannel(slackService); | ||
|
||
export { | ||
notifySlackChannel | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
import "./subscribers"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.