Merge pull request #329 from Hexastack/feat/widget-enhancements

feat: widget enhancements
This commit is contained in:
Med Marrouchi 2024-11-13 01:25:56 +00:00 committed by GitHub
commit 0546ed9c7c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
23 changed files with 109 additions and 102 deletions

View File

@ -62,7 +62,7 @@ export default [
{
group: WEB_CHANNEL_NAMESPACE,
label: Web.SettingLabel.avatar_url,
value: 'https://eu.ui-avatars.com/api/?name=Hexa+Bot&size=64',
value: '',
type: SettingType.text,
},
{

View File

@ -83,8 +83,8 @@ export class ReadOnlyUserController extends BaseController<
*/
@Roles('public')
@Get('bot/profile_pic')
async botProfilePic() {
return getBotAvatar();
async botProfilePic(@Query('color') color: string) {
return getBotAvatar(color);
}
/**

View File

@ -39,8 +39,8 @@ export const generateInitialsAvatar = async (name: {
return await generateAvatarSvg(svg);
};
export const getBotAvatar = async () => {
const svg = generateBotAvatarSvg({});
export const getBotAvatar = async (color: string) => {
const svg = generateBotAvatarSvg({ bgColor: color });
return await generateAvatarSvg(svg);
};

View File

@ -43,17 +43,17 @@ export function generateUIAvatarSvg({
export function generateBotAvatarSvg({
size = 64,
bgColor = '#d1d1d1',
bgColor = '#000',
textColor = '#fff',
}: UIAvatarSvgParams): string {
return `
<svg width="${size}px" height="${size}px" viewBox="-3.36 -3.36 30.72 30.72" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" fill="#4f4f4f" stroke="#4f4f4f" transform="rotate(0)">
<svg width="${size}px" height="${size}px" viewBox="-3.36 -3.36 30.72 30.72" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g stroke-width="0" transform="translate(0,0), scale(1)">
<rect x="-3.36" y="-3.36" width="30.72" height="30.72" rx="15.36" fill="${bgColor}" strokewidth="0"></rect>
</g>
<g stroke-linecap="round" stroke-linejoin="round" stroke="#CCCCCC" stroke-width="0.336"></g>
<g>
<g stroke-width="0.00024000000000000003" fill="none" fill-rule="evenodd">
<g fill="#000000" fill-rule="nonzero">
<g stroke-width="0.00024000000000000003" fill="${textColor}" fill-rule="evenodd">
<g fill-rule="nonzero">
<path d="M17.7530511,13.999921 C18.9956918,13.999921 20.0030511,15.0072804 20.0030511,16.249921 L20.0030511,17.1550008 C20.0030511,18.2486786 19.5255957,19.2878579 18.6957793,20.0002733 C17.1303315,21.344244 14.8899962,22.0010712 12,22.0010712 C9.11050247,22.0010712 6.87168436,21.3444691 5.30881727,20.0007885 C4.48019625,19.2883988 4.00354153,18.2500002 4.00354153,17.1572408 L4.00354153,16.249921 C4.00354153,15.0072804 5.01090084,13.999921 6.25354153,13.999921 L17.7530511,13.999921 Z M17.7530511,15.499921 L6.25354153,15.499921 C5.83932796,15.499921 5.50354153,15.8357075 5.50354153,16.249921 L5.50354153,17.1572408 C5.50354153,17.8128951 5.78953221,18.4359296 6.28670709,18.8633654 C7.5447918,19.9450082 9.44080155,20.5010712 12,20.5010712 C14.5599799,20.5010712 16.4578003,19.9446634 17.7186879,18.8621641 C18.2165778,18.4347149 18.5030511,17.8112072 18.5030511,17.1550005 L18.5030511,16.249921 C18.5030511,15.8357075 18.1672647,15.499921 17.7530511,15.499921 Z M11.8985607,2.00734093 L12.0003312,2.00049432 C12.380027,2.00049432 12.6938222,2.2826482 12.7434846,2.64872376 L12.7503312,2.75049432 L12.7495415,3.49949432 L16.25,3.5 C17.4926407,3.5 18.5,4.50735931 18.5,5.75 L18.5,10.254591 C18.5,11.4972317 17.4926407,12.504591 16.25,12.504591 L7.75,12.504591 C6.50735931,12.504591 5.5,11.4972317 5.5,10.254591 L5.5,5.75 C5.5,4.50735931 6.50735931,3.5 7.75,3.5 L11.2495415,3.49949432 L11.2503312,2.75049432 C11.2503312,2.37079855 11.5324851,2.05700336 11.8985607,2.00734093 L12.0003312,2.00049432 L11.8985607,2.00734093 Z M16.25,5 L7.75,5 C7.33578644,5 7,5.33578644 7,5.75 L7,10.254591 C7,10.6688046 7.33578644,11.004591 7.75,11.004591 L16.25,11.004591 C16.6642136,11.004591 17,10.6688046 17,10.254591 L17,5.75 C17,5.33578644 16.6642136,5 16.25,5 Z M9.74928905,6.5 C10.4392523,6.5 10.9985781,7.05932576 10.9985781,7.74928905 C10.9985781,8.43925235 10.4392523,8.99857811 9.74928905,8.99857811 C9.05932576,8.99857811 8.5,8.43925235 8.5,7.74928905 C8.5,7.05932576 9.05932576,6.5 9.74928905,6.5 Z M14.2420255,6.5 C14.9319888,6.5 15.4913145,7.05932576 15.4913145,7.74928905 C15.4913145,8.43925235 14.9319888,8.99857811 14.2420255,8.99857811 C13.5520622,8.99857811 12.9927364,8.43925235 12.9927364,7.74928905 C12.9927364,7.05932576 13.5520622,6.5 14.2420255,6.5 Z"></path>
</g>
</g>

View File

@ -39,8 +39,10 @@ export const ChatWidget = () => {
CustomHeader={ChatWidgetHeader}
CustomAvatar={() => (
<Avatar
sx={{ width: "32px", height: "32px", fontSize: ".75rem" }}
src={getAvatarSrc(apiUrl, EntityType.USER, "bot")}
sx={{ width: "32px", height: "32px" }}
src={
getAvatarSrc(apiUrl, EntityType.USER, "bot") + "?color=%231ba089"
}
/>
)}
/>

View File

@ -1,7 +1,7 @@
.sc-header {
min-height: 64px;
border-top-left-radius: 9px;
border-top-right-radius: 9px;
border-top-left-radius: .5rem;
border-top-right-radius: .5rem;
padding: 10px;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
position: relative;

View File

@ -12,7 +12,7 @@
flex-direction: column;
justify-content: space-between;
border-radius: 10px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
animation: fadeIn;
animation-duration: 0.3s;
animation-timing-function: ease-in-out;

View File

@ -21,7 +21,7 @@
}
.sc-chat--disconnected-button {
border: 1px solid;
border-radius: 20px;
border-radius: 2rem;
padding: 5px 10px;
width: 80%;
margin: 2px;

View File

@ -38,7 +38,7 @@
display: flex;
flex-direction: row;
position: relative;
max-width: calc(100% - 60px);
max-width: calc(100% - 2rem);
width: auto;
.sc-message--avatar {
@ -49,7 +49,7 @@
background-position: 0 0;
flex-shrink: 0;
background-size: cover;
border-radius: 999px;
border-radius: 100%;
}
.sc-message--wrapper {
@ -59,11 +59,10 @@
.sc-message--text {
padding: 10px 20px;
border-radius: 6px;
font-weight: 300;
font-size: .85rem;
max-width: 190px;
line-height: 1.2;
border-radius: .5rem;
font-weight: 400;
font-size: .9rem;
line-height: 1.5;
position: relative;
-webkit-font-smoothing: subpixel-antialiased;
color: #263238;
@ -74,10 +73,6 @@
white-space: pre-wrap;
}
}
code {
font-family: "Courier New", Courier, monospace !important;
}
}
.sc-message--meta {

View File

@ -17,6 +17,7 @@ import { useColors } from '../providers/ColorProvider';
import { TMessage } from '../types/message.types';
import ChatIcon from './icons/ChatIcon';
import './Message.scss';
import ButtonsMessage from './messages/ButtonMessage';
import CarouselMessage from './messages/CarouselMessage';
import FileMessage from './messages/FileMessage';
@ -24,7 +25,6 @@ import GeolocationMessage from './messages/GeolocationMessage';
import ListMessage from './messages/ListMessage';
import TextMessage from './messages/TextMessage';
import MessageStatus from './MessageStatus';
import './Message.scss';
dayjs.extend(relativeTime);
@ -58,7 +58,11 @@ const Message: React.FC<MessageProps> = ({ message, Avatar }) => {
className="sc-message--avatar"
style={
user.imageUrl
? { backgroundImage: `url(${user.imageUrl})` }
? {
backgroundImage: `url(${
user.imageUrl
}?color=${encodeURIComponent(colors.header.bg)})`,
}
: undefined
}
>

View File

@ -1,13 +1,13 @@
.sc-suggestions-row {
text-align: center;
padding: 0.25rem 0;
padding: 0.5rem 0;
}
.sc-suggestions-element {
margin: 0 0 0.25rem 0.25rem;
margin: 0 0 0 0.25rem;
padding: 0.25rem 0.5rem;
border: 1px solid;
border-radius: 15px;
border-radius: 2rem;
font-size: 1rem;
background: inherit;
cursor: pointer;

View File

@ -5,10 +5,10 @@
bottom: 0;
display: flex;
background-color: #f4f7f9;
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
border-bottom-left-radius: .5rem;
border-bottom-right-radius: .5rem;
transition: background-color 0.2s ease, box-shadow 0.2s ease;
border: 1px solid #eaeaea;
border-top: 1px solid #eef2f4;
}
.sc-user-input--text {
@ -16,7 +16,7 @@
resize: none;
border: none;
outline: none;
border-bottom-left-radius: 10px;
border-bottom-left-radius: .5rem;
box-sizing: border-box;
padding: 18px 8px;
font-size: 15px;

View File

@ -21,17 +21,17 @@
.user-subscription-form {
.user-subscription-form-input {
border: 0;
background-color: #eeeeee;
border: 1px solid #dfe5e8;
outline: 0;
padding: 1rem;
border-radius: 10px;
border-radius: 2rem;
margin: 1rem;
width: 70%;
}
.user-subscription-form-button-submit {
display: block;
border-radius: 10px;
border-radius: 2rem;
border: 0;
width: 50%;
margin: 2rem auto;

View File

@ -9,46 +9,52 @@
import { FC, SVGProps } from 'react';
const ChatIcon: FC<SVGProps<SVGSVGElement>> = ({
viewBox = '-4749.48 -5020 35.036 35.036',
width = '18',
height = '18',
...rest
}) => {
return (
<svg xmlns="http://www.w3.org/2000/svg" viewBox={viewBox} {...rest}>
<defs>
<clipPath id="a">
<path
className="a"
style={{ fill: 'none' }}
d="M0-399.479H17.555v17.555H0Z"
transform="translate(0 399.479)"
/>
</clipPath>
</defs>
<g transform="translate(-4886 -5075)">
<circle
style={{ fill: '#4e8cff' }}
cx="17.518"
cy="17.518"
r="17.518"
transform="translate(136.52 55)"
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 42.555282 47.2949"
width={width}
height={height}
{...rest}
>
<g fillOpacity={1} strokeDasharray="none">
<path
d="M32.756 170.872l-4.26 7.482-2.786-7.494-8.211-.017a4.405 4.405 0 01-3.8-2.191l-6.443-11.087a4.215 4.215 0 01-.011-4.216l6.213-10.833a4.96 4.96 0 014.288-2.492l12.2-.034a4.715 4.715 0 014.09 2.347l6.16 10.602a4.864 4.864 0 01.02 4.855z"
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeOpacity={1}
strokeWidth={4.4649702399999995}
paintOrder="normal"
style={{
mixBlendMode: 'normal',
}}
transform="translate(-58.835 -133.808) translate(53.705 -18.313) scale(1.10427)"
/>
<g transform="translate(145.13 64)">
<g style={{ clipPath: "url('#a')" }}>
<g transform="translate(0 0)">
<path
style={{ fill: '#fff' }}
d="M-381.924-190.962a8.778,8.778,0,0,0-8.778-8.778,8.778,8.778,0,0,0-8.778,8.778,8.745,8.745,0,0,0,2.26,5.879v1.442c0,.8.492,1.457,1.1,1.457h5.83a.843.843,0,0,0,.183-.02,8.778,8.778,0,0,0,8.184-8.757"
transform="translate(399.479 199.74)"
/>
</g>
<g transform="translate(0 0)">
<path
style={{ fill: '#eff4f9' }}
d="M-68.763-194.079a9.292,9.292,0,0,1,6.38-8.888c-.252-.022-.506-.033-.763-.033a8.774,8.774,0,0,0-8.778,8.778A9.508,9.508,0,0,0-69.7-188.3c.005,0,0,.009,0,.01-.311.352-1.924,2.849.021,2.849h2.25c-1.23-.022,1.263-2.107.269-3.494a8.225,8.225,0,0,1-1.6-5.141"
transform="translate(71.924 203)"
/>
</g>
</g>
<g
fill="currentColor"
fillRule="nonzero"
stroke="none"
strokeWidth={0.662}
fillOpacity={1}
>
<path
d="M-532.348 630.303a6.253 6.253 0 11-12.506.023 6.253 6.253 0 0112.506-.023"
transform="translate(-58.835 -133.808) translate(53.705 -18.313) scale(1.10427) matrix(.25113 0 0 .25263 -27.6 133.42) matrix(1.51171 0 0 1.50275 1044.41 -860.854)"
/>
<path
d="M-532.348 630.303a6.253 6.253 0 11-12.506.023 6.253 6.253 0 0112.506-.023"
transform="translate(-58.835 -133.808) translate(53.705 -18.313) scale(1.10427) matrix(.25113 0 0 .25263 -27.6 133.42) matrix(1.51171 0 0 1.50275 992.8 -860.854)"
/>
<path
d="M-532.348 630.303a6.253 6.253 0 11-12.506.023 6.253 6.253 0 0112.506-.023"
transform="translate(-58.835 -133.808) translate(53.705 -18.313) scale(1.10427) matrix(.25113 0 0 .25263 -27.6 133.42) matrix(1.51171 0 0 1.50275 1018.605 -860.854)"
/>
</g>
</g>
</svg>

View File

@ -2,7 +2,7 @@
color: rgb(34, 34, 34);
max-width: -webkit-fill-available;
padding: 0.25rem 0.5rem;
border-radius: 6px;
border-radius: .5rem;
font-weight: 300;
font-size: 1.25rem;
line-height: 1.4;
@ -12,7 +12,7 @@
.sc-message--buttons-content {
border: 1px solid;
border-radius: 20px;
border-radius: 2rem;
padding: 0.25rem;
width: 80%;
margin: 2px;

View File

@ -1,5 +1,5 @@
.sc-message--carousel {
border-radius: 10px;
border-radius: .5rem;
position: relative;
width: 100%;
overflow: hidden;

View File

@ -1,6 +1,6 @@
.sc-message--file {
background-color: transparent !important;
border-radius: 6px;
border-radius: .5rem;
font-weight: 300;
font-size: 14px;
line-height: 1.4;
@ -31,7 +31,7 @@
.sc-message--file-download {
padding: 10px 20px;
border-radius: 6px;
border-radius: .5rem;
color: white;
text-align: center;

View File

@ -1,8 +1,8 @@
.sc-message--location {
border-radius: 6px;
border-radius: .5rem;
}
.sc-message-map {
width: 200px;
height: 150px;
border-radius: 6px;
border-radius: .5rem;
}

View File

@ -1,5 +1,5 @@
.sc-message--list {
border-radius: 10px;
border-radius: .5rem;
width: 256px;
.sc-message--list-element {
@ -19,12 +19,12 @@
.sc-message--list-element-image {
background-size: cover;
height: auto;
border-radius: 10px 10px 0 0;
border-radius: .5rem .5rem 0 0;
}
.sc-message--list-element-description {
color: #fff;
border-radius: 10px 10px 0 0;
border-radius: .5rem .5rem 0 0;
background: rgba(0, 0, 0, 0.5);
}
}

View File

@ -1,7 +1,7 @@
.sc-typing-indicator {
text-align: center;
padding: 2px 5px;
border-radius: 6px;
padding: .5rem;
border-radius: 2rem;
width: 50px;
margin-left: 2rem;
}

View File

@ -25,11 +25,11 @@ const colors: Record<string, ColorState> = {
text: '#fff',
},
received: {
bg: '#eaeaea',
bg: '#f6f8f9',
text: '#000',
},
userInput: {
bg: '#fbfbfb',
bg: '#fff',
text: '#000',
},
button: {
@ -60,11 +60,11 @@ const colors: Record<string, ColorState> = {
text: '#fff',
},
received: {
bg: '#eaeaea',
bg: '#f6f8f9',
text: '#000',
},
userInput: {
bg: '#fbfbfb',
bg: '#fff',
text: '#000',
},
button: {
@ -95,11 +95,11 @@ const colors: Record<string, ColorState> = {
text: '#fff',
},
received: {
bg: '#eaeaea',
bg: '#f6f8f9',
text: '#000',
},
userInput: {
bg: '#fbfbfb',
bg: '#fff',
text: '#000',
},
button: {
@ -130,11 +130,11 @@ const colors: Record<string, ColorState> = {
text: '#fff',
},
received: {
bg: '#eaeaea',
bg: '#f6f8f9',
text: '#000',
},
userInput: {
bg: '#fbfbfb',
bg: '#fff',
text: '#000',
},
button: {
@ -165,11 +165,11 @@ const colors: Record<string, ColorState> = {
text: '#fff',
},
received: {
bg: '#eaeaea',
bg: '#f6f8f9',
text: '#000',
},
userInput: {
bg: '#fbfbfb',
bg: '#fff',
text: '#000',
},
button: {
@ -200,15 +200,15 @@ const colors: Record<string, ColorState> = {
text: '#FFF',
},
received: {
bg: '#F0F0F0',
bg: '#f6f8f9',
text: '#000',
},
userInput: {
bg: '#FFF',
bg: '#fff',
text: '#000',
},
button: {
bg: '#2c3e50',
bg: '#000',
text: '#ecf0f1',
border: '#34495e',
},

View File

@ -109,7 +109,7 @@ export const SettingsProvider: React.FC<ChatSettingsProviderProps> = ({
allowedUploadSize: settings.allowed_upload_size,
inputDisabled: settings.input_disabled,
color: settings.theme_color,
greetingMessage: t('settings.greeting'),
greetingMessage: settings.greeting_message,
placeholder: t('settings.placeholder'),
avatarUrl: settings.avatar_url,
});

View File

@ -7,7 +7,7 @@
*/
export type ColorState = {
header: { bg?: string; text?: string };
header: { bg: string; text: string };
launcher: { bg?: string };
messageList: { bg?: string };
sent: { bg?: string; text?: string };