Skip to content

Commit 8935e89

Browse files
authored
Merge pull request #90 from Dialogue-Bot/DIAL-42-implement-test-your-bot
Dial 42 implement test your bot
2 parents 717b8f1 + d79d01e commit 8935e89

File tree

18 files changed

+168
-35
lines changed

18 files changed

+168
-35
lines changed

client/src/components/forms/variables-setting.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export const VariablesSettingForm = ({
120120

121121
if (
122122
!_.isEmpty(form.formState.errors.variables) ||
123-
variablesWatch?.some((field) => !field.name || !field.value)
123+
variablesWatch?.some((field) => !field.name)
124124
)
125125
return
126126

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: 5 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',
@@ -70,6 +71,9 @@ export const ENDPOINTS = {
7071
INDEX: '/conversation-live-chat',
7172
GET_MESSAGES: '/conversation-live-chat/:userId/:contactId',
7273
},
74+
BOT_MAIL: {
75+
SEND_MAIL: '/bot-mail/send',
76+
},
7377
}
7478

7579
export const LOCALE_KEY = 'lang'
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { LOCALE_KEY } from '@/constants'
2+
import { BotMailDto } from '@/dtos/bot-mail.dto'
3+
import { LocaleService } from '@/i18n/ctx'
4+
import { BotMailService } from '@/services/bot-mail.service'
5+
import { catchAsync } from '@/utils/catch-async'
6+
import { StatusCodes } from 'http-status-codes'
7+
import Container from 'typedi'
8+
9+
export class BotMailController {
10+
private readonly botMailService = Container.get(BotMailService)
11+
private readonly localeService: LocaleService = Container.get(LOCALE_KEY)
12+
13+
sendMail = catchAsync(async (req, res) => {
14+
await this.botMailService.sendMail(req.body as BotMailDto)
15+
16+
res.status(StatusCodes.OK).json({
17+
message: this.localeService.i18n().COMMON.SEND_MAIL_SUCCESS(),
18+
})
19+
})
20+
}

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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { TTemplate } from '@/mail/send-mail'
2-
import { IsEmail, IsNotEmpty, IsObject, IsString } from 'class-validator'
1+
import { IsEmail, IsNotEmpty, IsString } from 'class-validator'
32

43
export class BotMailDto {
54
@IsString()
@@ -18,8 +17,9 @@ export class BotMailDto {
1817

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

23-
@IsObject()
24-
variables: Record<string, any>
22+
@IsString()
23+
@IsNotEmpty()
24+
contactId: string
2525
}

server/src/i18n/ctx.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,28 @@ export class LocaleService {
1010
this.locale = locale
1111
}
1212

13+
/**
14+
* Gets the current locale.
15+
*
16+
* @returns The current locale.
17+
*/
1318
getLocale() {
1419
return this.locale
1520
}
1621

22+
/**
23+
* Sets the locale for the context.
24+
* @param locale The locale to set.
25+
*/
1726
setLocale(locale: Locales) {
18-
console.log('setLocale', locale)
1927
this.locale = locale
2028
}
2129

30+
/**
31+
* Returns the localized language object based on the current locale.
32+
* @returns The localized language object.
33+
*/
2234
i18n() {
23-
console.log(this.locale)
2435
return L[this.locale]
2536
}
2637
}

server/src/i18n/en/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export const COMMON = {
44
NAME: 'Name',
55
CONFIRM_PASSWORD: 'Confirm password',
66
OLD_PASSWORD: 'Old password',
7+
SEND_MAIL_SUCCESS: 'Send mail successfully',
78
}

0 commit comments

Comments
 (0)