bibot 1.0.23 → 1.0.24
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/hooks/useBiBotChatBot.d.ts +3 -2
- package/dist/index.js +112 -40
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +112 -40
- package/dist/index.modern.js.map +1 -1
- package/dist/services/plugin-api.d.ts +5 -1
- package/package.json +1 -1
@@ -1,4 +1,5 @@
|
|
1
1
|
import React from 'react';
|
2
|
+
import { predefinedQuestionsType } from '../services/plugin-api';
|
2
3
|
interface UseBiBotChatBotProps {
|
3
4
|
clientId: string;
|
4
5
|
}
|
@@ -23,7 +24,7 @@ declare const useBiBotChatBot: ({ clientId }: UseBiBotChatBotProps) => {
|
|
23
24
|
sendInputInquiry: () => Promise<void>;
|
24
25
|
chatBubbleConfig: ChatBubbleConfigProps | undefined;
|
25
26
|
showPredefinedQuestions: boolean;
|
26
|
-
predefinedQuestions:
|
27
|
-
handlePredefinedQuestionSelect: (question:
|
27
|
+
predefinedQuestions: predefinedQuestionsType[];
|
28
|
+
handlePredefinedQuestionSelect: (question: predefinedQuestionsType) => void;
|
28
29
|
};
|
29
30
|
export { useBiBotChatBot };
|
package/dist/index.js
CHANGED
@@ -3488,16 +3488,33 @@ var AppProvider = function AppProvider(_ref) {
|
|
3488
3488
|
};
|
3489
3489
|
|
3490
3490
|
var getRemoteClientChatPredefinedQuestions = function getRemoteClientChatPredefinedQuestions(params) {
|
3491
|
-
|
3492
|
-
|
3493
|
-
|
3494
|
-
|
3495
|
-
|
3496
|
-
|
3497
|
-
|
3498
|
-
|
3499
|
-
|
3500
|
-
|
3491
|
+
try {
|
3492
|
+
return Promise.resolve(_catch(function () {
|
3493
|
+
var path = "" + domain.inference + resources.predefinedQ;
|
3494
|
+
return Promise.resolve(pluginAxiosInstance.get(path, {
|
3495
|
+
params: params
|
3496
|
+
})).then(function (response) {
|
3497
|
+
console.log(response.data.predefined_questions);
|
3498
|
+
return response.data.predefined_questions;
|
3499
|
+
});
|
3500
|
+
}, function () {
|
3501
|
+
return [{
|
3502
|
+
question: 'These are placeholders',
|
3503
|
+
answer: ''
|
3504
|
+
}, {
|
3505
|
+
question: 'They will be removed in production',
|
3506
|
+
answer: ''
|
3507
|
+
}, {
|
3508
|
+
question: 'This will be empty if there are no predefined questions',
|
3509
|
+
answer: ''
|
3510
|
+
}, {
|
3511
|
+
question: 'So hide if there are no predefined questions',
|
3512
|
+
answer: ''
|
3513
|
+
}];
|
3514
|
+
}));
|
3515
|
+
} catch (e) {
|
3516
|
+
return Promise.reject(e);
|
3517
|
+
}
|
3501
3518
|
};
|
3502
3519
|
var getRemoteClientChatBubbleConfig = function getRemoteClientChatBubbleConfig(params) {
|
3503
3520
|
try {
|
@@ -3591,20 +3608,21 @@ var useBiBotChatBot = function useBiBotChatBot(_ref) {
|
|
3591
3608
|
var sendInputInquiry = function sendInputInquiry() {
|
3592
3609
|
try {
|
3593
3610
|
setIsLoading(true);
|
3611
|
+
var input = userInput.trim();
|
3594
3612
|
setUserInput('');
|
3595
3613
|
return Promise.resolve(_finallyRethrows(function () {
|
3596
3614
|
return _catch(function () {
|
3597
3615
|
var _temp2 = function () {
|
3598
|
-
if (
|
3616
|
+
if (input) {
|
3599
3617
|
setMessages(function (messages) {
|
3600
3618
|
return [].concat(messages, [{
|
3601
3619
|
sender: 'user',
|
3602
|
-
text:
|
3620
|
+
text: input
|
3603
3621
|
}]);
|
3604
3622
|
});
|
3605
3623
|
return Promise.resolve(askBiBot({
|
3606
3624
|
client_id: clientId,
|
3607
|
-
q:
|
3625
|
+
q: input,
|
3608
3626
|
session_id: state.sessionId,
|
3609
3627
|
chat_id: v4()
|
3610
3628
|
})).then(function (response) {
|
@@ -3620,7 +3638,7 @@ var useBiBotChatBot = function useBiBotChatBot(_ref) {
|
|
3620
3638
|
if (_temp2 && _temp2.then) return _temp2.then(function () {});
|
3621
3639
|
}, function (error) {
|
3622
3640
|
var _error$message;
|
3623
|
-
|
3641
|
+
console.error((_error$message = error === null || error === void 0 ? void 0 : error.message) != null ? _error$message : 'Failed to get response from server');
|
3624
3642
|
});
|
3625
3643
|
}, function (_wasThrown, _result) {
|
3626
3644
|
setIsLoading(false);
|
@@ -3631,6 +3649,33 @@ var useBiBotChatBot = function useBiBotChatBot(_ref) {
|
|
3631
3649
|
return Promise.reject(e);
|
3632
3650
|
}
|
3633
3651
|
};
|
3652
|
+
var askPredefinedQuestion = function askPredefinedQuestion(question) {
|
3653
|
+
try {
|
3654
|
+
setIsLoading(true);
|
3655
|
+
var input = question.question.trim();
|
3656
|
+
setUserInput('');
|
3657
|
+
if (input === question.question) {
|
3658
|
+
setMessages(function (messages) {
|
3659
|
+
return [].concat(messages, [{
|
3660
|
+
sender: 'user',
|
3661
|
+
text: input
|
3662
|
+
}]);
|
3663
|
+
});
|
3664
|
+
setTimeout(function () {
|
3665
|
+
setMessages(function (messages) {
|
3666
|
+
return [].concat(messages, [{
|
3667
|
+
sender: 'bot',
|
3668
|
+
text: question.answer
|
3669
|
+
}]);
|
3670
|
+
});
|
3671
|
+
setIsLoading(false);
|
3672
|
+
}, 1000);
|
3673
|
+
}
|
3674
|
+
return Promise.resolve();
|
3675
|
+
} catch (e) {
|
3676
|
+
return Promise.reject(e);
|
3677
|
+
}
|
3678
|
+
};
|
3634
3679
|
var clientId = _ref.clientId;
|
3635
3680
|
var _useState = React.useState([]),
|
3636
3681
|
predefinedQuestions = _useState[0],
|
@@ -3657,9 +3702,10 @@ var useBiBotChatBot = function useBiBotChatBot(_ref) {
|
|
3657
3702
|
chatBubbleConfig = _useState7[0],
|
3658
3703
|
setChatBubbleConfig = _useState7[1];
|
3659
3704
|
var handlePredefinedQuestionSelect = function handlePredefinedQuestionSelect(question) {
|
3660
|
-
setUserInput(question);
|
3661
3705
|
sendInputInquiry();
|
3662
|
-
|
3706
|
+
askPredefinedQuestion(question);
|
3707
|
+
setUserInput('');
|
3708
|
+
setShowPredefinedQuestions(true);
|
3663
3709
|
};
|
3664
3710
|
var getChatBubbleConfig = React.useCallback(function () {
|
3665
3711
|
try {
|
@@ -3895,38 +3941,61 @@ var useOnlineStatus = function useOnlineStatus() {
|
|
3895
3941
|
|
3896
3942
|
var PredefinedQuestions = function PredefinedQuestions(_ref) {
|
3897
3943
|
var questions = _ref.questions,
|
3898
|
-
onSelect = _ref.onSelect
|
3944
|
+
onSelect = _ref.onSelect,
|
3945
|
+
clientId = _ref.clientId;
|
3946
|
+
var _useBiBotChatBot = useBiBotChatBot({
|
3947
|
+
clientId: clientId
|
3948
|
+
}),
|
3949
|
+
chatBubbleConfig = _useBiBotChatBot.chatBubbleConfig;
|
3899
3950
|
return React.createElement("div", {
|
3900
|
-
className: styles['predefined-questions']
|
3951
|
+
className: styles['predefined-questions'],
|
3952
|
+
style: {
|
3953
|
+
height: '50%',
|
3954
|
+
color: '#000'
|
3955
|
+
}
|
3901
3956
|
}, questions.map(function (question, index) {
|
3957
|
+
var _chatBubbleConfig$col;
|
3902
3958
|
return React.createElement("div", {
|
3903
3959
|
key: index,
|
3904
3960
|
className: styles['predefined-questions'],
|
3961
|
+
style: {
|
3962
|
+
backgroundColor: '#fff',
|
3963
|
+
border: "0.5px solid " + (chatBubbleConfig ? (_chatBubbleConfig$col = chatBubbleConfig === null || chatBubbleConfig === void 0 ? void 0 : chatBubbleConfig.color) != null ? _chatBubbleConfig$col : '#dedede' : '#000'),
|
3964
|
+
fontSize: 16,
|
3965
|
+
margin: 5,
|
3966
|
+
textAlign: 'start',
|
3967
|
+
height: 20,
|
3968
|
+
padding: 10,
|
3969
|
+
display: 'flex',
|
3970
|
+
alignItems: 'center',
|
3971
|
+
borderRadius: 6,
|
3972
|
+
cursor: 'pointer'
|
3973
|
+
},
|
3905
3974
|
onClick: function onClick() {
|
3906
|
-
|
3975
|
+
onSelect(question);
|
3907
3976
|
}
|
3908
|
-
}, question);
|
3977
|
+
}, question.question);
|
3909
3978
|
}));
|
3910
3979
|
};
|
3911
3980
|
var ChatBubbleBiBot = function ChatBubbleBiBot(_ref2) {
|
3912
|
-
var _chatBubbleConfig$
|
3981
|
+
var _chatBubbleConfig$col2, _chatBubbleConfig$col3;
|
3913
3982
|
var clientId = _ref2.clientId;
|
3914
|
-
var
|
3983
|
+
var _useBiBotChatBot2 = useBiBotChatBot({
|
3915
3984
|
clientId: clientId
|
3916
3985
|
}),
|
3917
|
-
chatIsOpen =
|
3918
|
-
messages =
|
3919
|
-
isLoading =
|
3920
|
-
messageEndRef =
|
3921
|
-
userInput =
|
3922
|
-
handleUserInput =
|
3923
|
-
handleKeyPress =
|
3924
|
-
sendInputInquiry =
|
3925
|
-
toggleChat =
|
3926
|
-
chatBubbleConfig =
|
3927
|
-
showPredefinedQuestions =
|
3928
|
-
predefinedQuestions =
|
3929
|
-
handlePredefinedQuestionSelect =
|
3986
|
+
chatIsOpen = _useBiBotChatBot2.chatIsOpen,
|
3987
|
+
messages = _useBiBotChatBot2.messages,
|
3988
|
+
isLoading = _useBiBotChatBot2.isLoading,
|
3989
|
+
messageEndRef = _useBiBotChatBot2.messageEndRef,
|
3990
|
+
userInput = _useBiBotChatBot2.userInput,
|
3991
|
+
handleUserInput = _useBiBotChatBot2.handleUserInput,
|
3992
|
+
handleKeyPress = _useBiBotChatBot2.handleKeyPress,
|
3993
|
+
sendInputInquiry = _useBiBotChatBot2.sendInputInquiry,
|
3994
|
+
toggleChat = _useBiBotChatBot2.toggleChat,
|
3995
|
+
chatBubbleConfig = _useBiBotChatBot2.chatBubbleConfig,
|
3996
|
+
showPredefinedQuestions = _useBiBotChatBot2.showPredefinedQuestions,
|
3997
|
+
predefinedQuestions = _useBiBotChatBot2.predefinedQuestions,
|
3998
|
+
handlePredefinedQuestionSelect = _useBiBotChatBot2.handlePredefinedQuestionSelect;
|
3930
3999
|
var isOnline = useOnlineStatus();
|
3931
4000
|
return React.createElement("div", {
|
3932
4001
|
className: "chat-bubble " + (chatIsOpen ? 'open' : ''),
|
@@ -3953,7 +4022,7 @@ var ChatBubbleBiBot = function ChatBubbleBiBot(_ref2) {
|
|
3953
4022
|
}, React.createElement("div", {
|
3954
4023
|
className: styles['chat-header'],
|
3955
4024
|
style: {
|
3956
|
-
backgroundColor: (_chatBubbleConfig$
|
4025
|
+
backgroundColor: (_chatBubbleConfig$col2 = chatBubbleConfig === null || chatBubbleConfig === void 0 ? void 0 : chatBubbleConfig.color) != null ? _chatBubbleConfig$col2 : '#dedede',
|
3957
4026
|
height: 50,
|
3958
4027
|
borderTopLeftRadius: 8,
|
3959
4028
|
borderTopRightRadius: 8,
|
@@ -4050,8 +4119,9 @@ var ChatBubbleBiBot = function ChatBubbleBiBot(_ref2) {
|
|
4050
4119
|
}
|
4051
4120
|
}, message.text));
|
4052
4121
|
}), showPredefinedQuestions && predefinedQuestions && predefinedQuestions.length > 0 && React.createElement(PredefinedQuestions, {
|
4053
|
-
questions: predefinedQuestions,
|
4054
|
-
onSelect: handlePredefinedQuestionSelect
|
4122
|
+
questions: predefinedQuestions.slice(0, 5),
|
4123
|
+
onSelect: handlePredefinedQuestionSelect,
|
4124
|
+
clientId: clientId
|
4055
4125
|
}), isLoading && React.createElement("div", {
|
4056
4126
|
style: {
|
4057
4127
|
marginLeft: '20px'
|
@@ -4096,14 +4166,16 @@ var ChatBubbleBiBot = function ChatBubbleBiBot(_ref2) {
|
|
4096
4166
|
border: 'none',
|
4097
4167
|
cursor: 'pointer'
|
4098
4168
|
},
|
4099
|
-
onClick:
|
4169
|
+
onClick: function onClick() {
|
4170
|
+
return sendInputInquiry();
|
4171
|
+
}
|
4100
4172
|
}, React.createElement(SendMessageIcon, {
|
4101
4173
|
color: isLoading ? '#fff' : chatBubbleConfig === null || chatBubbleConfig === void 0 ? void 0 : chatBubbleConfig.color
|
4102
4174
|
})))), React.createElement("button", {
|
4103
4175
|
onClick: toggleChat,
|
4104
4176
|
className: styles['chat-toggle'],
|
4105
4177
|
style: {
|
4106
|
-
backgroundColor: (_chatBubbleConfig$
|
4178
|
+
backgroundColor: (_chatBubbleConfig$col3 = chatBubbleConfig === null || chatBubbleConfig === void 0 ? void 0 : chatBubbleConfig.color) != null ? _chatBubbleConfig$col3 : '#dedede',
|
4107
4179
|
color: '#fff',
|
4108
4180
|
borderRadius: '50%',
|
4109
4181
|
cursor: 'pointer',
|