feat: rename live chat tester to console

This commit is contained in:
Mohamed Marrouchi 2024-10-22 14:37:42 +01:00
parent a3d7b83511
commit 5218233434
21 changed files with 67 additions and 69 deletions

View File

@ -10,7 +10,7 @@ import { Injectable, UnauthorizedException } from '@nestjs/common';
import { Request, Response } from 'express'; import { Request, Response } from 'express';
import { SubscriberService } from '@/chat/services/subscriber.service'; import { SubscriberService } from '@/chat/services/subscriber.service';
import { LIVE_CHAT_TEST_CHANNEL_NAME } from '@/extensions/channels/live-chat-tester/settings'; import { CONSOLE_CHANNEL_NAME } from '@/extensions/channels/console/settings';
import { WEB_CHANNEL_NAME } from '@/extensions/channels/web/settings'; import { WEB_CHANNEL_NAME } from '@/extensions/channels/web/settings';
import { LoggerService } from '@/logger/logger.service'; import { LoggerService } from '@/logger/logger.service';
import { import {
@ -116,20 +116,20 @@ export class ChannelService {
} }
/** /**
* Handles a websocket request for the live chat tester channel. * Handles a websocket request for the admin chat console channel.
* It considers the user as a subscriber. * It considers the user as a subscriber.
* *
* @param req - The websocket request object. * @param req - The websocket request object.
* @param res - The websocket response object. * @param res - The websocket response object.
*/ */
@SocketGet(`/webhook/${LIVE_CHAT_TEST_CHANNEL_NAME}/`) @SocketGet(`/webhook/${CONSOLE_CHANNEL_NAME}/`)
@SocketPost(`/webhook/${LIVE_CHAT_TEST_CHANNEL_NAME}/`) @SocketPost(`/webhook/${CONSOLE_CHANNEL_NAME}/`)
async handleWebsocketForLiveChatTester( async handleWebsocketForAdminChatConsole(
@SocketReq() req: SocketRequest, @SocketReq() req: SocketRequest,
@SocketRes() res: SocketResponse, @SocketRes() res: SocketResponse,
) { ) {
this.logger.log( this.logger.log(
'Channel notification (Live Chat Tester Socket) : ', 'Channel notification (Admin Chat Console Socket) : ',
req.method, req.method,
); );
@ -158,7 +158,7 @@ export class ChannelService {
country: '', country: '',
labels: [], labels: [],
channel: { channel: {
name: LIVE_CHAT_TEST_CHANNEL_NAME, name: CONSOLE_CHANNEL_NAME,
isSocket: true, isSocket: true,
}, },
}, },
@ -172,7 +172,7 @@ export class ChannelService {
polling: false, polling: false,
}; };
const handler = this.getChannelHandler(LIVE_CHAT_TEST_CHANNEL_NAME); const handler = this.getChannelHandler(CONSOLE_CHANNEL_NAME);
return handler.handle(req, res); return handler.handle(req, res);
} }
} }

View File

@ -0,0 +1,3 @@
{
"console_channel": "Admin Chat Console"
}

View File

@ -0,0 +1,3 @@
{
"console_channel": "Testeur Live Chat"
}

View File

@ -21,11 +21,11 @@ import { WebsocketGateway } from '@/websocket/websocket.gateway';
import BaseWebChannelHandler from '../web/base-web-channel'; import BaseWebChannelHandler from '../web/base-web-channel';
import { LIVE_CHAT_TEST_CHANNEL_NAME } from './settings'; import { CONSOLE_CHANNEL_NAME } from './settings';
@Injectable() @Injectable()
export default class LiveChatTesterHandler extends BaseWebChannelHandler< export default class ConsoleChannelHandler extends BaseWebChannelHandler<
typeof LIVE_CHAT_TEST_CHANNEL_NAME typeof CONSOLE_CHANNEL_NAME
> { > {
constructor( constructor(
settingService: SettingService, settingService: SettingService,
@ -40,7 +40,7 @@ export default class LiveChatTesterHandler extends BaseWebChannelHandler<
websocketGateway: WebsocketGateway, websocketGateway: WebsocketGateway,
) { ) {
super( super(
LIVE_CHAT_TEST_CHANNEL_NAME, CONSOLE_CHANNEL_NAME,
settingService, settingService,
channelService, channelService,
logger, logger,

View File

@ -0,0 +1,16 @@
import CONSOLE_CHANNEL_SETTINGS, {
CONSOLE_CHANNEL_NAMESPACE,
} from './settings';
declare global {
interface Settings extends SettingTree<typeof CONSOLE_CHANNEL_SETTINGS> {}
}
declare module '@nestjs/event-emitter' {
interface IHookExtensionsOperationMap {
[CONSOLE_CHANNEL_NAMESPACE]: TDefinition<
object,
SettingMapByType<typeof CONSOLE_CHANNEL_SETTINGS>
>;
}
}

View File

@ -0,0 +1,7 @@
{
"name": "hexabot-channel-console",
"version": "2.0.0",
"description": "The Admin Chat Console Channel Extension for Hexabot Chatbot / Agent Builder.",
"author": "Hexastack",
"license": "AGPL-3.0-only"
}

View File

@ -12,83 +12,83 @@ import { SettingType } from '@/setting/schemas/types';
import { Web } from '../web/types'; import { Web } from '../web/types';
export const LIVE_CHAT_TEST_CHANNEL_NAME = 'live-chat-tester-channel'; export const CONSOLE_CHANNEL_NAME = 'console-channel';
export const LIVE_CHAT_TEST_CHANNEL_NAMESPACE = 'live_chat_tester_channel'; export const CONSOLE_CHANNEL_NAMESPACE = 'console_channel';
export default [ export default [
{ {
group: LIVE_CHAT_TEST_CHANNEL_NAMESPACE, group: CONSOLE_CHANNEL_NAMESPACE,
label: Web.SettingLabel.verification_token, label: Web.SettingLabel.verification_token,
value: 'test', value: 'test',
type: SettingType.text, type: SettingType.text,
}, },
{ {
group: LIVE_CHAT_TEST_CHANNEL_NAMESPACE, group: CONSOLE_CHANNEL_NAMESPACE,
label: Web.SettingLabel.allowed_domains, label: Web.SettingLabel.allowed_domains,
value: config.frontendPath, value: config.frontendPath,
type: SettingType.text, type: SettingType.text,
}, },
{ {
group: LIVE_CHAT_TEST_CHANNEL_NAMESPACE, group: CONSOLE_CHANNEL_NAMESPACE,
label: Web.SettingLabel.start_button, label: Web.SettingLabel.start_button,
value: true, value: true,
type: SettingType.checkbox, type: SettingType.checkbox,
}, },
{ {
group: LIVE_CHAT_TEST_CHANNEL_NAMESPACE, group: CONSOLE_CHANNEL_NAMESPACE,
label: Web.SettingLabel.input_disabled, label: Web.SettingLabel.input_disabled,
value: false, value: false,
type: SettingType.checkbox, type: SettingType.checkbox,
}, },
{ {
group: LIVE_CHAT_TEST_CHANNEL_NAMESPACE, group: CONSOLE_CHANNEL_NAMESPACE,
label: Web.SettingLabel.persistent_menu, label: Web.SettingLabel.persistent_menu,
value: true, value: true,
type: SettingType.checkbox, type: SettingType.checkbox,
}, },
{ {
group: LIVE_CHAT_TEST_CHANNEL_NAMESPACE, group: CONSOLE_CHANNEL_NAMESPACE,
label: Web.SettingLabel.greeting_message, label: Web.SettingLabel.greeting_message,
value: 'Welcome! Ready to start a conversation with our chatbot?', value: 'Welcome! Ready to start a conversation with our chatbot?',
type: SettingType.textarea, type: SettingType.textarea,
}, },
{ {
group: LIVE_CHAT_TEST_CHANNEL_NAMESPACE, group: CONSOLE_CHANNEL_NAMESPACE,
label: Web.SettingLabel.theme_color, label: Web.SettingLabel.theme_color,
value: 'teal', value: 'teal',
type: SettingType.select, type: SettingType.select,
options: ['teal', 'orange', 'red', 'green', 'blue', 'dark'], options: ['teal', 'orange', 'red', 'green', 'blue', 'dark'],
}, },
{ {
group: LIVE_CHAT_TEST_CHANNEL_NAMESPACE, group: CONSOLE_CHANNEL_NAMESPACE,
label: Web.SettingLabel.show_emoji, label: Web.SettingLabel.show_emoji,
value: true, value: true,
type: SettingType.checkbox, type: SettingType.checkbox,
}, },
{ {
group: LIVE_CHAT_TEST_CHANNEL_NAMESPACE, group: CONSOLE_CHANNEL_NAMESPACE,
label: Web.SettingLabel.show_file, label: Web.SettingLabel.show_file,
value: true, value: true,
type: SettingType.checkbox, type: SettingType.checkbox,
}, },
{ {
group: LIVE_CHAT_TEST_CHANNEL_NAMESPACE, group: CONSOLE_CHANNEL_NAMESPACE,
label: Web.SettingLabel.show_location, label: Web.SettingLabel.show_location,
value: true, value: true,
type: SettingType.checkbox, type: SettingType.checkbox,
}, },
{ {
group: LIVE_CHAT_TEST_CHANNEL_NAMESPACE, group: CONSOLE_CHANNEL_NAMESPACE,
label: Web.SettingLabel.allowed_upload_size, label: Web.SettingLabel.allowed_upload_size,
value: 2500000, value: 2500000,
type: SettingType.number, type: SettingType.number,
}, },
{ {
group: LIVE_CHAT_TEST_CHANNEL_NAMESPACE, group: CONSOLE_CHANNEL_NAMESPACE,
label: Web.SettingLabel.allowed_upload_types, label: Web.SettingLabel.allowed_upload_types,
value: value:
'audio/mpeg,audio/x-ms-wma,audio/vnd.rn-realaudio,audio/x-wav,image/gif,image/jpeg,image/png,image/tiff,image/vnd.microsoft.icon,image/vnd.djvu,image/svg+xml,text/css,text/csv,text/html,text/plain,text/xml,video/mpeg,video/mp4,video/quicktime,video/x-ms-wmv,video/x-msvideo,video/x-flv,video/web,application/msword,application/vnd.ms-powerpoint,application/pdf,application/vnd.ms-excel,application/vnd.oasis.opendocument.presentation,application/vnd.oasis.opendocument.tex,application/vnd.oasis.opendocument.spreadsheet,application/vnd.oasis.opendocument.graphics,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'audio/mpeg,audio/x-ms-wma,audio/vnd.rn-realaudio,audio/x-wav,image/gif,image/jpeg,image/png,image/tiff,image/vnd.microsoft.icon,image/vnd.djvu,image/svg+xml,text/css,text/csv,text/html,text/plain,text/xml,video/mpeg,video/mp4,video/quicktime,video/x-ms-wmv,video/x-msvideo,video/x-flv,video/web,application/msword,application/vnd.ms-powerpoint,application/pdf,application/vnd.ms-excel,application/vnd.oasis.opendocument.presentation,application/vnd.oasis.opendocument.tex,application/vnd.oasis.opendocument.spreadsheet,application/vnd.oasis.opendocument.graphics,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.openxmlformats-officedocument.wordprocessingml.document',
type: SettingType.textarea, type: SettingType.textarea,
}, },
] as const satisfies ChannelSetting<typeof LIVE_CHAT_TEST_CHANNEL_NAME>[]; ] as const satisfies ChannelSetting<typeof CONSOLE_CHANNEL_NAME>[];

View File

@ -1,3 +0,0 @@
{
"live_chat_tester_channel": "Live Chat Tester"
}

View File

@ -1,3 +0,0 @@
{
"live_chat_tester_channel": "Testeur Live Chat"
}

View File

@ -1,17 +0,0 @@
import DEFAULT_LIVE_CHAT_TEST_SETTINGS, {
LIVE_CHAT_TEST_CHANNEL_NAMESPACE,
} from './settings';
declare global {
interface Settings
extends SettingTree<typeof DEFAULT_LIVE_CHAT_TEST_SETTINGS> {}
}
declare module '@nestjs/event-emitter' {
interface IHookExtensionsOperationMap {
[LIVE_CHAT_TEST_CHANNEL_NAMESPACE]: TDefinition<
object,
SettingMapByType<typeof DEFAULT_LIVE_CHAT_TEST_SETTINGS>
>;
}
}

View File

@ -1,7 +0,0 @@
{
"name": "hexabot-channel-live-chat-tester",
"version": "2.0.0",
"description": "The Web Channel Extension for Hexabot Chatbot / Agent Builder for website integration",
"author": "Hexastack",
"license": "AGPL-3.0-only"
}

View File

@ -49,8 +49,8 @@ describe('WebsocketGateway', () => {
ioClient = io('http://localhost:3000', { ioClient = io('http://localhost:3000', {
autoConnect: false, autoConnect: false,
transports: ['websocket', 'polling'], transports: ['websocket', 'polling'],
// path: '/socket.io/?EIO=4&transport=websocket&channel=web', // path: '/socket.io/?EIO=4&transport=websocket&channel=web-channel',
query: { EIO: '4', transport: 'websocket', channel: 'web' }, query: { EIO: '4', transport: 'websocket', channel: 'web-channel' },
}); });
app.listen(3000); app.listen(3000);

View File

@ -209,6 +209,7 @@ export class WebsocketGateway
this.logger.verbose('Client connected, attempting to load session.'); this.logger.verbose('Client connected, attempting to load session.');
try { try {
const { searchParams } = new URL(`ws://localhost${client.request.url}`); const { searchParams } = new URL(`ws://localhost${client.request.url}`);
if (client.request.headers.cookie) { if (client.request.headers.cookie) {
const cookies = cookie.parse(client.request.headers.cookie); const cookies = cookie.parse(client.request.headers.cookie);
if (cookies && config.session.name in cookies) { if (cookies && config.session.name in cookies) {
@ -223,7 +224,7 @@ export class WebsocketGateway
'Unable to load session, creating a new one ...', 'Unable to load session, creating a new one ...',
err, err,
); );
if (searchParams.get('channel') === 'web') { if (searchParams.get('channel') === 'web-channel') {
return this.createAndStoreSession(client, next); return this.createAndStoreSession(client, next);
} else { } else {
return next(new Error('Unauthorized: Unknown session ID')); return next(new Error('Unauthorized: Unknown session ID'));
@ -237,7 +238,7 @@ export class WebsocketGateway
return next(new Error('Unable to parse session ID from cookie')); return next(new Error('Unable to parse session ID from cookie'));
} }
} }
} else if (searchParams.get('channel') === 'web') { } else if (searchParams.get('channel') === 'web-channel') {
return this.createAndStoreSession(client, next); return this.createAndStoreSession(client, next);
} else { } else {
return next(new Error('Unauthorized to connect to WS')); return next(new Error('Unauthorized to connect to WS'));

View File

@ -57,5 +57,5 @@ NEXT_PUBLIC_SSO_ENABLED=false
# Widget # Widget
APP_WIDGET_PORT=5173 APP_WIDGET_PORT=5173
REACT_APP_WIDGET_API_URL=http://${APP_DOMAIN}:${API_PORT} REACT_APP_WIDGET_API_URL=http://${APP_DOMAIN}:${API_PORT}
REACT_APP_WIDGET_CHANNEL=web REACT_APP_WIDGET_CHANNEL=web-channel
REACT_APP_WIDGET_TOKEN=token123 REACT_APP_WIDGET_TOKEN=token123

View File

@ -220,8 +220,7 @@
"log_entry": "Log entry", "log_entry": "Log entry",
"dashboard": "Dashboard", "dashboard": "Dashboard",
"warning": "Warning", "warning": "Warning",
"live_chat_tester": "Live Chat Tester", "console": "Admin Chat Console"
"live-chat-tester": "Live Chat Tester"
}, },
"label": { "label": {
"terms": "I have read and approve the terms and conditions.", "terms": "I have read and approve the terms and conditions.",

View File

@ -220,8 +220,7 @@
"log_entry": "Journal des entrées", "log_entry": "Journal des entrées",
"dashboard": "Tableau de bord", "dashboard": "Tableau de bord",
"warning": "Avertissement", "warning": "Avertissement",
"live_chat_tester": "Testeur Live Chat", "console": "Console de Chat Admin"
"live-chat-tester": "Testeur Live Chat"
}, },
"label": { "label": {
"terms": "J'ai lu et approuvé les termes et conditions.", "terms": "J'ai lu et approuvé les termes et conditions.",

View File

@ -33,7 +33,7 @@ export const ChatWidget = () => {
<UiChatWidget <UiChatWidget
config={{ config={{
apiUrl, apiUrl,
channel: "live-chat-tester-channel", channel: "console-channel",
token: "test", token: "test",
language: i18n.language, language: i18n.language,
}} }}

View File

@ -19,7 +19,7 @@ export const ChatWidgetHeader = () => {
<Box display="flex" alignItems="center" ml={2}> <Box display="flex" alignItems="center" ml={2}>
<HexabotLogoRound width={32} height={32} /> <HexabotLogoRound width={32} height={32} />
<Typography component="h2" fontSize="1.25rem" ml={2}> <Typography component="h2" fontSize="1.25rem" ml={2}>
{t("title.live_chat_tester")} {t("title.console")}
</Typography> </Typography>
</Box> </Box>
); );

View File

@ -8,7 +8,7 @@
export const DEFAULT_CONFIG = { export const DEFAULT_CONFIG = {
apiUrl: process.env.REACT_APP_WIDGET_API_URL || 'http://localhost:4000', apiUrl: process.env.REACT_APP_WIDGET_API_URL || 'http://localhost:4000',
channel: process.env.REACT_APP_WIDGET_CHANNEL || 'live-chat-tester-channel', channel: process.env.REACT_APP_WIDGET_CHANNEL || 'console-channel',
token: process.env.REACT_APP_WIDGET_TOKEN || 'test', token: process.env.REACT_APP_WIDGET_TOKEN || 'test',
language: 'en', language: 'en',
}; };