Skip to content

Commit c2048b1

Browse files
committed
refactor(v1): bind email send message support language
1 parent f5af37c commit c2048b1

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

src/v1/controller/user/binding/platform/email/SendMessage.ts

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export class SendMessage extends AbstractController<RequestType, ResponseType> {
2727
type: "string",
2828
format: "email",
2929
},
30+
language: {
31+
type: "string",
32+
nullable: true,
33+
},
3034
},
3135
},
3236
};
@@ -36,12 +40,13 @@ export class SendMessage extends AbstractController<RequestType, ResponseType> {
3640
};
3741

3842
public async execute(): Promise<Response<ResponseType>> {
39-
const { email } = this.body;
43+
const { email, language } = this.body;
44+
4045
const sms = new Email(email, {
4146
tagName: "bind",
42-
subject: "Flat Verification Code",
47+
subject: this.getSubject(language),
4348
htmlBody: (email: string, code: string) =>
44-
`Hello, ${email}! Please enter the verification code within 10 minutes:<br><br><h1 style="text-align:center">${code}</h1><br><br><Currently, Flat is actively under development. If you encounter any issues during usage, please feel free to contact me for feedback. It is growing day by day, and we are delighted to share this joy with you.<br><br>Thanks and Regards,<br>Leo Yang<br>Flat PM<br><a href="mailto:yangliu02@agora.io">yangliu02@agora.io</a>`,
49+
this.getMessage("bind", email, code, language),
4550
});
4651

4752
if (await SendMessage.canSend(email)) {
@@ -88,11 +93,42 @@ export class SendMessage extends AbstractController<RequestType, ResponseType> {
8893
public errorHandler(error: Error): ResponseError {
8994
return this.autoHandlerError(error);
9095
}
96+
97+
private getSubject(language?: string): string {
98+
if (language && language.startsWith("zh")) {
99+
return "Flat 验证码";
100+
} else {
101+
return "Flat Verification Code";
102+
}
103+
}
104+
105+
private getMessage(
106+
type: "register" | "reset" | "bind",
107+
email: string,
108+
code: string,
109+
language?: string,
110+
): string {
111+
const name = email.split("@")[0];
112+
if (language && language.startsWith("zh")) {
113+
if (type === "register") {
114+
return `${name},你好!<br><br>感谢注册 <a href="http://flat.whiteboard.agora.io/">Flat 在线教室</a>,请在10分钟内输入验证码:<br><br><h1 style="text-align:center">${code}</h1><br><br>Flat 是一款<a href="https://github.com/netless-io/flat">开源</a>的在线授课软件,专为个人老师设计。我们努力克制保持简单、清爽、专注课中互动体验,希望可以给你带来愉悦的上课体验。<br><br>目前 Flat 正在积极开发中,如果你在使用过程中遇到问题,欢迎联系我进行反馈。它在一天天长大,我们很高兴与你分享这份喜悦。<br><br>Leo Yang<br>Flat 产品经理<br><a href="mailto:yangliu02@agora.io">yangliu02@agora.io</a>`;
115+
} else {
116+
return `${name},你好!请在10分钟内输入验证码:<br><br><h1 style="text-align:center">${code}</h1><br><br>目前 Flat 正在积极开发中,如果你在使用过程中遇到问题,欢迎联系我进行反馈。它在一天天长大,我们很高兴与你分享这份喜悦。<br><br>Leo Yang<br>Flat 产品经理<br><a href="mailto:yangliu02@agora.io">yangliu02@agora.io</a>`;
117+
}
118+
} else {
119+
if (type === "register") {
120+
return `Hello, ${name}! <br><br>Thank you for registering with <a href="http://flat.whiteboard.agora.io/">Flat Online Classroom</a>. Please enter the verification code within 10 minutes:<br><br><h1 style="text-align:center">${code}</h1><br><br>Flat is an <a href="https://github.com/netless-io/flat">open-source</a> online teaching software designed specifically for freelance teachers. We strive to maintain a simple, refreshing, and focused in-class interactive experience, aiming to provide you with a pleasant teaching experience.<br><br>Currently, Flat is actively under development. If you encounter any issues during usage, please feel free to contact me for feedback. It is growing day by day, and we are delighted to share this joy with you.<br><br>Thanks and Regards,<br>Leo Yang<br>Flat PM<br><a href="mailto:yangliu02@agora.io">yangliu02@agora.io</a>`;
121+
} else {
122+
return `Hello, ${name}! Please enter the verification code within 10 minutes:<br><br><h1 style="text-align:center">${code}</h1><br><br><Currently, Flat is actively under development. If you encounter any issues during usage, please feel free to contact me for feedback. It is growing day by day, and we are delighted to share this joy with you.<br><br>Thanks and Regards,<br>Leo Yang<br>Flat PM<br><a href="mailto:yangliu02@agora.io">yangliu02@agora.io</a>`;
123+
}
124+
}
125+
}
91126
}
92127

93128
interface RequestType {
94129
body: {
95130
email: string;
131+
language?: string;
96132
};
97133
}
98134

0 commit comments

Comments
 (0)