bibot 1.0.22 → 1.0.24

Sign up to get free protection for your applications and to get access to all the features.
@@ -3485,16 +3485,33 @@ var AppProvider = function AppProvider(_ref) {
3485
3485
  };
3486
3486
 
3487
3487
  var getRemoteClientChatPredefinedQuestions = function getRemoteClientChatPredefinedQuestions(params) {
3488
- return Promise.resolve(_catch(function () {
3489
- var path = "" + domain.inference + resources.predefinedQ;
3490
- return Promise.resolve(pluginAxiosInstance.get(path, {
3491
- params: params
3492
- })).then(function (response) {
3493
- return response.data.predefined_messages;
3494
- });
3495
- }, function () {
3496
- return ['These are placeholders', 'They will be removed in production', 'This will be empty if there are no predefined questions', 'So hide if there are no predefined questions'];
3497
- }));
3488
+ try {
3489
+ return Promise.resolve(_catch(function () {
3490
+ var path = "" + domain.inference + resources.predefinedQ;
3491
+ return Promise.resolve(pluginAxiosInstance.get(path, {
3492
+ params: params
3493
+ })).then(function (response) {
3494
+ console.log(response.data.predefined_questions);
3495
+ return response.data.predefined_questions;
3496
+ });
3497
+ }, function () {
3498
+ return [{
3499
+ question: 'These are placeholders',
3500
+ answer: ''
3501
+ }, {
3502
+ question: 'They will be removed in production',
3503
+ answer: ''
3504
+ }, {
3505
+ question: 'This will be empty if there are no predefined questions',
3506
+ answer: ''
3507
+ }, {
3508
+ question: 'So hide if there are no predefined questions',
3509
+ answer: ''
3510
+ }];
3511
+ }));
3512
+ } catch (e) {
3513
+ return Promise.reject(e);
3514
+ }
3498
3515
  };
3499
3516
  var getRemoteClientChatBubbleConfig = function getRemoteClientChatBubbleConfig(params) {
3500
3517
  try {
@@ -3517,64 +3534,49 @@ var getRemoteClientChatBubbleConfig = function getRemoteClientChatBubbleConfig(p
3517
3534
  return Promise.reject(e);
3518
3535
  }
3519
3536
  };
3537
+ var handleRetries = function handleRetries(data, attempt) {
3538
+ try {
3539
+ var maxAttempts = 30;
3540
+ var delay = 10000;
3541
+ if (attempt >= maxAttempts) {
3542
+ return Promise.resolve("Sorry this is taking longer than usual. Please try again later");
3543
+ }
3544
+ return Promise.resolve(new Promise(function (resolve) {
3545
+ return setTimeout(resolve, delay);
3546
+ })).then(function () {
3547
+ return _catch(function () {
3548
+ return Promise.resolve(askTimedOutBiBot(_extends({}, data, {
3549
+ tries: attempt + 1
3550
+ }))).then(function (message) {
3551
+ if (message === defaultSlacker) {
3552
+ return Promise.resolve(handleRetries(data, attempt + 1));
3553
+ } else {
3554
+ return message;
3555
+ }
3556
+ });
3557
+ }, function (error) {
3558
+ return error.message;
3559
+ });
3560
+ });
3561
+ } catch (e) {
3562
+ return Promise.reject(e);
3563
+ }
3564
+ };
3520
3565
  var askBiBot = function askBiBot(data) {
3521
3566
  try {
3522
3567
  return Promise.resolve(_catch(function () {
3523
3568
  var path = "" + domain.inference + resources.q;
3524
3569
  return Promise.resolve(pluginAxiosInstance.post(path, data)).then(function (response) {
3525
3570
  if (response.data.message === defaultSlacker) {
3526
- return _catch(function () {
3527
- return Promise.resolve(new Promise(function (resolve) {
3528
- return setTimeout(resolve, 6000);
3529
- })).then(function () {
3530
- return Promise.resolve(askTimedOutBiBot(_extends({}, data, {
3531
- tries: 2
3532
- })));
3533
- });
3534
- }, function (error2) {
3535
- if (error2.code === 'ECONNABORTED' || error2.message.includes('Endpoint request timed out')) {
3536
- return _catch(function () {
3537
- return Promise.resolve(new Promise(function (resolve) {
3538
- return setTimeout(resolve, 6000);
3539
- })).then(function () {
3540
- return Promise.resolve(askTimedOutBiBot(_extends({}, data, {
3541
- tries: 3
3542
- })));
3543
- });
3544
- }, function (error3) {
3545
- return error3.message;
3546
- });
3547
- } else {
3548
- return error2.message;
3549
- }
3550
- });
3571
+ return Promise.resolve(handleRetries(data, 1));
3551
3572
  } else {
3552
3573
  return response.data.message;
3553
3574
  }
3554
3575
  });
3555
3576
  }, function (error1) {
3577
+ console.log('This is the error1 from the endpoint on the 1st try:', error1);
3556
3578
  console.log(error1.message);
3557
- if (error1.code === 'ECONNABORTED' || error1.message.includes('Endpoint request timed out')) {
3558
- return _catch(function () {
3559
- return Promise.resolve(askTimedOutBiBot(_extends({}, data, {
3560
- tries: 2
3561
- })));
3562
- }, function (error2) {
3563
- if (error2.code === 'ECONNABORTED' || error2.message.includes('Endpoint request timed out')) {
3564
- return _catch(function () {
3565
- return Promise.resolve(askTimedOutBiBot(_extends({}, data, {
3566
- tries: 3
3567
- })));
3568
- }, function (error3) {
3569
- return error3.message;
3570
- });
3571
- } else {
3572
- return error2.message;
3573
- }
3574
- });
3575
- } else {
3576
- return error1.message;
3577
- }
3579
+ return error1.message;
3578
3580
  }));
3579
3581
  } catch (e) {
3580
3582
  return Promise.reject(e);
@@ -3596,27 +3598,28 @@ var askTimedOutBiBot = function askTimedOutBiBot(data) {
3596
3598
  return Promise.reject(e);
3597
3599
  }
3598
3600
  };
3599
- var defaultSlacker = "Unfortunately I could not find any information that reasonably answers that question. I just forwarded your inquiry to support, they will respond ASAP.";
3601
+ var defaultSlacker = "BiBot_Retry_Later";
3600
3602
  var pluginAxiosInstance = createPluginAxiosInstance();
3601
3603
 
3602
3604
  var useBiBotChatBot = function useBiBotChatBot(_ref) {
3603
3605
  var sendInputInquiry = function sendInputInquiry() {
3604
3606
  try {
3605
3607
  setIsLoading(true);
3608
+ var input = userInput.trim();
3606
3609
  setUserInput('');
3607
3610
  return Promise.resolve(_finallyRethrows(function () {
3608
3611
  return _catch(function () {
3609
3612
  var _temp2 = function () {
3610
- if (userInput.trim()) {
3613
+ if (input) {
3611
3614
  setMessages(function (messages) {
3612
3615
  return [].concat(messages, [{
3613
3616
  sender: 'user',
3614
- text: userInput
3617
+ text: input
3615
3618
  }]);
3616
3619
  });
3617
3620
  return Promise.resolve(askBiBot({
3618
3621
  client_id: clientId,
3619
- q: userInput.trim(),
3622
+ q: input,
3620
3623
  session_id: state.sessionId,
3621
3624
  chat_id: v4()
3622
3625
  })).then(function (response) {
@@ -3632,7 +3635,7 @@ var useBiBotChatBot = function useBiBotChatBot(_ref) {
3632
3635
  if (_temp2 && _temp2.then) return _temp2.then(function () {});
3633
3636
  }, function (error) {
3634
3637
  var _error$message;
3635
- void error((_error$message = error === null || error === void 0 ? void 0 : error.message) != null ? _error$message : 'Failed to get response from server');
3638
+ console.error((_error$message = error === null || error === void 0 ? void 0 : error.message) != null ? _error$message : 'Failed to get response from server');
3636
3639
  });
3637
3640
  }, function (_wasThrown, _result) {
3638
3641
  setIsLoading(false);
@@ -3643,6 +3646,33 @@ var useBiBotChatBot = function useBiBotChatBot(_ref) {
3643
3646
  return Promise.reject(e);
3644
3647
  }
3645
3648
  };
3649
+ var askPredefinedQuestion = function askPredefinedQuestion(question) {
3650
+ try {
3651
+ setIsLoading(true);
3652
+ var input = question.question.trim();
3653
+ setUserInput('');
3654
+ if (input === question.question) {
3655
+ setMessages(function (messages) {
3656
+ return [].concat(messages, [{
3657
+ sender: 'user',
3658
+ text: input
3659
+ }]);
3660
+ });
3661
+ setTimeout(function () {
3662
+ setMessages(function (messages) {
3663
+ return [].concat(messages, [{
3664
+ sender: 'bot',
3665
+ text: question.answer
3666
+ }]);
3667
+ });
3668
+ setIsLoading(false);
3669
+ }, 1000);
3670
+ }
3671
+ return Promise.resolve();
3672
+ } catch (e) {
3673
+ return Promise.reject(e);
3674
+ }
3675
+ };
3646
3676
  var clientId = _ref.clientId;
3647
3677
  var _useState = useState([]),
3648
3678
  predefinedQuestions = _useState[0],
@@ -3669,9 +3699,10 @@ var useBiBotChatBot = function useBiBotChatBot(_ref) {
3669
3699
  chatBubbleConfig = _useState7[0],
3670
3700
  setChatBubbleConfig = _useState7[1];
3671
3701
  var handlePredefinedQuestionSelect = function handlePredefinedQuestionSelect(question) {
3672
- setUserInput(question);
3673
3702
  sendInputInquiry();
3674
- setShowPredefinedQuestions(false);
3703
+ askPredefinedQuestion(question);
3704
+ setUserInput('');
3705
+ setShowPredefinedQuestions(true);
3675
3706
  };
3676
3707
  var getChatBubbleConfig = useCallback(function () {
3677
3708
  try {
@@ -3907,38 +3938,61 @@ var useOnlineStatus = function useOnlineStatus() {
3907
3938
 
3908
3939
  var PredefinedQuestions = function PredefinedQuestions(_ref) {
3909
3940
  var questions = _ref.questions,
3910
- onSelect = _ref.onSelect;
3941
+ onSelect = _ref.onSelect,
3942
+ clientId = _ref.clientId;
3943
+ var _useBiBotChatBot = useBiBotChatBot({
3944
+ clientId: clientId
3945
+ }),
3946
+ chatBubbleConfig = _useBiBotChatBot.chatBubbleConfig;
3911
3947
  return createElement("div", {
3912
- className: styles['predefined-questions']
3948
+ className: styles['predefined-questions'],
3949
+ style: {
3950
+ height: '50%',
3951
+ color: '#000'
3952
+ }
3913
3953
  }, questions.map(function (question, index) {
3954
+ var _chatBubbleConfig$col;
3914
3955
  return createElement("div", {
3915
3956
  key: index,
3916
3957
  className: styles['predefined-questions'],
3958
+ style: {
3959
+ backgroundColor: '#fff',
3960
+ border: "0.5px solid " + (chatBubbleConfig ? (_chatBubbleConfig$col = chatBubbleConfig === null || chatBubbleConfig === void 0 ? void 0 : chatBubbleConfig.color) != null ? _chatBubbleConfig$col : '#dedede' : '#000'),
3961
+ fontSize: 16,
3962
+ margin: 5,
3963
+ textAlign: 'start',
3964
+ height: 20,
3965
+ padding: 10,
3966
+ display: 'flex',
3967
+ alignItems: 'center',
3968
+ borderRadius: 6,
3969
+ cursor: 'pointer'
3970
+ },
3917
3971
  onClick: function onClick() {
3918
- return onSelect(question);
3972
+ onSelect(question);
3919
3973
  }
3920
- }, question);
3974
+ }, question.question);
3921
3975
  }));
3922
3976
  };
3923
3977
  var ChatBubbleBiBot = function ChatBubbleBiBot(_ref2) {
3924
- var _chatBubbleConfig$col, _chatBubbleConfig$col2;
3978
+ var _chatBubbleConfig$col2, _chatBubbleConfig$col3;
3925
3979
  var clientId = _ref2.clientId;
3926
- var _useBiBotChatBot = useBiBotChatBot({
3980
+ var _useBiBotChatBot2 = useBiBotChatBot({
3927
3981
  clientId: clientId
3928
3982
  }),
3929
- chatIsOpen = _useBiBotChatBot.chatIsOpen,
3930
- messages = _useBiBotChatBot.messages,
3931
- isLoading = _useBiBotChatBot.isLoading,
3932
- messageEndRef = _useBiBotChatBot.messageEndRef,
3933
- userInput = _useBiBotChatBot.userInput,
3934
- handleUserInput = _useBiBotChatBot.handleUserInput,
3935
- handleKeyPress = _useBiBotChatBot.handleKeyPress,
3936
- sendInputInquiry = _useBiBotChatBot.sendInputInquiry,
3937
- toggleChat = _useBiBotChatBot.toggleChat,
3938
- chatBubbleConfig = _useBiBotChatBot.chatBubbleConfig,
3939
- showPredefinedQuestions = _useBiBotChatBot.showPredefinedQuestions,
3940
- predefinedQuestions = _useBiBotChatBot.predefinedQuestions,
3941
- handlePredefinedQuestionSelect = _useBiBotChatBot.handlePredefinedQuestionSelect;
3983
+ chatIsOpen = _useBiBotChatBot2.chatIsOpen,
3984
+ messages = _useBiBotChatBot2.messages,
3985
+ isLoading = _useBiBotChatBot2.isLoading,
3986
+ messageEndRef = _useBiBotChatBot2.messageEndRef,
3987
+ userInput = _useBiBotChatBot2.userInput,
3988
+ handleUserInput = _useBiBotChatBot2.handleUserInput,
3989
+ handleKeyPress = _useBiBotChatBot2.handleKeyPress,
3990
+ sendInputInquiry = _useBiBotChatBot2.sendInputInquiry,
3991
+ toggleChat = _useBiBotChatBot2.toggleChat,
3992
+ chatBubbleConfig = _useBiBotChatBot2.chatBubbleConfig,
3993
+ showPredefinedQuestions = _useBiBotChatBot2.showPredefinedQuestions,
3994
+ predefinedQuestions = _useBiBotChatBot2.predefinedQuestions,
3995
+ handlePredefinedQuestionSelect = _useBiBotChatBot2.handlePredefinedQuestionSelect;
3942
3996
  var isOnline = useOnlineStatus();
3943
3997
  return createElement("div", {
3944
3998
  className: "chat-bubble " + (chatIsOpen ? 'open' : ''),
@@ -3965,7 +4019,7 @@ var ChatBubbleBiBot = function ChatBubbleBiBot(_ref2) {
3965
4019
  }, createElement("div", {
3966
4020
  className: styles['chat-header'],
3967
4021
  style: {
3968
- backgroundColor: (_chatBubbleConfig$col = chatBubbleConfig === null || chatBubbleConfig === void 0 ? void 0 : chatBubbleConfig.color) != null ? _chatBubbleConfig$col : '#dedede',
4022
+ backgroundColor: (_chatBubbleConfig$col2 = chatBubbleConfig === null || chatBubbleConfig === void 0 ? void 0 : chatBubbleConfig.color) != null ? _chatBubbleConfig$col2 : '#dedede',
3969
4023
  height: 50,
3970
4024
  borderTopLeftRadius: 8,
3971
4025
  borderTopRightRadius: 8,
@@ -4062,8 +4116,9 @@ var ChatBubbleBiBot = function ChatBubbleBiBot(_ref2) {
4062
4116
  }
4063
4117
  }, message.text));
4064
4118
  }), showPredefinedQuestions && predefinedQuestions && predefinedQuestions.length > 0 && createElement(PredefinedQuestions, {
4065
- questions: predefinedQuestions,
4066
- onSelect: handlePredefinedQuestionSelect
4119
+ questions: predefinedQuestions.slice(0, 5),
4120
+ onSelect: handlePredefinedQuestionSelect,
4121
+ clientId: clientId
4067
4122
  }), isLoading && createElement("div", {
4068
4123
  style: {
4069
4124
  marginLeft: '20px'
@@ -4108,14 +4163,16 @@ var ChatBubbleBiBot = function ChatBubbleBiBot(_ref2) {
4108
4163
  border: 'none',
4109
4164
  cursor: 'pointer'
4110
4165
  },
4111
- onClick: sendInputInquiry
4166
+ onClick: function onClick() {
4167
+ return sendInputInquiry();
4168
+ }
4112
4169
  }, createElement(SendMessageIcon, {
4113
4170
  color: isLoading ? '#fff' : chatBubbleConfig === null || chatBubbleConfig === void 0 ? void 0 : chatBubbleConfig.color
4114
4171
  })))), createElement("button", {
4115
4172
  onClick: toggleChat,
4116
4173
  className: styles['chat-toggle'],
4117
4174
  style: {
4118
- backgroundColor: (_chatBubbleConfig$col2 = chatBubbleConfig === null || chatBubbleConfig === void 0 ? void 0 : chatBubbleConfig.color) != null ? _chatBubbleConfig$col2 : '#dedede',
4175
+ backgroundColor: (_chatBubbleConfig$col3 = chatBubbleConfig === null || chatBubbleConfig === void 0 ? void 0 : chatBubbleConfig.color) != null ? _chatBubbleConfig$col3 : '#dedede',
4119
4176
  color: '#fff',
4120
4177
  borderRadius: '50%',
4121
4178
  cursor: 'pointer',