llmasaservice-ui 0.9.2 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +66 -44
- package/dist/index.mjs +66 -44
- package/package.json +1 -1
- package/src/AgentPanel.tsx +6 -0
- package/src/ChatPanel.tsx +71 -50
package/dist/index.d.mts
CHANGED
|
@@ -65,7 +65,7 @@ interface ChatPanelProps {
|
|
|
65
65
|
};
|
|
66
66
|
hideRagContextInPrompt?: boolean;
|
|
67
67
|
createConversationOnFirstChat?: boolean;
|
|
68
|
-
customerEmailCaptureMode?: "
|
|
68
|
+
customerEmailCaptureMode?: "HIDE" | "OPTIONAL" | "REQUIRED";
|
|
69
69
|
customerEmailCapturePlaceholder?: string;
|
|
70
70
|
}
|
|
71
71
|
interface ExtraProps$1 extends React.HTMLAttributes<HTMLElement> {
|
|
@@ -120,6 +120,8 @@ interface AgentPanelProps {
|
|
|
120
120
|
};
|
|
121
121
|
hideRagContextInPrompt?: boolean;
|
|
122
122
|
createConversationOnFirstChat?: boolean;
|
|
123
|
+
customerEmailCaptureMode?: "HIDE" | "OPTIONAL" | "REQUIRED";
|
|
124
|
+
customerEmailCapturePlaceholder?: string;
|
|
123
125
|
}
|
|
124
126
|
interface ExtraProps extends React.HTMLAttributes<HTMLElement> {
|
|
125
127
|
inline?: boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -65,7 +65,7 @@ interface ChatPanelProps {
|
|
|
65
65
|
};
|
|
66
66
|
hideRagContextInPrompt?: boolean;
|
|
67
67
|
createConversationOnFirstChat?: boolean;
|
|
68
|
-
customerEmailCaptureMode?: "
|
|
68
|
+
customerEmailCaptureMode?: "HIDE" | "OPTIONAL" | "REQUIRED";
|
|
69
69
|
customerEmailCapturePlaceholder?: string;
|
|
70
70
|
}
|
|
71
71
|
interface ExtraProps$1 extends React.HTMLAttributes<HTMLElement> {
|
|
@@ -120,6 +120,8 @@ interface AgentPanelProps {
|
|
|
120
120
|
};
|
|
121
121
|
hideRagContextInPrompt?: boolean;
|
|
122
122
|
createConversationOnFirstChat?: boolean;
|
|
123
|
+
customerEmailCaptureMode?: "HIDE" | "OPTIONAL" | "REQUIRED";
|
|
124
|
+
customerEmailCapturePlaceholder?: string;
|
|
123
125
|
}
|
|
124
126
|
interface ExtraProps extends React.HTMLAttributes<HTMLElement> {
|
|
125
127
|
inline?: boolean;
|
package/dist/index.js
CHANGED
|
@@ -168,7 +168,7 @@ var ChatPanel = ({
|
|
|
168
168
|
initialHistory = {},
|
|
169
169
|
hideRagContextInPrompt = true,
|
|
170
170
|
createConversationOnFirstChat = true,
|
|
171
|
-
customerEmailCaptureMode = "
|
|
171
|
+
customerEmailCaptureMode = "HIDE",
|
|
172
172
|
customerEmailCapturePlaceholder = "Please enter your email..."
|
|
173
173
|
}) => {
|
|
174
174
|
var _a;
|
|
@@ -198,7 +198,7 @@ var ChatPanel = ({
|
|
|
198
198
|
);
|
|
199
199
|
const [emailValid, setEmailValid] = (0, import_react2.useState)(true);
|
|
200
200
|
const [showEmailPanel, setShowEmailPanel] = (0, import_react2.useState)(
|
|
201
|
-
customerEmailCaptureMode !== "
|
|
201
|
+
customerEmailCaptureMode !== "HIDE"
|
|
202
202
|
);
|
|
203
203
|
const [callToActionSent, setCallToActionSent] = (0, import_react2.useState)(false);
|
|
204
204
|
const [CTAClickedButNoEmail, setCTAClickedButNoEmail] = (0, import_react2.useState)(false);
|
|
@@ -222,8 +222,8 @@ var ChatPanel = ({
|
|
|
222
222
|
publicAPIUrl = "https://8ftw8droff.execute-api.us-east-1.amazonaws.com/dev";
|
|
223
223
|
}
|
|
224
224
|
(0, import_react2.useEffect)(() => {
|
|
225
|
-
setShowEmailPanel(customerEmailCaptureMode !== "
|
|
226
|
-
if (customerEmailCaptureMode === "
|
|
225
|
+
setShowEmailPanel(customerEmailCaptureMode !== "HIDE");
|
|
226
|
+
if (customerEmailCaptureMode === "REQUIRED") {
|
|
227
227
|
if (!isEmailAddress(emailInput)) {
|
|
228
228
|
setEmailValid(false);
|
|
229
229
|
}
|
|
@@ -428,6 +428,42 @@ var ChatPanel = ({
|
|
|
428
428
|
}
|
|
429
429
|
return void 0;
|
|
430
430
|
};
|
|
431
|
+
const ensureConversation = () => {
|
|
432
|
+
var _a2, _b;
|
|
433
|
+
if ((!currentConversation || currentConversation === "") && createConversationOnFirstChat) {
|
|
434
|
+
return fetch(`${publicAPIUrl}/conversations`, {
|
|
435
|
+
method: "POST",
|
|
436
|
+
headers: {
|
|
437
|
+
"Content-Type": "application/json"
|
|
438
|
+
},
|
|
439
|
+
body: JSON.stringify({
|
|
440
|
+
project_id: project_id != null ? project_id : "",
|
|
441
|
+
agentId: agent,
|
|
442
|
+
customerId: (_a2 = currentCustomer == null ? void 0 : currentCustomer.customer_id) != null ? _a2 : null,
|
|
443
|
+
customerEmail: (_b = currentCustomer == null ? void 0 : currentCustomer.customer_user_email) != null ? _b : null
|
|
444
|
+
})
|
|
445
|
+
}).then((res) => __async(void 0, null, function* () {
|
|
446
|
+
if (!res.ok) {
|
|
447
|
+
const errorText = yield res.text();
|
|
448
|
+
throw new Error(
|
|
449
|
+
`HTTP error! status: ${res.status}, message: ${errorText}`
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
return res.json();
|
|
453
|
+
})).then((newConvo) => {
|
|
454
|
+
if (newConvo == null ? void 0 : newConvo.id) {
|
|
455
|
+
console.log("new conversation created", newConvo.id);
|
|
456
|
+
setCurrentConversation(newConvo.id);
|
|
457
|
+
return newConvo.id;
|
|
458
|
+
}
|
|
459
|
+
return "";
|
|
460
|
+
}).catch((error) => {
|
|
461
|
+
console.error("Error creating new conversation", error);
|
|
462
|
+
return "";
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
return Promise.resolve(currentConversation);
|
|
466
|
+
};
|
|
431
467
|
(0, import_react2.useEffect)(() => {
|
|
432
468
|
var _a2, _b, _c;
|
|
433
469
|
console.log("currentCustomer effect", currentCustomer);
|
|
@@ -463,45 +499,27 @@ var ChatPanel = ({
|
|
|
463
499
|
}
|
|
464
500
|
}
|
|
465
501
|
if (needsUpdate) {
|
|
502
|
+
ensureConversation().then((convId) => {
|
|
503
|
+
console.log(
|
|
504
|
+
"updating conversation with customer id and email",
|
|
505
|
+
convId,
|
|
506
|
+
currentCustomer
|
|
507
|
+
);
|
|
508
|
+
const r = fetch(`${publicAPIUrl}/conversations/${convId}`, {
|
|
509
|
+
method: "POST",
|
|
510
|
+
headers: {
|
|
511
|
+
"Content-Type": "application/json"
|
|
512
|
+
},
|
|
513
|
+
body: JSON.stringify({
|
|
514
|
+
project_id: project_id != null ? project_id : "",
|
|
515
|
+
customerId: currentCustomer.customer_id,
|
|
516
|
+
customerEmail: currentCustomer.customer_user_email
|
|
517
|
+
})
|
|
518
|
+
});
|
|
519
|
+
});
|
|
466
520
|
setCurrentCustomer(updatedValues);
|
|
467
521
|
}
|
|
468
522
|
}, [currentCustomer]);
|
|
469
|
-
const ensureConversation = () => {
|
|
470
|
-
var _a2, _b;
|
|
471
|
-
if ((!currentConversation || currentConversation === "") && createConversationOnFirstChat) {
|
|
472
|
-
return fetch(`${publicAPIUrl}/conversations`, {
|
|
473
|
-
method: "POST",
|
|
474
|
-
headers: {
|
|
475
|
-
"Content-Type": "application/json"
|
|
476
|
-
},
|
|
477
|
-
body: JSON.stringify({
|
|
478
|
-
project_id: project_id != null ? project_id : "",
|
|
479
|
-
agentId: agent,
|
|
480
|
-
customerId: (_a2 = currentCustomer == null ? void 0 : currentCustomer.customer_id) != null ? _a2 : null,
|
|
481
|
-
customerEmail: (_b = currentCustomer == null ? void 0 : currentCustomer.customer_user_email) != null ? _b : null
|
|
482
|
-
})
|
|
483
|
-
}).then((res) => __async(void 0, null, function* () {
|
|
484
|
-
if (!res.ok) {
|
|
485
|
-
const errorText = yield res.text();
|
|
486
|
-
throw new Error(
|
|
487
|
-
`HTTP error! status: ${res.status}, message: ${errorText}`
|
|
488
|
-
);
|
|
489
|
-
}
|
|
490
|
-
return res.json();
|
|
491
|
-
})).then((newConvo) => {
|
|
492
|
-
if (newConvo == null ? void 0 : newConvo.id) {
|
|
493
|
-
console.log("new conversation created", newConvo.id);
|
|
494
|
-
setCurrentConversation(newConvo.id);
|
|
495
|
-
return newConvo.id;
|
|
496
|
-
}
|
|
497
|
-
return "";
|
|
498
|
-
}).catch((error) => {
|
|
499
|
-
console.error("Error creating new conversation", error);
|
|
500
|
-
return "";
|
|
501
|
-
});
|
|
502
|
-
}
|
|
503
|
-
return Promise.resolve(currentConversation);
|
|
504
|
-
};
|
|
505
523
|
const continueChat = (suggestion) => {
|
|
506
524
|
console.log("continueChat", suggestion);
|
|
507
525
|
ensureConversation().then((convId) => {
|
|
@@ -857,7 +875,7 @@ var ChatPanel = ({
|
|
|
857
875
|
const isDisabledDueToNoEmail = () => {
|
|
858
876
|
const valid = isEmailAddress(emailInput);
|
|
859
877
|
if (valid) return false;
|
|
860
|
-
if (customerEmailCaptureMode === "
|
|
878
|
+
if (customerEmailCaptureMode === "REQUIRED") return true;
|
|
861
879
|
};
|
|
862
880
|
return /* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, null, /* @__PURE__ */ import_react2.default.createElement(
|
|
863
881
|
"div",
|
|
@@ -1006,7 +1024,7 @@ var ChatPanel = ({
|
|
|
1006
1024
|
setEmailClickedButNoEmail(false);
|
|
1007
1025
|
}
|
|
1008
1026
|
} else {
|
|
1009
|
-
if (customerEmailCaptureMode === "
|
|
1027
|
+
if (customerEmailCaptureMode === "REQUIRED") {
|
|
1010
1028
|
setEmailValid(false);
|
|
1011
1029
|
} else {
|
|
1012
1030
|
if (emailInput === "") {
|
|
@@ -1385,7 +1403,9 @@ var AgentPanel = ({
|
|
|
1385
1403
|
//ragRankLimit = 5,
|
|
1386
1404
|
initialHistory = {},
|
|
1387
1405
|
hideRagContextInPrompt = true,
|
|
1388
|
-
createConversationOnFirstChat = true
|
|
1406
|
+
createConversationOnFirstChat = true,
|
|
1407
|
+
customerEmailCaptureMode = "HIDE",
|
|
1408
|
+
customerEmailCapturePlaceholder = "Please enter your email..."
|
|
1389
1409
|
}) => {
|
|
1390
1410
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
1391
1411
|
const [followOnPrompt, setFollowOnPrompt] = (0, import_react3.useState)("");
|
|
@@ -1475,7 +1495,9 @@ var AgentPanel = ({
|
|
|
1475
1495
|
conversation,
|
|
1476
1496
|
initialHistory,
|
|
1477
1497
|
hideRagContextInPrompt,
|
|
1478
|
-
createConversationOnFirstChat
|
|
1498
|
+
createConversationOnFirstChat,
|
|
1499
|
+
customerEmailCaptureMode,
|
|
1500
|
+
customerEmailCapturePlaceholder
|
|
1479
1501
|
}
|
|
1480
1502
|
));
|
|
1481
1503
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -134,7 +134,7 @@ var ChatPanel = ({
|
|
|
134
134
|
initialHistory = {},
|
|
135
135
|
hideRagContextInPrompt = true,
|
|
136
136
|
createConversationOnFirstChat = true,
|
|
137
|
-
customerEmailCaptureMode = "
|
|
137
|
+
customerEmailCaptureMode = "HIDE",
|
|
138
138
|
customerEmailCapturePlaceholder = "Please enter your email..."
|
|
139
139
|
}) => {
|
|
140
140
|
var _a;
|
|
@@ -164,7 +164,7 @@ var ChatPanel = ({
|
|
|
164
164
|
);
|
|
165
165
|
const [emailValid, setEmailValid] = useState2(true);
|
|
166
166
|
const [showEmailPanel, setShowEmailPanel] = useState2(
|
|
167
|
-
customerEmailCaptureMode !== "
|
|
167
|
+
customerEmailCaptureMode !== "HIDE"
|
|
168
168
|
);
|
|
169
169
|
const [callToActionSent, setCallToActionSent] = useState2(false);
|
|
170
170
|
const [CTAClickedButNoEmail, setCTAClickedButNoEmail] = useState2(false);
|
|
@@ -188,8 +188,8 @@ var ChatPanel = ({
|
|
|
188
188
|
publicAPIUrl = "https://8ftw8droff.execute-api.us-east-1.amazonaws.com/dev";
|
|
189
189
|
}
|
|
190
190
|
useEffect(() => {
|
|
191
|
-
setShowEmailPanel(customerEmailCaptureMode !== "
|
|
192
|
-
if (customerEmailCaptureMode === "
|
|
191
|
+
setShowEmailPanel(customerEmailCaptureMode !== "HIDE");
|
|
192
|
+
if (customerEmailCaptureMode === "REQUIRED") {
|
|
193
193
|
if (!isEmailAddress(emailInput)) {
|
|
194
194
|
setEmailValid(false);
|
|
195
195
|
}
|
|
@@ -394,6 +394,42 @@ var ChatPanel = ({
|
|
|
394
394
|
}
|
|
395
395
|
return void 0;
|
|
396
396
|
};
|
|
397
|
+
const ensureConversation = () => {
|
|
398
|
+
var _a2, _b;
|
|
399
|
+
if ((!currentConversation || currentConversation === "") && createConversationOnFirstChat) {
|
|
400
|
+
return fetch(`${publicAPIUrl}/conversations`, {
|
|
401
|
+
method: "POST",
|
|
402
|
+
headers: {
|
|
403
|
+
"Content-Type": "application/json"
|
|
404
|
+
},
|
|
405
|
+
body: JSON.stringify({
|
|
406
|
+
project_id: project_id != null ? project_id : "",
|
|
407
|
+
agentId: agent,
|
|
408
|
+
customerId: (_a2 = currentCustomer == null ? void 0 : currentCustomer.customer_id) != null ? _a2 : null,
|
|
409
|
+
customerEmail: (_b = currentCustomer == null ? void 0 : currentCustomer.customer_user_email) != null ? _b : null
|
|
410
|
+
})
|
|
411
|
+
}).then((res) => __async(void 0, null, function* () {
|
|
412
|
+
if (!res.ok) {
|
|
413
|
+
const errorText = yield res.text();
|
|
414
|
+
throw new Error(
|
|
415
|
+
`HTTP error! status: ${res.status}, message: ${errorText}`
|
|
416
|
+
);
|
|
417
|
+
}
|
|
418
|
+
return res.json();
|
|
419
|
+
})).then((newConvo) => {
|
|
420
|
+
if (newConvo == null ? void 0 : newConvo.id) {
|
|
421
|
+
console.log("new conversation created", newConvo.id);
|
|
422
|
+
setCurrentConversation(newConvo.id);
|
|
423
|
+
return newConvo.id;
|
|
424
|
+
}
|
|
425
|
+
return "";
|
|
426
|
+
}).catch((error) => {
|
|
427
|
+
console.error("Error creating new conversation", error);
|
|
428
|
+
return "";
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
return Promise.resolve(currentConversation);
|
|
432
|
+
};
|
|
397
433
|
useEffect(() => {
|
|
398
434
|
var _a2, _b, _c;
|
|
399
435
|
console.log("currentCustomer effect", currentCustomer);
|
|
@@ -429,45 +465,27 @@ var ChatPanel = ({
|
|
|
429
465
|
}
|
|
430
466
|
}
|
|
431
467
|
if (needsUpdate) {
|
|
468
|
+
ensureConversation().then((convId) => {
|
|
469
|
+
console.log(
|
|
470
|
+
"updating conversation with customer id and email",
|
|
471
|
+
convId,
|
|
472
|
+
currentCustomer
|
|
473
|
+
);
|
|
474
|
+
const r = fetch(`${publicAPIUrl}/conversations/${convId}`, {
|
|
475
|
+
method: "POST",
|
|
476
|
+
headers: {
|
|
477
|
+
"Content-Type": "application/json"
|
|
478
|
+
},
|
|
479
|
+
body: JSON.stringify({
|
|
480
|
+
project_id: project_id != null ? project_id : "",
|
|
481
|
+
customerId: currentCustomer.customer_id,
|
|
482
|
+
customerEmail: currentCustomer.customer_user_email
|
|
483
|
+
})
|
|
484
|
+
});
|
|
485
|
+
});
|
|
432
486
|
setCurrentCustomer(updatedValues);
|
|
433
487
|
}
|
|
434
488
|
}, [currentCustomer]);
|
|
435
|
-
const ensureConversation = () => {
|
|
436
|
-
var _a2, _b;
|
|
437
|
-
if ((!currentConversation || currentConversation === "") && createConversationOnFirstChat) {
|
|
438
|
-
return fetch(`${publicAPIUrl}/conversations`, {
|
|
439
|
-
method: "POST",
|
|
440
|
-
headers: {
|
|
441
|
-
"Content-Type": "application/json"
|
|
442
|
-
},
|
|
443
|
-
body: JSON.stringify({
|
|
444
|
-
project_id: project_id != null ? project_id : "",
|
|
445
|
-
agentId: agent,
|
|
446
|
-
customerId: (_a2 = currentCustomer == null ? void 0 : currentCustomer.customer_id) != null ? _a2 : null,
|
|
447
|
-
customerEmail: (_b = currentCustomer == null ? void 0 : currentCustomer.customer_user_email) != null ? _b : null
|
|
448
|
-
})
|
|
449
|
-
}).then((res) => __async(void 0, null, function* () {
|
|
450
|
-
if (!res.ok) {
|
|
451
|
-
const errorText = yield res.text();
|
|
452
|
-
throw new Error(
|
|
453
|
-
`HTTP error! status: ${res.status}, message: ${errorText}`
|
|
454
|
-
);
|
|
455
|
-
}
|
|
456
|
-
return res.json();
|
|
457
|
-
})).then((newConvo) => {
|
|
458
|
-
if (newConvo == null ? void 0 : newConvo.id) {
|
|
459
|
-
console.log("new conversation created", newConvo.id);
|
|
460
|
-
setCurrentConversation(newConvo.id);
|
|
461
|
-
return newConvo.id;
|
|
462
|
-
}
|
|
463
|
-
return "";
|
|
464
|
-
}).catch((error) => {
|
|
465
|
-
console.error("Error creating new conversation", error);
|
|
466
|
-
return "";
|
|
467
|
-
});
|
|
468
|
-
}
|
|
469
|
-
return Promise.resolve(currentConversation);
|
|
470
|
-
};
|
|
471
489
|
const continueChat = (suggestion) => {
|
|
472
490
|
console.log("continueChat", suggestion);
|
|
473
491
|
ensureConversation().then((convId) => {
|
|
@@ -823,7 +841,7 @@ var ChatPanel = ({
|
|
|
823
841
|
const isDisabledDueToNoEmail = () => {
|
|
824
842
|
const valid = isEmailAddress(emailInput);
|
|
825
843
|
if (valid) return false;
|
|
826
|
-
if (customerEmailCaptureMode === "
|
|
844
|
+
if (customerEmailCaptureMode === "REQUIRED") return true;
|
|
827
845
|
};
|
|
828
846
|
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(
|
|
829
847
|
"div",
|
|
@@ -972,7 +990,7 @@ var ChatPanel = ({
|
|
|
972
990
|
setEmailClickedButNoEmail(false);
|
|
973
991
|
}
|
|
974
992
|
} else {
|
|
975
|
-
if (customerEmailCaptureMode === "
|
|
993
|
+
if (customerEmailCaptureMode === "REQUIRED") {
|
|
976
994
|
setEmailValid(false);
|
|
977
995
|
} else {
|
|
978
996
|
if (emailInput === "") {
|
|
@@ -1351,7 +1369,9 @@ var AgentPanel = ({
|
|
|
1351
1369
|
//ragRankLimit = 5,
|
|
1352
1370
|
initialHistory = {},
|
|
1353
1371
|
hideRagContextInPrompt = true,
|
|
1354
|
-
createConversationOnFirstChat = true
|
|
1372
|
+
createConversationOnFirstChat = true,
|
|
1373
|
+
customerEmailCaptureMode = "HIDE",
|
|
1374
|
+
customerEmailCapturePlaceholder = "Please enter your email..."
|
|
1355
1375
|
}) => {
|
|
1356
1376
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
1357
1377
|
const [followOnPrompt, setFollowOnPrompt] = useState3("");
|
|
@@ -1441,7 +1461,9 @@ var AgentPanel = ({
|
|
|
1441
1461
|
conversation,
|
|
1442
1462
|
initialHistory,
|
|
1443
1463
|
hideRagContextInPrompt,
|
|
1444
|
-
createConversationOnFirstChat
|
|
1464
|
+
createConversationOnFirstChat,
|
|
1465
|
+
customerEmailCaptureMode,
|
|
1466
|
+
customerEmailCapturePlaceholder
|
|
1445
1467
|
}
|
|
1446
1468
|
));
|
|
1447
1469
|
};
|
package/package.json
CHANGED
package/src/AgentPanel.tsx
CHANGED
|
@@ -59,6 +59,8 @@ export interface AgentPanelProps {
|
|
|
59
59
|
initialHistory?: { [key: string]: { content: string; callId: string } };
|
|
60
60
|
hideRagContextInPrompt?: boolean;
|
|
61
61
|
createConversationOnFirstChat?: boolean;
|
|
62
|
+
customerEmailCaptureMode?: "HIDE" | "OPTIONAL" | "REQUIRED";
|
|
63
|
+
customerEmailCapturePlaceholder?: string;
|
|
62
64
|
}
|
|
63
65
|
interface ExtraProps extends React.HTMLAttributes<HTMLElement> {
|
|
64
66
|
inline?: boolean;
|
|
@@ -105,6 +107,8 @@ const AgentPanel: React.FC<AgentPanelProps & ExtraProps> = ({
|
|
|
105
107
|
initialHistory = {},
|
|
106
108
|
hideRagContextInPrompt = true,
|
|
107
109
|
createConversationOnFirstChat = true,
|
|
110
|
+
customerEmailCaptureMode = "HIDE",
|
|
111
|
+
customerEmailCapturePlaceholder = "Please enter your email...",
|
|
108
112
|
}) => {
|
|
109
113
|
const [followOnPrompt, setFollowOnPrompt] = useState<string>("");
|
|
110
114
|
|
|
@@ -241,6 +245,8 @@ const AgentPanel: React.FC<AgentPanelProps & ExtraProps> = ({
|
|
|
241
245
|
initialHistory={initialHistory}
|
|
242
246
|
hideRagContextInPrompt={hideRagContextInPrompt}
|
|
243
247
|
createConversationOnFirstChat={createConversationOnFirstChat}
|
|
248
|
+
customerEmailCaptureMode={customerEmailCaptureMode}
|
|
249
|
+
customerEmailCapturePlaceholder={customerEmailCapturePlaceholder}
|
|
244
250
|
/>
|
|
245
251
|
)}
|
|
246
252
|
</>
|
package/src/ChatPanel.tsx
CHANGED
|
@@ -66,7 +66,7 @@ export interface ChatPanelProps {
|
|
|
66
66
|
};
|
|
67
67
|
hideRagContextInPrompt?: boolean;
|
|
68
68
|
createConversationOnFirstChat?: boolean;
|
|
69
|
-
customerEmailCaptureMode?: "
|
|
69
|
+
customerEmailCaptureMode?: "HIDE" | "OPTIONAL" | "REQUIRED";
|
|
70
70
|
customerEmailCapturePlaceholder?: string;
|
|
71
71
|
}
|
|
72
72
|
|
|
@@ -114,7 +114,7 @@ const ChatPanel: React.FC<ChatPanelProps & ExtraProps> = ({
|
|
|
114
114
|
initialHistory = {},
|
|
115
115
|
hideRagContextInPrompt = true,
|
|
116
116
|
createConversationOnFirstChat = true,
|
|
117
|
-
customerEmailCaptureMode = "
|
|
117
|
+
customerEmailCaptureMode = "HIDE",
|
|
118
118
|
customerEmailCapturePlaceholder = "Please enter your email...",
|
|
119
119
|
}) => {
|
|
120
120
|
const isEmailAddress = (email: string): boolean => {
|
|
@@ -147,7 +147,7 @@ const ChatPanel: React.FC<ChatPanelProps & ExtraProps> = ({
|
|
|
147
147
|
);
|
|
148
148
|
const [emailValid, setEmailValid] = useState(true);
|
|
149
149
|
const [showEmailPanel, setShowEmailPanel] = useState(
|
|
150
|
-
customerEmailCaptureMode !== "
|
|
150
|
+
customerEmailCaptureMode !== "HIDE"
|
|
151
151
|
);
|
|
152
152
|
const [callToActionSent, setCallToActionSent] = useState(false);
|
|
153
153
|
const [CTAClickedButNoEmail, setCTAClickedButNoEmail] = useState(false);
|
|
@@ -184,9 +184,9 @@ const ChatPanel: React.FC<ChatPanelProps & ExtraProps> = ({
|
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
useEffect(() => {
|
|
187
|
-
setShowEmailPanel(customerEmailCaptureMode !== "
|
|
187
|
+
setShowEmailPanel(customerEmailCaptureMode !== "HIDE");
|
|
188
188
|
|
|
189
|
-
if (customerEmailCaptureMode === "
|
|
189
|
+
if (customerEmailCaptureMode === "REQUIRED") {
|
|
190
190
|
if (!isEmailAddress(emailInput)) {
|
|
191
191
|
setEmailValid(false);
|
|
192
192
|
}
|
|
@@ -418,6 +418,49 @@ const ChatPanel: React.FC<ChatPanelProps & ExtraProps> = ({
|
|
|
418
418
|
return undefined;
|
|
419
419
|
};
|
|
420
420
|
|
|
421
|
+
const ensureConversation = () => {
|
|
422
|
+
if (
|
|
423
|
+
(!currentConversation || currentConversation === "") &&
|
|
424
|
+
createConversationOnFirstChat
|
|
425
|
+
) {
|
|
426
|
+
return fetch(`${publicAPIUrl}/conversations`, {
|
|
427
|
+
method: "POST",
|
|
428
|
+
headers: {
|
|
429
|
+
"Content-Type": "application/json",
|
|
430
|
+
},
|
|
431
|
+
body: JSON.stringify({
|
|
432
|
+
project_id: project_id ?? "",
|
|
433
|
+
agentId: agent,
|
|
434
|
+
customerId: currentCustomer?.customer_id ?? null,
|
|
435
|
+
customerEmail: currentCustomer?.customer_user_email ?? null,
|
|
436
|
+
}),
|
|
437
|
+
})
|
|
438
|
+
.then(async (res) => {
|
|
439
|
+
if (!res.ok) {
|
|
440
|
+
const errorText = await res.text();
|
|
441
|
+
throw new Error(
|
|
442
|
+
`HTTP error! status: ${res.status}, message: ${errorText}`
|
|
443
|
+
);
|
|
444
|
+
}
|
|
445
|
+
return res.json();
|
|
446
|
+
})
|
|
447
|
+
.then((newConvo) => {
|
|
448
|
+
if (newConvo?.id) {
|
|
449
|
+
console.log("new conversation created", newConvo.id);
|
|
450
|
+
setCurrentConversation(newConvo.id);
|
|
451
|
+
return newConvo.id;
|
|
452
|
+
}
|
|
453
|
+
return "";
|
|
454
|
+
})
|
|
455
|
+
.catch((error) => {
|
|
456
|
+
console.error("Error creating new conversation", error);
|
|
457
|
+
return "";
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
// If a currentConversation exists, return it in a resolved Promise.
|
|
461
|
+
return Promise.resolve(currentConversation);
|
|
462
|
+
};
|
|
463
|
+
|
|
421
464
|
useEffect(() => {
|
|
422
465
|
console.log("currentCustomer effect", currentCustomer);
|
|
423
466
|
|
|
@@ -464,53 +507,31 @@ const ChatPanel: React.FC<ChatPanelProps & ExtraProps> = ({
|
|
|
464
507
|
}
|
|
465
508
|
}
|
|
466
509
|
|
|
467
|
-
// Only update currentCustomer if we found values in cookies
|
|
468
510
|
if (needsUpdate) {
|
|
511
|
+
// update the customer id and email in the conversation
|
|
512
|
+
ensureConversation().then((convId) => {
|
|
513
|
+
console.log(
|
|
514
|
+
"updating conversation with customer id and email",
|
|
515
|
+
convId,
|
|
516
|
+
currentCustomer
|
|
517
|
+
);
|
|
518
|
+
|
|
519
|
+
const r = fetch(`${publicAPIUrl}/conversations/${convId}`, {
|
|
520
|
+
method: "POST",
|
|
521
|
+
headers: {
|
|
522
|
+
"Content-Type": "application/json",
|
|
523
|
+
},
|
|
524
|
+
body: JSON.stringify({
|
|
525
|
+
project_id: project_id ?? "",
|
|
526
|
+
customerId: currentCustomer.customer_id,
|
|
527
|
+
customerEmail: currentCustomer.customer_user_email,
|
|
528
|
+
}),
|
|
529
|
+
});
|
|
530
|
+
});
|
|
531
|
+
|
|
469
532
|
setCurrentCustomer(updatedValues);
|
|
470
533
|
}
|
|
471
534
|
}, [currentCustomer]);
|
|
472
|
-
const ensureConversation = () => {
|
|
473
|
-
if (
|
|
474
|
-
(!currentConversation || currentConversation === "") &&
|
|
475
|
-
createConversationOnFirstChat
|
|
476
|
-
) {
|
|
477
|
-
return fetch(`${publicAPIUrl}/conversations`, {
|
|
478
|
-
method: "POST",
|
|
479
|
-
headers: {
|
|
480
|
-
"Content-Type": "application/json",
|
|
481
|
-
},
|
|
482
|
-
body: JSON.stringify({
|
|
483
|
-
project_id: project_id ?? "",
|
|
484
|
-
agentId: agent,
|
|
485
|
-
customerId: currentCustomer?.customer_id ?? null,
|
|
486
|
-
customerEmail: currentCustomer?.customer_user_email ?? null,
|
|
487
|
-
}),
|
|
488
|
-
})
|
|
489
|
-
.then(async (res) => {
|
|
490
|
-
if (!res.ok) {
|
|
491
|
-
const errorText = await res.text();
|
|
492
|
-
throw new Error(
|
|
493
|
-
`HTTP error! status: ${res.status}, message: ${errorText}`
|
|
494
|
-
);
|
|
495
|
-
}
|
|
496
|
-
return res.json();
|
|
497
|
-
})
|
|
498
|
-
.then((newConvo) => {
|
|
499
|
-
if (newConvo?.id) {
|
|
500
|
-
console.log("new conversation created", newConvo.id);
|
|
501
|
-
setCurrentConversation(newConvo.id);
|
|
502
|
-
return newConvo.id;
|
|
503
|
-
}
|
|
504
|
-
return "";
|
|
505
|
-
})
|
|
506
|
-
.catch((error) => {
|
|
507
|
-
console.error("Error creating new conversation", error);
|
|
508
|
-
return "";
|
|
509
|
-
});
|
|
510
|
-
}
|
|
511
|
-
// If a currentConversation exists, return it in a resolved Promise.
|
|
512
|
-
return Promise.resolve(currentConversation);
|
|
513
|
-
};
|
|
514
535
|
|
|
515
536
|
const continueChat = (suggestion?: string) => {
|
|
516
537
|
console.log("continueChat", suggestion);
|
|
@@ -954,7 +975,7 @@ const ChatPanel: React.FC<ChatPanelProps & ExtraProps> = ({
|
|
|
954
975
|
const isDisabledDueToNoEmail = () => {
|
|
955
976
|
const valid = isEmailAddress(emailInput);
|
|
956
977
|
if (valid) return false;
|
|
957
|
-
if (customerEmailCaptureMode === "
|
|
978
|
+
if (customerEmailCaptureMode === "REQUIRED") return true;
|
|
958
979
|
};
|
|
959
980
|
|
|
960
981
|
return (
|
|
@@ -1159,7 +1180,7 @@ const ChatPanel: React.FC<ChatPanelProps & ExtraProps> = ({
|
|
|
1159
1180
|
setEmailClickedButNoEmail(false);
|
|
1160
1181
|
}
|
|
1161
1182
|
} else {
|
|
1162
|
-
if (customerEmailCaptureMode === "
|
|
1183
|
+
if (customerEmailCaptureMode === "REQUIRED") {
|
|
1163
1184
|
setEmailValid(false);
|
|
1164
1185
|
} else {
|
|
1165
1186
|
if (emailInput === "") {
|