Skip to content

Commit

Permalink
Merge pull request #177 from webwhiz-ai/main
Browse files Browse the repository at this point in the history
Integrations and invite members updates
  • Loading branch information
sachinchoolur authored Mar 9, 2024
2 parents 89aaf53 + 3e254e8 commit 67229db
Show file tree
Hide file tree
Showing 13 changed files with 280 additions and 32 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/ChatSessions/ChatList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const ChatList = ({ isChatListLoading, chatSessionsPage, selectedChat, on
<Flex direction="column">
{
chatSessionsPage?.results
.filter((chatSession) => chatSession.firstMessage)
.filter((chatSession) => chatSession.latestMessage)
.map((chatSession) => (
<ChatListItem
key={chatSession._id}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/ChatSessions/ChatListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const ChatListItem = ({ chatSessionData, isSelected, onSelectChat, update
{getFormattedTime(chatSessionData.updatedAt)}
</Text>
<Text fontSize="sm" noOfLines={2} fontWeight={chatSessionData.isUnread ? '500' : '400'}>
{ chatSessionData.firstMessage.q ||chatSessionData.firstMessage.msg }
{ chatSessionData.latestMessage.q ||chatSessionData.latestMessage.msg }
</Text>
</Flex >
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React, { HTMLAttributes } from "react";

interface IconProps extends HTMLAttributes<SVGElement> {
width?: number;
height?: number;
}

export const SlackIntegrationIcon = ({
width = 60,
height = 63,
...restProps
}: IconProps) => {
return (
<svg xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 2447.6 2452.5"
width={width}
height={height}
{...restProps}
>
<g fillRule="evenodd" clipRule="evenodd">
<path
fill="#36c5f0"
d="M897.4 0C762.1.1 652.6 109.9 652.7 245.2c-.1 135.3 109.5 245.1 244.8 245.2h244.8V245.3C1142.4 110 1032.8.2 897.4 0c.1 0 .1 0 0 0m0 654H244.8C109.5 654.1-.1 763.9 0 899.2c-.2 135.3 109.4 245.1 244.7 245.3h652.7c135.3-.1 244.9-109.9 244.8-245.2.1-135.4-109.5-245.2-244.8-245.3z"
></path>
<path
fill="#2eb67d"
d="M2447.6 899.2c.1-135.3-109.5-245.1-244.8-245.2-135.3.1-244.9 109.9-244.8 245.2v245.3h244.8c135.3-.1 244.9-109.9 244.8-245.3zm-652.7 0v-654C1795 110 1685.5.2 1550.2 0c-135.3.1-244.9 109.9-244.8 245.2v654c-.2 135.3 109.4 245.1 244.7 245.3 135.3-.1 244.9-109.9 244.8-245.3z"
></path>
<path
fill="#ecb22e"
d="M1550.1 2452.5c135.3-.1 244.9-109.9 244.8-245.2.1-135.3-109.5-245.1-244.8-245.2h-244.8v245.2c-.1 135.2 109.5 245 244.8 245.2zm0-654.1h652.7c135.3-.1 244.9-109.9 244.8-245.2.2-135.3-109.4-245.1-244.7-245.3h-652.7c-135.3.1-244.9 109.9-244.8 245.2-.1 135.4 109.4 245.2 244.7 245.3z"
></path>
<path
fill="#e01e5a"
d="M0 1553.2c-.1 135.3 109.5 245.1 244.8 245.2 135.3-.1 244.9-109.9 244.8-245.2V1308H244.8C109.5 1308.1-.1 1417.9 0 1553.2zm652.7 0v654c-.2 135.3 109.4 245.1 244.7 245.3 135.3-.1 244.9-109.9 244.8-245.2v-653.9c.2-135.3-109.4-245.1-244.7-245.3-135.4 0-244.9 109.8-244.8 245.1 0 0 0 .1 0 0"
></path>
</g>
</svg>
);
}
28 changes: 28 additions & 0 deletions frontend/src/components/Icons/Integrations/ZapierIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from "react";

interface IconProps extends HTMLAttributes<SVGElement> {
width?: number;
height?: number;
}
function ZapierIcon({
width = 60,
height = 63,
...restProps
}: IconProps) {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
width={width}
height={height}
{...restProps}
viewBox="0 0 256 256"
>
<path
fill="#FF4A00"
d="M128.08 0c7.231.013 14.343.624 21.256 1.78V76.3l52.831-52.696a128.425 128.425 0 0116.34 13.789 128.468 128.468 0 0113.84 16.312L179.513 106.4h74.715A127.58 127.58 0 01256 127.587v.173c0 7.226-.613 14.306-1.772 21.2H179.5l52.847 52.682a129.615 129.615 0 01-13.824 16.312h-.015a128.254 128.254 0 01-16.326 13.789l-52.846-52.696v74.52a130.321 130.321 0 01-21.243 1.781h-.186a130.26 130.26 0 01-21.23-1.78v-74.52l-52.831 52.695a128.401 128.401 0 01-30.18-30.1L76.5 148.96H1.785A126.984 126.984 0 010 127.72v-.371c.012-1.875.135-4.166.311-6.536l.055-.713c.522-6.671 1.419-13.7 1.419-13.7H76.5L23.666 53.705a126.265 126.265 0 0113.81-16.286l.026-.026a127.746 127.746 0 0116.344-13.789L106.677 76.3V1.78A130.278 130.278 0 01127.933 0h.147zm-.013 95.76h-.122c-9.509 0-18.616 1.74-27.034 4.902a76.662 76.662 0 00-4.915 26.952v.12a76.383 76.383 0 004.927 26.951 76.608 76.608 0 0027.022 4.902h.122c9.51 0 18.617-1.74 27.022-4.902a76.146 76.146 0 004.915-26.952v-.12c0-9.484-1.747-18.57-4.915-26.951a76.614 76.614 0 00-27.022-4.902z"
></path>
</svg>
);
}

export default ZapierIcon;
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,9 @@ export const ChatBotsCustomize = ({
<Flex justifyContent="space-between" w="100%" alignItems="center">

<FormLabel fontWeight="400" fontSize="sm" color="gray.700" htmlFor="enableHumanChat">
Enable human chat
Enable human chat <Badge ml="8px" variant='outline' colorScheme='yellow'>
Beta
</Badge>
</FormLabel>
<Switch
{...field}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/containers/ChatSessions/ChatSessionsNew.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export const ChatSessionsNew = ({ chatbotId, userId }: ChatSessionsProps) => {
data?.sessionId !== chatData?._id && !chatSession.isUnread && updateChatSessionReadStatus(chatSession?._id, true, false)
chatSession.isUnread = true
chatSession.updatedAt = new Date().toString()
chatSession.firstMessage = data;
chatSession.latestMessage = data;
} else return prev
return {
...prev, results: [chatSession, ...prev?.results.filter(item => item._id !== data.sessionId) || []]
Expand Down Expand Up @@ -196,7 +196,7 @@ export const ChatSessionsNew = ({ chatbotId, userId }: ChatSessionsProps) => {
if (chatSession) {
chatSession.isUnread = true
chatSession.updatedAt = new Date().toString()
chatSession.firstMessage = data;
chatSession.latestMessage = data;
}
return {
...prev, results: [...prev?.results || []]
Expand Down
53 changes: 50 additions & 3 deletions frontend/src/containers/EditChatbot/EditChatbot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
AlertTitle, Box,
Button, Flex,
Heading,
Badge,
HStack,
IconButton, List,
ListItem,
Expand All @@ -23,6 +24,7 @@ import {
Link,
RouteComponentProps,
useHistory,
useLocation,
withRouter
} from "react-router-dom";
import { ChatBot } from "../../components/ChatBot/ChatBot";
Expand All @@ -40,6 +42,7 @@ import { ChatBotProductSetup } from "../ChatBotProductSetup/ChatBotProductSetup"
import { ChatBotsCustomize } from "../ChatBotsCustomize/ChatBotsCustomize";
import { ChatSessionsNew } from "../ChatSessions/ChatSessionsNew";
import { CustomDomain } from "../CustomDomain/CustomDomain";
import Integrations from "../Integrations/Integrations";
import Members from "../Members/Members";
import { OfflineMessagesNew } from "../OfflineMessages/OfflineMessagesNew";
import styles from "./EditChatbot.module.scss";
Expand All @@ -57,7 +60,8 @@ type Steps =
| "chat-sessions"
| "offline-messages"
| "chatbot"
| "custom-domain" | "members";
| "custom-domain" | "members"
| "integrations";

interface MatchParams {
chatbotId: string;
Expand All @@ -70,6 +74,10 @@ const EditChatbot = (props: EditChatbotProps) => {
const toast = useToast();
let history = useHistory();

const location = useLocation();
const queryParams = new URLSearchParams(location.search);
const shouldActivateInviteMembers = queryParams.get('inviteMembers') === 'true';

const [user, setUser] = React.useState<User>(CurrentUser.get());
const [access, setAccess] = React.useState(permissions.get());
React.useEffect(() => {
Expand Down Expand Up @@ -962,6 +970,20 @@ console.log(permissions.get(), 'permissionspermissions')
/>
{chatBot._id? <CustomDomain defaultCustomDomain={chatBot.customDomain} chatBotId={chatBot._id}></CustomDomain>: null}
</Flex>
<Flex
direction="column"
style={{
display: currentStep === 'integrations' ? 'flex' : 'none',
}}
h="100%"
overflow="auto"
>
<SectionTitle
title="Integrations"
description="Expand your chatbot's capabilities by seamlessly integrating with popular tools and platforms."
/>
{chatBot._id ? <Integrations chatbotId={chatBot._id} /> : null}
</Flex>
{access.isOwner ? <Flex
direction="column"
style={{
Expand Down Expand Up @@ -1253,7 +1275,7 @@ console.log(permissions.get(), 'permissionspermissions')

Custom domain
</ListItem>: null}
{access.isOwner ? <ListItem
{access.isOwner && shouldActivateInviteMembers ? <ListItem
display="flex"
alignItems="center"
fontSize="md"
Expand All @@ -1267,7 +1289,32 @@ console.log(permissions.get(), 'permissionspermissions')
<path d="M22 21V19C22 17.1362 20.7252 15.5701 19 15.126M15.5 3.29076C16.9659 3.88415 18 5.32131 18 7C18 8.67869 16.9659 10.1159 15.5 10.7092M17 21C17 19.1362 17 18.2044 16.6955 17.4693C16.2895 16.4892 15.5108 15.7105 14.5307 15.3045C13.7956 15 12.8638 15 11 15H8C6.13623 15 5.20435 15 4.46927 15.3045C3.48915 15.7105 2.71046 16.4892 2.30448 17.4693C2 18.2044 2 19.1362 2 21M13.5 7C13.5 9.20914 11.7091 11 9.5 11C7.29086 11 5.5 9.20914 5.5 7C5.5 4.79086 7.29086 3 9.5 3C11.7091 3 13.5 4.79086 13.5 7Z" stroke="currentcolor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
</svg>

Members
Members <Badge ml="8px" variant='outline' colorScheme='yellow'>
Beta
</Badge>
</ListItem> : null}

{access.isAdmin || access.isEditor ? <ListItem
display="flex"
alignItems="center"
fontSize="md"
cursor="pointer"
onClick={() => {
goToStep("integrations");
}}
className={currentStep === "integrations" ? styles.active : ""}
>
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path d="M7.5 7H7C4.23858 7 2 9.23858 2 12C2 14.7614 4.23858 17 7 17H9C11.7614 17 14 14.7614 14 12M16.5 17H17C19.7614 17 22 14.7614 22 12C22 9.23858 19.7614 7 17 7H15C12.2386 7 10 9.23858 10 12" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
</svg>

Integrations
</ListItem> : null}
</List>
</Box>
Expand Down
105 changes: 105 additions & 0 deletions frontend/src/containers/Integrations/Integrations.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { Box, Heading, HStack, SimpleGrid, Text, Button, Badge } from '@chakra-ui/react';
import React from 'react';
import { SlackIntegrationIcon } from '../../components/Icons/Integrations/SlackIntegrationIcon';
import ZapierIcon from '../../components/Icons/Integrations/ZapierIcon';
import { baseURL } from '../../config';

interface IntegrationsProps {
chatbotId: string
}

const Integrations = ({ chatbotId }: IntegrationsProps) => {
return (
<SimpleGrid columns={[1, 1, 1, 2]} spacing={6}>
<Box
bg="gray.50"
p={4}
borderRadius="lg"
boxShadow="md"
>
<HStack
spacing={4}
alignItems="start"
>
<Box
p={3}
>
<SlackIntegrationIcon />
</Box>
<Box width="100%">
<Heading fontSize="lg" mb={2}>Slack <Badge ml="8px" fontSize="12px" textTransform="capitalize" fontWeight="500" padding="2px 6px" variant='outline' colorScheme='yellow'>
Beta
</Badge></Heading>
<Text fontSize="sm" color="gray.600">
Connect your WebWhiz chatbot to your Slack workspace,
enabling direct access right from within
Slack.
</Text>
<Button
variant="solid"
size="sm"
colorScheme="blue"
mt={4}
onClick={() => {
window.open(`${baseURL}/slack/install?webwhizKbId=${chatbotId}`, '_blank');
}}
>
Add to Slack
</Button>
</Box>
</HStack>
</Box>
<Box
bg="gray.50"
p={4}
borderRadius="lg"
boxShadow="md"
>
<HStack
spacing={4}
alignItems="start"
>
<Box
p={3}
>
<ZapierIcon />
</Box>
<Box width="100%">
<Heading fontSize="lg" mb={2}>Zapier <Badge ml="8px" fontSize="12px" textTransform="capitalize" fontWeight="500" padding="2px 6px" variant='outline' colorScheme='yellow'>
Beta
</Badge></Heading>
<Text fontSize="sm" color="gray.600">
Unlock the potential of AI chatbots in your workflow with the WebWhiz and Zapier integration.
</Text>
<HStack>
<a href="https://zapier.com/developer/public-invite/191149/ff8d8edc00c542b4c8c34aabac594b1e/">
<Button
variant="solid"
size="sm"
colorScheme="blue"
mt={4}
>
Connect with Zapier
</Button>
</a>

<a href="https://www.webwhiz.ai/docs/integrations/zapier-integration/">
<Button
variant="outline"
size="sm"
colorScheme="gray"
mt={4}
>
View docs
</Button>
</a>

</HStack>
</Box>
</HStack>
</Box>
</SimpleGrid>
)
}

export default Integrations
2 changes: 1 addition & 1 deletion frontend/src/types/knowledgebase.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export interface UserData {
export interface ChatSession {
isUnread: boolean;
firstMessage: MessageList;
firstMessage: MessageList;
latestMessage: MessageList;
startedAt: string;
updatedAt: string;
userData?: UserData;
Expand Down
4 changes: 2 additions & 2 deletions src/knowledgebase/knowledgebase-db.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,14 +579,14 @@ export class KnowledgebaseDbService {
) {
const itemsPerPage = Math.min(pageSize, 50);

// TODO: remove firstMessage if not required
const projectionFields = {
_id: 1,
startedAt: 1,
updatedAt: 1,
userData: 1,
isUnread: 1,
firstMessage: { $first: '$messages' }
firstMessage: { $first: '$messages' },
latestMessage: { $last: '$messages' },
};

const filter = {
Expand Down
10 changes: 10 additions & 0 deletions widget/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -1052,4 +1052,14 @@ a.chat-source-btn {
.offline-message.show-success-msg,
.offline-message.how-error-msg {
overflow: hidden;
}
.switch-chat-btn {
display: flex;
align-items: center;
}
.switch-chat-btn svg {
width: 14px;
height: 14px;
margin-right: 5px;
color: #757575;
}
Loading

0 comments on commit 67229db

Please sign in to comment.