-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[recnet-api] Update slack message template #359
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 2 Skipped Deployments
|
Example import { generateMock } from "@anatine/zod-mock";
import { Body, Controller, HttpStatus, Inject, Post } from "@nestjs/common";
import { ConfigType } from "@nestjs/config";
import {
ApiBody,
ApiCreatedResponse,
ApiOperation,
ApiTags,
} from "@nestjs/swagger";
import { AppConfig } from "@recnet-api/config/common.config";
import UserRepository from "@recnet-api/database/repository/user.repository";
import { RecnetError } from "@recnet-api/utils/error/recnet.error";
import { ErrorCode } from "@recnet-api/utils/error/recnet.error.const";
import { getLatestCutOff } from "@recnet/recnet-date-fns";
import { announcementSchema, recSchema } from "@recnet/recnet-api-model";
import { WeeklyDigestContent } from "./subscription.type";
import { SlackService } from "../slack/slack.service";
@ApiTags("subscriptions")
@Controller("subscriptions")
export class SubscriptionController {
constructor(
@Inject(AppConfig.KEY)
private readonly appConfig: ConfigType<typeof AppConfig>,
private readonly slackService: SlackService,
private readonly userRepository: UserRepository
) {}
/* Development only */
@ApiOperation({
summary: "Send weekly digest slack to the designated user.",
description: "This endpoint is for development only.",
})
@ApiCreatedResponse()
@ApiBody({
schema: {
properties: {
userId: { type: "string" },
},
required: ["userId"],
},
})
@Post("slack/test")
public async testSendingWeeklyDigest(
@Body("userId") userId: string
): Promise<void> {
if (this.appConfig.nodeEnv === "production") {
throw new RecnetError(
ErrorCode.INTERNAL_SERVER_ERROR,
HttpStatus.INTERNAL_SERVER_ERROR,
"This endpoint is only for development"
);
}
function getMockWeeklyDigestData(): WeeklyDigestContent {
const getMockRec = (title = 1) =>
generateMock(recSchema, {
stringMap: {
photoUrl: () => "https://avatar.iran.liara.run/public",
title: () => `Paper Title ${title}`,
},
});
const announcement = generateMock(announcementSchema, {
stringMap: {
content: () => "This is a test announcement!",
},
});
return {
recs: [getMockRec(), getMockRec(2), getMockRec(3), getMockRec()],
numUnusedInviteCodes: 3,
latestAnnouncement: {
...announcement,
startAt: new Date(announcement.startAt),
endAt: new Date(announcement.endAt),
},
};
}
const cutoff = getLatestCutOff();
const user = await this.userRepository.findUserById(userId);
const content = getMockWeeklyDigestData();
this.slackService.sendWeeklyDigest(user, content, cutoff);
}
} |
@@ -97,10 +97,12 @@ export class SlackTransporter { | |||
); | |||
} | |||
|
|||
const notificationText = `📬 Your RecNet weekly digest has arrived!`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This SlackTransporter class is designed to send messages for general purposes. I suggest putting this text into the template to create a better logic boundary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. I forget to extract this part.
I'll add the test subscription API back once this PR is merged. |
## RecNet auto-release action This is an auto-generated PR by recnet-release-action 🤖 Please make sure to test your changes in staging before merging. ## Related Issues - #261 - #64 - #356 - #355 ## Related PRs - #359 - #357 - #358 ## Staging links recnet-web: [https://vercel.live/link/recnet-git-dev-recnet-542617e7.vercel.app](https://vercel.live/link/recnet-git-dev-recnet-542617e7.vercel.app) recnet-api: [https://dev-api.recnet.io/api](https://dev-api.recnet.io/api)
Description
Beautify slack weekly digest template
Related Issue
Notes
Misc: I think we should add email and slack testing API endpoints back to ease the development, but I am not sure where to add it, maybe create
subscription.controller.ts
again? @joannechen1223Test
You will need to add back the
POST /subsriptions/slack/test
endpoint to test. I will provide example code below in the comment to show how I use mock data to test it.Screenshots (if appropriate):
The data in the screenshot were generated by
generateMock()
.TODO
console.log
orconsole.error
for debug usagerecnet-docs
if needed