bibot 1.0.22 → 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 +144 -87
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +144 -87
- 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 {
|
@@ -3520,64 +3537,49 @@ var getRemoteClientChatBubbleConfig = function getRemoteClientChatBubbleConfig(p
|
|
3520
3537
|
return Promise.reject(e);
|
3521
3538
|
}
|
3522
3539
|
};
|
3540
|
+
var handleRetries = function handleRetries(data, attempt) {
|
3541
|
+
try {
|
3542
|
+
var maxAttempts = 30;
|
3543
|
+
var delay = 10000;
|
3544
|
+
if (attempt >= maxAttempts) {
|
3545
|
+
return Promise.resolve("Sorry this is taking longer than usual. Please try again later");
|
3546
|
+
}
|
3547
|
+
return Promise.resolve(new Promise(function (resolve) {
|
3548
|
+
return setTimeout(resolve, delay);
|
3549
|
+
})).then(function () {
|
3550
|
+
return _catch(function () {
|
3551
|
+
return Promise.resolve(askTimedOutBiBot(_extends({}, data, {
|
3552
|
+
tries: attempt + 1
|
3553
|
+
}))).then(function (message) {
|
3554
|
+
if (message === defaultSlacker) {
|
3555
|
+
return Promise.resolve(handleRetries(data, attempt + 1));
|
3556
|
+
} else {
|
3557
|
+
return message;
|
3558
|
+
}
|
3559
|
+
});
|
3560
|
+
}, function (error) {
|
3561
|
+
return error.message;
|
3562
|
+
});
|
3563
|
+
});
|
3564
|
+
} catch (e) {
|
3565
|
+
return Promise.reject(e);
|
3566
|
+
}
|
3567
|
+
};
|
3523
3568
|
var askBiBot = function askBiBot(data) {
|
3524
3569
|
try {
|
3525
3570
|
return Promise.resolve(_catch(function () {
|
3526
3571
|
var path = "" + domain.inference + resources.q;
|
3527
3572
|
return Promise.resolve(pluginAxiosInstance.post(path, data)).then(function (response) {
|
3528
3573
|
if (response.data.message === defaultSlacker) {
|
3529
|
-
return
|
3530
|
-
return Promise.resolve(new Promise(function (resolve) {
|
3531
|
-
return setTimeout(resolve, 6000);
|
3532
|
-
})).then(function () {
|
3533
|
-
return Promise.resolve(askTimedOutBiBot(_extends({}, data, {
|
3534
|
-
tries: 2
|
3535
|
-
})));
|
3536
|
-
});
|
3537
|
-
}, function (error2) {
|
3538
|
-
if (error2.code === 'ECONNABORTED' || error2.message.includes('Endpoint request timed out')) {
|
3539
|
-
return _catch(function () {
|
3540
|
-
return Promise.resolve(new Promise(function (resolve) {
|
3541
|
-
return setTimeout(resolve, 6000);
|
3542
|
-
})).then(function () {
|
3543
|
-
return Promise.resolve(askTimedOutBiBot(_extends({}, data, {
|
3544
|
-
tries: 3
|
3545
|
-
})));
|
3546
|
-
});
|
3547
|
-
}, function (error3) {
|
3548
|
-
return error3.message;
|
3549
|
-
});
|
3550
|
-
} else {
|
3551
|
-
return error2.message;
|
3552
|
-
}
|
3553
|
-
});
|
3574
|
+
return Promise.resolve(handleRetries(data, 1));
|
3554
3575
|
} else {
|
3555
3576
|
return response.data.message;
|
3556
3577
|
}
|
3557
3578
|
});
|
3558
3579
|
}, function (error1) {
|
3580
|
+
console.log('This is the error1 from the endpoint on the 1st try:', error1);
|
3559
3581
|
console.log(error1.message);
|
3560
|
-
|
3561
|
-
return _catch(function () {
|
3562
|
-
return Promise.resolve(askTimedOutBiBot(_extends({}, data, {
|
3563
|
-
tries: 2
|
3564
|
-
})));
|
3565
|
-
}, function (error2) {
|
3566
|
-
if (error2.code === 'ECONNABORTED' || error2.message.includes('Endpoint request timed out')) {
|
3567
|
-
return _catch(function () {
|
3568
|
-
return Promise.resolve(askTimedOutBiBot(_extends({}, data, {
|
3569
|
-
tries: 3
|
3570
|
-
})));
|
3571
|
-
}, function (error3) {
|
3572
|
-
return error3.message;
|
3573
|
-
});
|
3574
|
-
} else {
|
3575
|
-
return error2.message;
|
3576
|
-
}
|
3577
|
-
});
|
3578
|
-
} else {
|
3579
|
-
return error1.message;
|
3580
|
-
}
|
3582
|
+
return error1.message;
|
3581
3583
|
}));
|
3582
3584
|
} catch (e) {
|
3583
3585
|
return Promise.reject(e);
|
@@ -3599,27 +3601,28 @@ var askTimedOutBiBot = function askTimedOutBiBot(data) {
|
|
3599
3601
|
return Promise.reject(e);
|
3600
3602
|
}
|
3601
3603
|
};
|
3602
|
-
var defaultSlacker = "
|
3604
|
+
var defaultSlacker = "BiBot_Retry_Later";
|
3603
3605
|
var pluginAxiosInstance = createPluginAxiosInstance();
|
3604
3606
|
|
3605
3607
|
var useBiBotChatBot = function useBiBotChatBot(_ref) {
|
3606
3608
|
var sendInputInquiry = function sendInputInquiry() {
|
3607
3609
|
try {
|
3608
3610
|
setIsLoading(true);
|
3611
|
+
var input = userInput.trim();
|
3609
3612
|
setUserInput('');
|
3610
3613
|
return Promise.resolve(_finallyRethrows(function () {
|
3611
3614
|
return _catch(function () {
|
3612
3615
|
var _temp2 = function () {
|
3613
|
-
if (
|
3616
|
+
if (input) {
|
3614
3617
|
setMessages(function (messages) {
|
3615
3618
|
return [].concat(messages, [{
|
3616
3619
|
sender: 'user',
|
3617
|
-
text:
|
3620
|
+
text: input
|
3618
3621
|
}]);
|
3619
3622
|
});
|
3620
3623
|
return Promise.resolve(askBiBot({
|
3621
3624
|
client_id: clientId,
|
3622
|
-
q:
|
3625
|
+
q: input,
|
3623
3626
|
session_id: state.sessionId,
|
3624
3627
|
chat_id: v4()
|
3625
3628
|
})).then(function (response) {
|
@@ -3635,7 +3638,7 @@ var useBiBotChatBot = function useBiBotChatBot(_ref) {
|
|
3635
3638
|
if (_temp2 && _temp2.then) return _temp2.then(function () {});
|
3636
3639
|
}, function (error) {
|
3637
3640
|
var _error$message;
|
3638
|
-
|
3641
|
+
console.error((_error$message = error === null || error === void 0 ? void 0 : error.message) != null ? _error$message : 'Failed to get response from server');
|
3639
3642
|
});
|
3640
3643
|
}, function (_wasThrown, _result) {
|
3641
3644
|
setIsLoading(false);
|
@@ -3646,6 +3649,33 @@ var useBiBotChatBot = function useBiBotChatBot(_ref) {
|
|
3646
3649
|
return Promise.reject(e);
|
3647
3650
|
}
|
3648
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
|
+
};
|
3649
3679
|
var clientId = _ref.clientId;
|
3650
3680
|
var _useState = React.useState([]),
|
3651
3681
|
predefinedQuestions = _useState[0],
|
@@ -3672,9 +3702,10 @@ var useBiBotChatBot = function useBiBotChatBot(_ref) {
|
|
3672
3702
|
chatBubbleConfig = _useState7[0],
|
3673
3703
|
setChatBubbleConfig = _useState7[1];
|
3674
3704
|
var handlePredefinedQuestionSelect = function handlePredefinedQuestionSelect(question) {
|
3675
|
-
setUserInput(question);
|
3676
3705
|
sendInputInquiry();
|
3677
|
-
|
3706
|
+
askPredefinedQuestion(question);
|
3707
|
+
setUserInput('');
|
3708
|
+
setShowPredefinedQuestions(true);
|
3678
3709
|
};
|
3679
3710
|
var getChatBubbleConfig = React.useCallback(function () {
|
3680
3711
|
try {
|
@@ -3910,38 +3941,61 @@ var useOnlineStatus = function useOnlineStatus() {
|
|
3910
3941
|
|
3911
3942
|
var PredefinedQuestions = function PredefinedQuestions(_ref) {
|
3912
3943
|
var questions = _ref.questions,
|
3913
|
-
onSelect = _ref.onSelect
|
3944
|
+
onSelect = _ref.onSelect,
|
3945
|
+
clientId = _ref.clientId;
|
3946
|
+
var _useBiBotChatBot = useBiBotChatBot({
|
3947
|
+
clientId: clientId
|
3948
|
+
}),
|
3949
|
+
chatBubbleConfig = _useBiBotChatBot.chatBubbleConfig;
|
3914
3950
|
return React.createElement("div", {
|
3915
|
-
className: styles['predefined-questions']
|
3951
|
+
className: styles['predefined-questions'],
|
3952
|
+
style: {
|
3953
|
+
height: '50%',
|
3954
|
+
color: '#000'
|
3955
|
+
}
|
3916
3956
|
}, questions.map(function (question, index) {
|
3957
|
+
var _chatBubbleConfig$col;
|
3917
3958
|
return React.createElement("div", {
|
3918
3959
|
key: index,
|
3919
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
|
+
},
|
3920
3974
|
onClick: function onClick() {
|
3921
|
-
|
3975
|
+
onSelect(question);
|
3922
3976
|
}
|
3923
|
-
}, question);
|
3977
|
+
}, question.question);
|
3924
3978
|
}));
|
3925
3979
|
};
|
3926
3980
|
var ChatBubbleBiBot = function ChatBubbleBiBot(_ref2) {
|
3927
|
-
var _chatBubbleConfig$
|
3981
|
+
var _chatBubbleConfig$col2, _chatBubbleConfig$col3;
|
3928
3982
|
var clientId = _ref2.clientId;
|
3929
|
-
var
|
3983
|
+
var _useBiBotChatBot2 = useBiBotChatBot({
|
3930
3984
|
clientId: clientId
|
3931
3985
|
}),
|
3932
|
-
chatIsOpen =
|
3933
|
-
messages =
|
3934
|
-
isLoading =
|
3935
|
-
messageEndRef =
|
3936
|
-
userInput =
|
3937
|
-
handleUserInput =
|
3938
|
-
handleKeyPress =
|
3939
|
-
sendInputInquiry =
|
3940
|
-
toggleChat =
|
3941
|
-
chatBubbleConfig =
|
3942
|
-
showPredefinedQuestions =
|
3943
|
-
predefinedQuestions =
|
3944
|
-
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;
|
3945
3999
|
var isOnline = useOnlineStatus();
|
3946
4000
|
return React.createElement("div", {
|
3947
4001
|
className: "chat-bubble " + (chatIsOpen ? 'open' : ''),
|
@@ -3968,7 +4022,7 @@ var ChatBubbleBiBot = function ChatBubbleBiBot(_ref2) {
|
|
3968
4022
|
}, React.createElement("div", {
|
3969
4023
|
className: styles['chat-header'],
|
3970
4024
|
style: {
|
3971
|
-
backgroundColor: (_chatBubbleConfig$
|
4025
|
+
backgroundColor: (_chatBubbleConfig$col2 = chatBubbleConfig === null || chatBubbleConfig === void 0 ? void 0 : chatBubbleConfig.color) != null ? _chatBubbleConfig$col2 : '#dedede',
|
3972
4026
|
height: 50,
|
3973
4027
|
borderTopLeftRadius: 8,
|
3974
4028
|
borderTopRightRadius: 8,
|
@@ -4065,8 +4119,9 @@ var ChatBubbleBiBot = function ChatBubbleBiBot(_ref2) {
|
|
4065
4119
|
}
|
4066
4120
|
}, message.text));
|
4067
4121
|
}), showPredefinedQuestions && predefinedQuestions && predefinedQuestions.length > 0 && React.createElement(PredefinedQuestions, {
|
4068
|
-
questions: predefinedQuestions,
|
4069
|
-
onSelect: handlePredefinedQuestionSelect
|
4122
|
+
questions: predefinedQuestions.slice(0, 5),
|
4123
|
+
onSelect: handlePredefinedQuestionSelect,
|
4124
|
+
clientId: clientId
|
4070
4125
|
}), isLoading && React.createElement("div", {
|
4071
4126
|
style: {
|
4072
4127
|
marginLeft: '20px'
|
@@ -4111,14 +4166,16 @@ var ChatBubbleBiBot = function ChatBubbleBiBot(_ref2) {
|
|
4111
4166
|
border: 'none',
|
4112
4167
|
cursor: 'pointer'
|
4113
4168
|
},
|
4114
|
-
onClick:
|
4169
|
+
onClick: function onClick() {
|
4170
|
+
return sendInputInquiry();
|
4171
|
+
}
|
4115
4172
|
}, React.createElement(SendMessageIcon, {
|
4116
4173
|
color: isLoading ? '#fff' : chatBubbleConfig === null || chatBubbleConfig === void 0 ? void 0 : chatBubbleConfig.color
|
4117
4174
|
})))), React.createElement("button", {
|
4118
4175
|
onClick: toggleChat,
|
4119
4176
|
className: styles['chat-toggle'],
|
4120
4177
|
style: {
|
4121
|
-
backgroundColor: (_chatBubbleConfig$
|
4178
|
+
backgroundColor: (_chatBubbleConfig$col3 = chatBubbleConfig === null || chatBubbleConfig === void 0 ? void 0 : chatBubbleConfig.color) != null ? _chatBubbleConfig$col3 : '#dedede',
|
4122
4179
|
color: '#fff',
|
4123
4180
|
borderRadius: '50%',
|
4124
4181
|
cursor: 'pointer',
|