Skip to content

Fix for 401 Unauthorized #15

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ yarn build
Chatbot.init({
chatflowid: "<chatflowid>",
apiHost: "http://localhost:3000",
authToken: "<chatflowapikey>",
});
</script>
```
Expand All @@ -46,6 +47,7 @@ yarn build
Chatbot.initFull({
chatflowid: "<chatflowid>",
apiHost: "http://localhost:3000",
authToken: "<chatflowapikey>",
});
</script>
<flowise-fullchatbot></flowise-fullchatbot>
Expand All @@ -72,6 +74,7 @@ You can also customize chatbot with different configuration
Chatbot.init({
chatflowid: "91e9c803-5169-4db9-8207-3c0915d71c5f",
apiHost: "http://localhost:3000",
authToken: "<chatflowapikey>",
chatflowConfig: {
// topK: 2
},
Expand Down
1 change: 1 addition & 0 deletions dist/components/Bot.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type BotProps = {
chatflowid: string;
apiHost?: string;
chatflowConfig?: Record<string, unknown>;
authToken?: string;
welcomeMessage?: string;
botMessage?: BotMessageTheme;
userMessage?: UserMessageTheme;
Expand Down
2 changes: 1 addition & 1 deletion dist/components/Bot.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/constants.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/features/bubble/components/Bubble.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/features/full/components/Full.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions dist/queries/sendMessageQuery.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ export type MessageRequest = {
chatflowid: string;
apiHost?: string;
body?: IncomingInput;
authToken?: string;
};
export declare const sendMessageQuery: ({ chatflowid, apiHost, body }: MessageRequest) => Promise<{
export declare const sendMessageQuery: ({ chatflowid, apiHost, body, authToken }: MessageRequest) => Promise<{
data?: any;
error?: Error | undefined;
}>;
export declare const isStreamAvailableQuery: ({ chatflowid, apiHost }: MessageRequest) => Promise<{
export declare const isStreamAvailableQuery: ({ chatflowid, apiHost, authToken }: MessageRequest) => Promise<{
data?: any;
error?: Error | undefined;
}>;
Expand Down
2 changes: 1 addition & 1 deletion dist/queries/sendMessageQuery.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/utils/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export declare const sendRequest: <ResponseData>(params: {
url: string;
method: string;
body?: Record<string, unknown> | FormData;
authToken?: string;
} | string) => Promise<{
data?: ResponseData | undefined;
error?: Error | undefined;
Expand Down
2 changes: 1 addition & 1 deletion dist/utils/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions dist/web.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ declare const chatbot: {
initFull: (props: {
chatflowid: string;
apiHost?: string | undefined;
authToken?: string | undefined;
chatflowConfig?: Record<string, unknown> | undefined;
} & {
id?: string | undefined;
}) => void;
init: (props: {
chatflowid: string;
apiHost?: string | undefined;
authToken?: string | undefined;
chatflowConfig?: Record<string, unknown> | undefined;
}) => void;
};
Expand Down
2 changes: 1 addition & 1 deletion dist/web.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/web.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/window.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
type BotProps = {
chatflowid: string;
apiHost?: string;
authToken?: string;
chatflowConfig?: Record<string, unknown>;
};
export declare const initFull: (props: BotProps & {
Expand Down
2 changes: 1 addition & 1 deletion dist/window.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/components/Bot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type BotProps = {
chatflowid: string
apiHost?: string
chatflowConfig?: Record<string, unknown>
authToken?: string
welcomeMessage?: string
botMessage?: BotMessageTheme
userMessage?: UserMessageTheme
Expand Down Expand Up @@ -198,6 +199,7 @@ export const Bot = (props: BotProps & { class?: string }) => {
const { data, error } = await sendMessageQuery({
chatflowid: props.chatflowid,
apiHost: props.apiHost,
authToken: props.authToken,
body
})

Expand Down Expand Up @@ -239,6 +241,7 @@ export const Bot = (props: BotProps & { class?: string }) => {
const { data } = await isStreamAvailableQuery({
chatflowid: props.chatflowid,
apiHost: props.apiHost,
authToken: props.authToken
})

if (data) {
Expand Down
3 changes: 2 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export const defaultBotProps: BubbleProps = {
chatflowid: '',
apiHost: undefined,
chatflowConfig: undefined,
theme: undefined
theme: undefined,
authToken: undefined
}
1 change: 1 addition & 0 deletions src/features/bubble/components/Bubble.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const Bubble = (props: BubbleProps) => {
userMessage={bubbleProps.theme?.chatWindow?.userMessage}
fontSize={bubbleProps.theme?.chatWindow?.fontSize}
chatflowid={props.chatflowid}
authToken={props.authToken}
chatflowConfig={props.chatflowConfig}
apiHost={props.apiHost} />
</Show>
Expand Down
1 change: 1 addition & 0 deletions src/features/full/components/Full.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const Full = (
userMessage={props.theme?.chatWindow?.userMessage}
fontSize={props.theme?.chatWindow?.fontSize}
chatflowid={props.chatflowid}
authToken={props.authToken}
chatflowConfig={props.chatflowConfig}
apiHost={props.apiHost} />
</div>
Expand Down
9 changes: 6 additions & 3 deletions src/queries/sendMessageQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@ export type MessageRequest = {
chatflowid: string
apiHost?: string
body?: IncomingInput
authToken?: string
}

export const sendMessageQuery = ({ chatflowid, apiHost = 'http://localhost:3000', body }: MessageRequest) =>
export const sendMessageQuery = ({ chatflowid, apiHost = 'http://localhost:3000', body, authToken }: MessageRequest) =>
sendRequest<any>({
method: 'POST',
url: `${apiHost}/api/v1/prediction/${chatflowid}`,
body
body,
authToken
})

export const isStreamAvailableQuery = ({ chatflowid, apiHost = 'http://localhost:3000' }: MessageRequest) =>
export const isStreamAvailableQuery = ({ chatflowid, apiHost = 'http://localhost:3000', authToken }: MessageRequest) =>
sendRequest<any>({
method: 'GET',
url: `${apiHost}/api/v1/chatflows-streaming/${chatflowid}`,
authToken
})
7 changes: 5 additions & 2 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const sendRequest = async <ResponseData>(
url: string
method: string
body?: Record<string, unknown> | FormData
authToken?: string
}
| string
): Promise<{ data?: ResponseData; error?: Error }> => {
Expand All @@ -21,9 +22,10 @@ export const sendRequest = async <ResponseData>(
method: typeof params === 'string' ? 'GET' : params.method,
mode: 'cors',
headers:
typeof params !== 'string' && isDefined(params.body)
typeof params !== 'string'
? {
'Content-Type': 'application/json'
'Content-Type': isDefined(params.body) ? 'application/json' : undefined,
'Authorization': params.authToken ? `Bearer ${params.authToken}` : undefined,
}
: undefined,
body: typeof params !== 'string' && isDefined(params.body) ? JSON.stringify(params.body) : undefined
Expand All @@ -36,3 +38,4 @@ export const sendRequest = async <ResponseData>(
return { error: e as Error }
}
}

1 change: 1 addition & 0 deletions src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
type BotProps = {
chatflowid: string
apiHost?: string
authToken?: string
chatflowConfig?: Record<string, unknown>
}

Expand Down
Loading