Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/n4ze3m/dialoqbase
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Nov 29, 2023
2 parents 7d91214 + 12d05d3 commit 467b8a1
Show file tree
Hide file tree
Showing 13 changed files with 300 additions and 65 deletions.
2 changes: 1 addition & 1 deletion app/ui/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "app",
"private": true,
"version": "1.4.3",
"version": "1.4.4",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
16 changes: 13 additions & 3 deletions app/ui/src/components/Bot/Conversation/ConversationSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ export const ConversationSidebar = ({
data,
defaultIndex,
setDefaultIndex,
onChannelChange,
defaultChannel,
}: {
data: ConversationsByType[];
defaultIndex: number | null;
setDefaultIndex: React.Dispatch<React.SetStateAction<number | null>>;
onChannelChange: (value: string) => void;
defaultChannel: string;
}) => {
const [hideMenu] = React.useState(false);
return (
Expand All @@ -31,8 +35,14 @@ export const ConversationSidebar = ({
<div className="flex flex-col gap-2">
<h2 className="text-lg font-semibold">Conversations</h2>
<Select
options={[{ label: "Website", value: "website" }]}
defaultValue="website"
options={[
{ label: "Website", value: "website" },
{ label: "Telegram", value: "telegram" },
{ label: "Discord", value: "discord" },
// { label: "WhatsApp", value: "whatsapp" },
]}
onChange={(value) => onChannelChange(value)}
defaultValue={defaultChannel}
style={{ width: "100%" }}
/>
</div>
Expand All @@ -59,7 +69,7 @@ export const ConversationSidebar = ({
: `Anonymous`}
</h3>
<span className="text-xs font-thin">
{dayjs(item?.created_at).fromNow()}
{item?.created_at && dayjs(item?.created_at).fromNow()}
</span>
</div>
<div className="flex mt-2 flex-col gap-1">
Expand Down
15 changes: 14 additions & 1 deletion app/ui/src/components/Bot/Conversation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@ import React from "react";
import { ConversationSidebar } from "./ConversationSidebar";
import { ConversationInfo } from "./ConversationInfo";

export const ConversationBody = ({ data }: { data: ConversationsByType[] }) => {
export const ConversationBody = ({
data,
setType,
type,
}: {
data: ConversationsByType[];
type: string;
setType: React.Dispatch<React.SetStateAction<string>>;
}) => {
const [defaultIndex, setDefaultIndex] = React.useState<number | null>(null);

React.useEffect(() => {
Expand All @@ -19,6 +27,11 @@ export const ConversationBody = ({ data }: { data: ConversationsByType[] }) => {
defaultIndex={defaultIndex}
setDefaultIndex={setDefaultIndex}
data={data}
defaultChannel={type}
onChannelChange={(value) => {
setDefaultIndex(null);
setType(value);
}}
/>
</div>
<div className="md:ml-[350px]">
Expand Down
6 changes: 3 additions & 3 deletions app/ui/src/components/Common/SkeletonLoading.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Skeleton } from "antd";

export const SkeletonLoading = () => {
export const SkeletonLoading = ({ className = "mt-6" }: { className?: string }) => {
return (
<>
<div className={className}>
<Skeleton active />
<Skeleton active className="mt-3" />
</>
</div>
);
};
17 changes: 8 additions & 9 deletions app/ui/src/routes/bot/conversations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,17 @@ export default function BotConversationsRoot() {
conversation_id?: string;
}>();
const navigate = useNavigate();
const [defaultType] = React.useState<string>(param.type || "website");
const [type, setType] = React.useState<string>(param.type || "website");
const { data, status } = useQuery(
["getBotConversations", param.id, param.type],
["getBotConversations", param.id, param.type, type],
async () => {
const response = await api.get(
`/bot/conversations/${param.id}/${defaultType}`
);
const response = await api.get(`/bot/conversations/${param.id}/${type}`);
return response.data as {
data: ConversationsByType[];
};
},
{
enabled: !!param.id,
refetchInterval: 1000,
}
);

Expand All @@ -39,11 +36,13 @@ export default function BotConversationsRoot() {
return (
<>
{status === "loading" && (
<div className="p-4 m-3">
<SkeletonLoading />
<div className="mx-auto my-3 w-full max-w-7xl">
<SkeletonLoading className="mt-6" />
</div>
)}
{status === "success" && <ConversationBody data={data.data} />}
{status === "success" && (
<ConversationBody setType={setType} type={type} data={data.data} />
)}
</>
);
}
4 changes: 1 addition & 3 deletions app/ui/src/routes/bot/integrations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export default function BotIntegrationRoot() {
},
{
enabled: !!param.id,
refetchInterval: 1000,
}
);

Expand All @@ -54,8 +53,7 @@ export default function BotIntegrationRoot() {

return (
<div className="mx-auto my-3 w-full max-w-7xl">

{status === "loading" && <SkeletonLoading />}
{status === "loading" && <SkeletonLoading className="mt-6" />}
{status === "success" && <IntegrationGrid data={data.data} />}
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion app/ui/src/routes/bot/playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default function BotPreviewRoot() {
return (
<>
{status === "loading" && (
<div className="p-4 m-3">
<div className="mx-auto my-3 w-full max-w-7xl">
<SkeletonLoading />
</div>
)}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dialoqbase",
"version": "1.4.3",
"version": "1.4.4",
"description": "Create chatbots with ease",
"scripts": {
"ui:dev": "pnpm run --filter ui dev",
Expand Down
4 changes: 4 additions & 0 deletions server/src/integration/handlers/discord.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export const discordBotHandler = async (
ai: message.bot,
}));

if (history.length > 20) {
history.splice(0, history.length - 20);
}

const temperature = bot.temperature;

const sanitizedQuestion = message.trim().replaceAll("\n", " ");
Expand Down
8 changes: 4 additions & 4 deletions server/src/integration/handlers/telegram.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ export const telegramBotHandler = async (
},
});

// if (chat_history.length > 10) {
// chat_history.splice(0, chat_history.length - 10);
// }

let history = chat_history.map((message) => ({
human: message.human,
ai: message.bot,
}));

if (history.length > 20) {
history.splice(0, history.length - 20);
}

const temperature = bot.temperature;

Expand Down
4 changes: 2 additions & 2 deletions server/src/integration/handlers/whatsapp.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export const whatsappBotHandler = async (
},
});

if (chat_history.length > 10) {
chat_history.splice(0, chat_history.length - 10);
if (chat_history.length > 20) {
chat_history.splice(0, chat_history.length - 20);
}

let history = chat_history.map((message) => ({
Expand Down
Loading

0 comments on commit 467b8a1

Please sign in to comment.