Skip to content

Commit 6ecaa88

Browse files
committed
feat: update
1 parent b5774c8 commit 6ecaa88

File tree

11 files changed

+78
-21
lines changed

11 files changed

+78
-21
lines changed

client/src/components/pages/flow-detail/node-dialog/message.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,20 @@ export const MessageDialogContent = () => {
113113
</Select>
114114
</div>
115115
<div className='space-y-2'>
116-
<Label required>{t('message_dialog.forms.bot_response.label')}</Label>
116+
<Label required>{t('forms:bot_response.label')}</Label>
117117
{messageType === EMessageTypes.TEXT && (
118-
<Input
119-
placeholder={t('message_dialog.forms.bot_response.placeholder')}
120-
value={botResponse}
121-
onChange={(e) => {
122-
setBotResponse(e.target.value)
123-
}}
124-
/>
118+
<>
119+
<Input
120+
placeholder={t('forms:bot_response.placeholder')}
121+
value={botResponse}
122+
onChange={(e) => {
123+
setBotResponse(e.target.value)
124+
}}
125+
/>
126+
<p className='text-[0.8rem] text-muted-foreground'>
127+
{t('forms:bot_response.description')}
128+
</p>
129+
</>
125130
)}
126131
{messageType === EMessageTypes.IMAGE && (
127132
<InputImage

client/src/locales/en/forms.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@
142142
"required": "Please enter button label."
143143
}
144144
},
145+
"bot_response": {
146+
"label": "Bot Response",
147+
"placeholder": "Type your bot response here",
148+
"errors": {
149+
"required": "Please enter bot response."
150+
},
151+
"description": "To access variable values, use {variable_name}, {variable_name->key}, {variable_name->0->key}, etc. {user->name} retrieves the 'name' key of the 'user' variable. For an array 'users' with an object at index 0 and a 'name' key, use {users->0->name}."
152+
},
145153
"button_url": {
146154
"label": "Button URL",
147155
"placeholder": "Enter button URL",

client/src/locales/vi/forms.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,5 +360,13 @@
360360
"errors": {
361361
"required": "Vui lòng chọn biến đầu ra."
362362
}
363+
},
364+
"bot_response": {
365+
"label": "Bot trả lời",
366+
"placeholder": "Nhập câu trả lời của bot",
367+
"errors": {
368+
"required": "Vui lòng nhập câu trả lời của bot."
369+
},
370+
"description": "Để truy cập các giá trị biến, hãy sử dụng {variable_name}, {variable_name->key}, {variable_name->0->key}, v.v. {user->name} lấy khóa 'name' của biến 'user'. Đối với mảng 'người dùng' có đối tượng ở chỉ mục 0 và khóa 'tên', hãy sử dụng {users->0->name}."
363371
}
364372
}

server/src/constants/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export const ENDPOINTS = {
3939
SETTING: {
4040
INDEX: '/setting',
4141
MAIL: '/setting/email',
42+
BY_CONTACT_ID: '/setting/by-contact-id/:contactId',
4243
},
4344
USER: {
4445
UPDATE_INFO: '/user/update-info',
@@ -59,7 +60,7 @@ export const ENDPOINTS = {
5960
ADD_CHANNELS: '/flow/add-channels',
6061
SELECT_FLOWS_FOR_CHANNEL: '/flow/select',
6162
BOT_GET_CONTACT_ID: '/bot/flow/:contactId',
62-
BOT_GET_ID: '/bot/flow/:id'
63+
BOT_GET_ID: '/bot/flow/:id',
6364
},
6465
INTENT: {
6566
INDEX: '/intent',

server/src/controllers/setting.controller.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { StatusCodes } from 'http-status-codes'
77
import Container from 'typedi'
88

99
export class SettingController {
10-
private settingService = Container.get(SettingService)
11-
private localeService: LocaleService = Container.get(LOCALE_KEY)
10+
private readonly settingService = Container.get(SettingService)
11+
private readonly localeService: LocaleService = Container.get(LOCALE_KEY)
1212

1313
public getSetting = catchAsync(async (req: RequestWithUser, res) => {
1414
const setting = await this.settingService.findByUserId(req.user.id)
@@ -29,4 +29,13 @@ export class SettingController {
2929
message: this.localeService.i18n().SETTING.UPDATE_EMAIL_SUCCESS(),
3030
})
3131
})
32+
33+
public getByContactId = catchAsync(async (req, res) => {
34+
const setting = await this.settingService.findByContactId(
35+
req.params.contactId,
36+
)
37+
res.status(StatusCodes.OK).json({
38+
data: setting,
39+
})
40+
})
3241
}

server/src/dtos/bot-mail.dto.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { TTemplate } from '@/mail/send-mail'
21
import { IsEmail, IsNotEmpty, IsObject, IsString } from 'class-validator'
32

43
export class BotMailDto {
@@ -18,7 +17,7 @@ export class BotMailDto {
1817

1918
@IsString()
2019
@IsNotEmpty()
21-
template: TTemplate
20+
template: string
2221

2322
@IsObject()
2423
variables: Record<string, any>

server/src/mail/send-mail.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ const MAP_TEMPLATES: TMapTemplates = {
2424

2525
export type TTemplate = keyof TemplateProps
2626

27-
export const sendMail = async <T extends keyof TemplateProps>(opts: {
27+
export const sendMail = async <
28+
T extends keyof TemplateProps = keyof TemplateProps & string,
29+
>(opts: {
2830
to: string
2931
subject: string
3032
template: T
31-
props: TemplateProps[T]
33+
props: T extends keyof TemplateProps ? TemplateProps[T] : any
3234
from?: string
3335
user?: string
3436
pass?: string
@@ -43,7 +45,9 @@ export const sendMail = async <T extends keyof TemplateProps>(opts: {
4345
from = MAIL_USER,
4446
} = opts
4547
try {
46-
const html = MAP_TEMPLATES[template](props)
48+
const isNotInKey = !Object.keys(MAP_TEMPLATES).includes(template)
49+
50+
const html = isNotInKey ? template : MAP_TEMPLATES[template](props)
4751

4852
const transporter = nodemailer.createTransport({
4953
service: 'gmail',

server/src/routes/setting.route.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,10 @@ export class SettingRoute implements Routes {
2929
authMiddleware,
3030
this.controller.updateEmailSetting,
3131
)
32+
33+
this.router.get(
34+
ENDPOINTS.SETTING.BY_CONTACT_ID,
35+
this.controller.getByContactId,
36+
)
3237
}
3338
}

server/src/services/bot-mail.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class BotMailService {
3030
to,
3131
props: variables as any,
3232
subject,
33-
template,
33+
template: template as any,
3434
pass: password,
3535
user: email,
3636
})

server/src/services/channels.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export class ChannelService {
9797
channelType: channelTypes.name,
9898
credentials: channels.credentials,
9999
flowId: channels.flowId,
100+
userId: channels.userId,
100101
})
101102
.from(channels)
102103
.where(

0 commit comments

Comments
 (0)