Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SBTW-1940] Optimize Interactive Demo #374

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { j as e } from "./index-0cbad462.mjs";
import { j as e } from "./index-83624634.mjs";
import { CopyBlock as r, irBlack as t } from "react-code-blocks";
import "react";
import "react-dom";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { c as F } from "./index-0cbad462.mjs";
import { c as F } from "./index-83624634.mjs";
function I(s, h) {
for (var b = 0; b < h.length; b++) {
const c = h[b];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { L as S, g as s, R as X, a as m, P as y, Y as I, H as N, X as b } from "./index-0cbad462.mjs";
import { L as S, g as s, R as X, a as m, P as y, Y as I, H as N, X as b } from "./index-83624634.mjs";
import "react";
import "react-dom";
var k = function(i, o) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { c as g } from "./index-0cbad462.mjs";
import { c as g } from "./index-83624634.mjs";
function H(e, t) {
for (var o = 0; o < t.length; o++) {
const s = t[o];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { V as g2 } from "./index-0cbad462.mjs";
import { V as g2 } from "./index-83624634.mjs";
import "react";
import "react-dom";
function Mt(H) {
Expand Down
2 changes: 1 addition & 1 deletion dist/components/Chat.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Props as ChatWidgetProps } from './ChatAiWidget';
declare const Chat: ({ applicationId, botId, hashedKey, isOpen, ...constantProps }: ChatWidgetProps & {
declare const Chat: ({ apiHost, applicationId, botId, hashedKey, isOpen, ...constantProps }: ChatWidgetProps & {
isOpen: boolean;
}) => import("react/jsx-runtime").JSX.Element;
export default Chat;
1 change: 1 addition & 0 deletions dist/const.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type FirstMessageItem = {
message: string;
};
export interface Constant {
apiHost?: string;
botCategory: string;
botNickName: string;
userId: string;
Expand Down
5,008 changes: 2,506 additions & 2,502 deletions dist/index-0cbad462.mjs → dist/index-83624634.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.es.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { b as r, C as m } from "./index-0cbad462.mjs";
import { b as r, C as m } from "./index-83624634.mjs";
import "react";
import "react-dom";
export {
Expand Down
106 changes: 53 additions & 53 deletions dist/index.umd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sendbird/chat-ai-widget",
"version": "1.1.0-interactive-demo-fintech-19",
"version": "1.1.0-interactive-demo-fintech-20",
"description": "Sendbird Chat AI Widget,\n Detailed documentation can be found at https://github.com/sendbird/chat-ai-widget#readme",
"main": "./dist/index.umd.js",
"module": "./dist/index.es.js",
Expand Down
10 changes: 8 additions & 2 deletions src/components/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ import {
useChatWindowLoadTime,
} from '../hooks/useInteractiveDemoSharableData';
import { assert, isMobile } from '../utils';
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';

const SBComponent = () => {
const {
apiHost,
applicationId,
botId,
userId,
Expand All @@ -32,10 +33,12 @@ const SBComponent = () => {
enableMention,
} = useConstantState();

assert(apiHost !== null, 'apiHost must be provided');
bang9 marked this conversation as resolved.
Show resolved Hide resolved
assert(
applicationId !== null && botId !== null,
'applicationId and botId must be provided'
);

const { sbConnectionStatus } = useSbConnectionState();
const sdkInitParams = useMemo(
() => ({
Expand All @@ -62,7 +65,7 @@ const SBComponent = () => {
appId={applicationId}
userId={userId}
nickname={userNickName}
customApiHost={`https://api-${applicationId}.sendbird.com`}
customApiHost={apiHost || `https://api-${applicationId}.sendbird.com`}
customWebSocketHost={`wss://ws-${applicationId}.sendbird.com`}
sdkInitParams={sdkInitParams}
configureSession={configureSession}
Expand All @@ -88,6 +91,7 @@ const SBComponent = () => {
};

const Chat = ({
apiHost,
applicationId,
botId,
hashedKey,
Expand All @@ -99,6 +103,7 @@ const Chat = ({
const CHAT_WIDGET_APP_ID = import.meta.env.VITE_CHAT_WIDGET_APP_ID;
const CHAT_WIDGET_BOT_ID = import.meta.env.VITE_CHAT_WIDGET_BOT_ID;

assert(apiHost !== null, 'apiHost must be provided');
bang9 marked this conversation as resolved.
Show resolved Hide resolved
assert(
applicationId !== null && botId !== null,
'applicationId and botId must be provided'
Expand All @@ -119,6 +124,7 @@ const Chat = ({
<ConstantStateProvider
// If env is not provided, prop will be used instead.
// But Either should be provided.
apiHost={apiHost}
applicationId={CHAT_WIDGET_APP_ID ?? applicationId}
botId={CHAT_WIDGET_BOT_ID ?? botId}
{...constantProps}
Expand Down
17 changes: 10 additions & 7 deletions src/components/CustomHealthcareMessageInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,12 @@ export function HealthcareMessageInput({

const { isPending } = useQuery({
queryKey: ["getAIRecommendMessage", bodyInput],
queryFn: () =>
axios
queryFn: () => {
// bodyinput must includes 2 objects, role and assistant
const isInvalidBodyInput = !bodyInput || bodyInput.length < 2;
if (isInvalidBodyInput) return Promise.resolve([]);

return axios
.post(`/api/assistant`, {
params: {
botId: "healthcare",
Expand All @@ -523,7 +527,8 @@ export function HealthcareMessageInput({
setShowTip(false);
setRecommendMessage(response.data.reply_messages[0]);
return response.data;
}),
});
},
});

async function getRecommendMessage(bodyInput?: any[]) {
Expand Down Expand Up @@ -853,7 +858,7 @@ export function HealthcareMessageInput({
{showTip ? "Tips for using AI assistant" : "Suggested by AI"}
</AIAssistantBodyHeadText>
</div>
{isPending ? (
{isPending || showTip ? (
<div
style={{
display: "flex",
Expand All @@ -869,9 +874,7 @@ export function HealthcareMessageInput({
type={LabelTypography.BODY_1}
color={LabelColors.ONBACKGROUND_1}
>
{showTip
? "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor "
: recommendMessage}
{recommendMessage}
</AIAssistantBodyText>
)}
</TextContainer>
Expand Down
1 change: 1 addition & 0 deletions src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ type FirstMessageItem = {
};

export interface Constant {
apiHost?: string;
botCategory: string;
botNickName: string;
userId: string;
Expand Down
1 change: 1 addition & 0 deletions src/context/ConstantContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type ProviderProps = React.PropsWithChildren<ConstantContextProps>;
export const ConstantStateProvider = (props: ProviderProps) => {
const memoizedValue = useMemo(
() => ({
apiHost: props.apiHost,
applicationId: props.applicationId,
botId: props.botId,
botCategory: props.botCategory ?? initialState.botCategory,
Expand Down