Skip to content

Commit

Permalink
feat(chatWidget): add support for api_key prop in ChatWidget and Chat…
Browse files Browse the repository at this point in the history
…Window components to pass API key to sendMessage function

fix(controllers): modify sendMessage function to include api_key in the request data if provided

feat(index.tsx): add api_key prop to ChatWidget component in custom element definition
  • Loading branch information
anovazzi1 committed Aug 24, 2023
1 parent 50235a4 commit 56e5a63
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/chatWidget/chatWindow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ChatMessage from "./chatMessage";
import { sendMessage } from "../../controllers";

export default function ChatWindow({
api_key,
flowId,
hostUrl,
updateLastMessage,
Expand Down Expand Up @@ -35,6 +36,7 @@ export default function ChatWindow({
height = 650,
tweaks,
}: {
api_key?: string;
chat_inputs: Object;
chat_input_field: string;
bot_message_style?: React.CSSProperties;
Expand Down Expand Up @@ -86,7 +88,7 @@ export default function ChatWindow({
addMessage({ message: value, isSend: true });
setSendingMessage(true);
setValue("");
sendMessage(hostUrl, flowId, value, chat_inputs, chat_input_field, tweaks)
sendMessage(hostUrl, flowId, value, chat_inputs, chat_input_field, tweaks,api_key)
.then((res) => {
if (
res.data &&
Expand Down
3 changes: 3 additions & 0 deletions src/chatWidget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ChatWindow from "./chatWindow";
import { ChatMessageType } from "../types/chatWidget";

export default function ChatWidget({
api_key,
chat_input_field,
chat_inputs,
chat_trigger_style,
Expand All @@ -29,6 +30,7 @@ export default function ChatWidget({
placeholder_sending,
input_container_style,
}: {
api_key?: string;
chat_inputs: Object;
chat_input_field: string;
send_icon_style?: React.CSSProperties;
Expand Down Expand Up @@ -976,6 +978,7 @@ input::-ms-input-placeholder { /* Microsoft Edge */
style={chat_trigger_style}
/>
<ChatWindow
api_key={api_key}
chat_input_field={chat_input_field}
chat_inputs={chat_inputs}
open={open}
Expand Down
5 changes: 4 additions & 1 deletion src/controllers/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from "axios";

export async function sendMessage(baseUrl: string, flowId: string, message: string,inputs: any,input_field:string, tweaks?: Object,) {
export async function sendMessage(baseUrl: string, flowId: string, message: string,inputs: any,input_field:string, tweaks?: Object,api_key?:string) {
let data;
inputs[input_field] = message;
if (tweaks) {
Expand All @@ -9,6 +9,9 @@ export async function sendMessage(baseUrl: string, flowId: string, message: stri
else {
data = { inputs: inputs };
}
if(api_key){
data = {...data, api_key};
}
let response = axios.post(`${baseUrl}/api/v1/process/${flowId}`, data,{headers:{"Content-Type": "application/json"}});
return response;
}
1 change: 1 addition & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ChatWidget from './chatWidget';
customElements.define('langflow-chat', r2wc(ChatWidget, {
shadow: "closed",
props: {
api_key: "string",
chat_input_field:"string",
chat_inputs: "json",
chat_trigger_style: "json",
Expand Down

0 comments on commit 56e5a63

Please sign in to comment.