Skip to content

Commit efe4875

Browse files
authored
Merge pull request #75 from Dialogue-Bot/DIAL-42-implement-test-your-bot
feat: update live chat
2 parents b30d951 + 0b26508 commit efe4875

File tree

14 files changed

+764
-28
lines changed

14 files changed

+764
-28
lines changed

client/src/apis/live-chat.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { ENDPOINTS } from '@/constants'
2+
import http_client from '@/lib/http-client'
3+
4+
class LiveChatApi {
5+
async getConversations() {
6+
return http_client.get(ENDPOINTS.CONVERSATION_LIVE_CHAT.INDEX)
7+
}
8+
}

client/src/components/layouts/app/sidebar.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
BrainCircuit,
1616
Cable,
1717
LogOut,
18+
MessageCircle,
1819
MessageSquareCode,
1920
} from 'lucide-react'
2021
import { useTranslation } from 'react-i18next'
@@ -46,6 +47,13 @@ const SIDEBAR_ITEMS: Array<{
4647
i18n: 'channels',
4748
to: ROUTES.PRIVATE.CHANNEL.INDEX,
4849
},
50+
{
51+
Icon: (
52+
<MessageCircle className='w-5 h-5 text-white group-hover:opacity-85 transition-all' />
53+
),
54+
i18n: 'conversations',
55+
to: ROUTES.PRIVATE.CONVERSATION.INDEX,
56+
},
4957
]
5058

5159
const Sidebar = () => {

client/src/components/layouts/live-chat/sidebar.tsx

Whitespace-only changes.

client/src/constants/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ export const ENDPOINTS = {
4747
DELETE: '/intent/delete',
4848
FOR_SELECT: '/intent/for-select',
4949
},
50+
CONVERSATION_LIVE_CHAT: {
51+
INDEX: '/conversation-live-chat',
52+
GET_MESSAGES: '/conversation-live-chat/:id',
53+
},
5054
}
5155

5256
export const ROUTES = {
@@ -84,6 +88,9 @@ export const ROUTES = {
8488
INDEX: '/training',
8589
ADD_INTENT: '/training/add-intent',
8690
},
91+
CONVERSATION: {
92+
INDEX: '/conversations',
93+
},
8794
},
8895
}
8996

client/src/pages/conversations.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const Conversations = () => {
2+
return <div>Conversations</div>
3+
}
4+
5+
export default Conversations

client/src/types/live-chat.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
export type TConversation = {
2+
id: string
3+
userId: string
4+
channelId: string
5+
createdAt: string
6+
updatedAt: string
7+
lastMessage: TMessage
8+
}
9+
10+
export type TMessage = {
11+
id: string
12+
conversationId: string
13+
createdAt: string
14+
from: string
15+
to: string
16+
type: string
17+
data: {
18+
text?: string
19+
buttons?: Array<{
20+
type: 'postback' | 'web_url'
21+
title: string
22+
payload?: string
23+
url?: string
24+
}>
25+
cards?: Array<{
26+
title: string
27+
subtitle: string
28+
image_url: string
29+
buttons: Array<{
30+
type: 'postback' | 'web_url'
31+
title: string
32+
payload?: string
33+
url?: string
34+
}>
35+
}>
36+
url?: string
37+
}
38+
}

server/src/constants/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const ENDPOINTS = {
6666
},
6767
CONVERSATION_LIVE_CHAT: {
6868
INDEX: '/conversation-live-chat',
69-
GET_MESSAGES: '/conversation-live-chat/:id',
69+
GET_MESSAGES: '/conversation-live-chat/:userId/:channelId',
7070
},
7171
}
7272

server/src/controllers/conversation-live-chat.controller.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ export class ConversationLiveChatController {
3939
})
4040

4141
public getMessages = catchAsync(async (req: RequestWithUser, res) => {
42-
const data = await this.messageService.getMessagesByConversationId(
43-
req.params.id as string,
44-
)
42+
const data = await this.messageService.getMessages({
43+
channelId: req.params.channelId,
44+
userId: req.params.userId,
45+
})
4546

4647
res.status(StatusCodes.OK).json({ data })
4748
})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ALTER TABLE "messages" DROP CONSTRAINT "messages_conversation_id_conversations_id_fk";
2+
--> statement-breakpoint
3+
DO $$ BEGIN
4+
ALTER TABLE "messages" ADD CONSTRAINT "messages_conversation_id_conversations_user_id_fk" FOREIGN KEY ("conversation_id") REFERENCES "conversations"("user_id") ON DELETE cascade ON UPDATE no action;
5+
EXCEPTION
6+
WHEN duplicate_object THEN null;
7+
END $$;
8+
--> statement-breakpoint
9+
ALTER TABLE "conversations" DROP COLUMN IF EXISTS "id";

0 commit comments

Comments
 (0)