Skip to content

Commit e5d97ee

Browse files
authored
Merge pull request #10 from yassineselmi/inject-additional-headers
Inject additional headers
2 parents 3c1d2b0 + fe9ba1e commit e5d97ee

6 files changed

Lines changed: 23 additions & 5 deletions

File tree

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ Use the widget API to customize your widget:
124124
| user_message_style | json | No |
125125
| width | number | No |
126126
| window_title | string | No |
127+
| additional_headers | json | No |
127128

128129
- **bot_message_style:**
129130
- Type: JSON
@@ -240,6 +241,12 @@ Use the widget API to customize your widget:
240241
- Required: No
241242
- Description: Title for the chat window, displayed in the header or title bar.
242243

244+
- **additional_headers:**
245+
- Type: JSON
246+
- Required: No
247+
- Description: Additional headers to be sent to Langflow server
248+
249+
243250
## Live example:
244251
Try out or [live example](https://codesandbox.io/s/langflow-embedded-chat-example-dv9zpx) to see how the Langflow Embedded Chat ⛓️ works.
245252

dist/build/static/js/bundle.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/chatWidget/chatWindow/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ export default function ChatWindow({
3535
width = 450,
3636
height = 650,
3737
tweaks,
38-
sessionId
38+
sessionId,
39+
additional_headers
3940
}: {
4041
api_key?: string;
4142
chat_inputs: Object;
@@ -67,6 +68,8 @@ export default function ChatWindow({
6768
width?: number;
6869
height?: number;
6970
sessionId: React.MutableRefObject<string>;
71+
additional_headers?: {[key:string]:string};
72+
7073
}) {
7174
const [value, setValue] = useState<string>("");
7275
const ref = useRef<HTMLDivElement>(null);
@@ -102,7 +105,7 @@ export default function ChatWindow({
102105
addMessage({ message: value, isSend: true });
103106
setSendingMessage(true);
104107
setValue("");
105-
sendMessage(hostUrl, flowId, value, chat_inputs,chat_input_field,sessionId, tweaks,api_key)
108+
sendMessage(hostUrl, flowId, value, chat_inputs,chat_input_field,sessionId, tweaks,api_key, additional_headers)
106109
.then((res) => {
107110
if (
108111
res.data &&

src/chatWidget/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export default function ChatWidget({
2929
input_style,
3030
placeholder_sending,
3131
input_container_style,
32+
additional_headers,
3233
}: {
3334
api_key?: string;
3435
chat_inputs: Object;
@@ -55,6 +56,7 @@ export default function ChatWidget({
5556
host_url: string;
5657
flow_id: string;
5758
tweaks?: { [key: string]: any };
59+
additional_headers?: {[key:string]:string};
5860
}) {
5961
const [open, setOpen] = useState(false);
6062
const [messages, setMessages] = useState<ChatMessageType[]>([]);
@@ -1009,6 +1011,7 @@ input::-ms-input-placeholder { /* Microsoft Edge */
10091011
triggerRef={triggerRef}
10101012
position={chat_position}
10111013
sessionId={sessionId}
1014+
additional_headers={additional_headers}
10121015
/>
10131016
</>
10141017
);

src/controllers/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import axios from "axios";
22

3-
export async function sendMessage(baseUrl: string, flowId: string, message: string,inputs: any,input_field:string,sessionId:React.MutableRefObject<string>, tweaks?: Object,api_key?:string) {
3+
export async function sendMessage(baseUrl: string, flowId: string, message: string,inputs: any,input_field:string,sessionId:React.MutableRefObject<string>, tweaks?: Object,api_key?:string,additional_headers?:{[key:string]:string}) {
44
let data:any;
55
inputs[input_field] = message;
66
if (tweaks) {
@@ -9,10 +9,14 @@ export async function sendMessage(baseUrl: string, flowId: string, message: stri
99
else {
1010
data = { inputs: inputs };
1111
}
12-
const headers:{[key:string]:string}= {"Content-Type": "application/json"}
12+
let headers:{[key:string]:string}= {"Content-Type": "application/json"}
1313
if( api_key){
1414
headers["x-api-key"]=api_key;
1515
}
16+
if (additional_headers){
17+
headers = Object.assign(headers, additional_headers);
18+
// headers = {...headers, ...additional_headers};
19+
}
1620
if(sessionId.current && sessionId.current!=""){
1721
data.session_id=sessionId.current;
1822
}

src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ customElements.define('langflow-chat', r2wc(ChatWidget, {
2828
input_style:"json",
2929
input_container_style:"json",
3030
chat_position:"string",
31+
additional_headers:"json",
3132
},
3233
}));

0 commit comments

Comments
 (0)