bibot 1.0.41 → 1.0.45

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,3 @@
1
1
  import React from 'react';
2
- interface AvatarProps {
3
- source: string | undefined;
4
- height: string;
5
- width: string;
6
- indicator?: string;
7
- borderColor: string | undefined;
8
- }
2
+ import { AvatarProps } from '../types/coreInterfaces';
9
3
  export declare const Avatar: React.FC<AvatarProps>;
10
- export {};
@@ -1,7 +1,5 @@
1
1
  import React from 'react';
2
- interface iconColor {
3
- color: string | undefined;
4
- }
2
+ import { iconColor } from '../types/coreInterfaces';
5
3
  declare function SendMessageIcon({ color }: iconColor): React.JSX.Element;
6
4
  declare function DefaultBotProfile(): React.JSX.Element;
7
5
  declare function ChatIcon(): React.JSX.Element;
@@ -1,8 +1,4 @@
1
1
  import * as React from 'react';
2
- interface bubbleProps {
3
- clientId: string;
4
- client_session_id?: string;
5
- redirect_notice?: boolean;
6
- }
7
- declare const ChatBubbleBiBot: ({ clientId, client_session_id, redirect_notice }: bubbleProps) => React.JSX.Element;
2
+ import { BiBotProps } from '../types/coreInterfaces';
3
+ declare const ChatBubbleBiBot: ({ clientId, client_session_id, redirect_notice, test }: BiBotProps) => React.JSX.Element;
8
4
  export default ChatBubbleBiBot;
@@ -2,7 +2,7 @@ export declare const APP_DATA: {
2
2
  APP_NAME: string;
3
3
  };
4
4
  export declare const endpoints: {
5
- readonly inference: string;
5
+ readonly getInferenceURL: (isTest?: boolean) => string;
6
6
  };
7
7
  export declare enum domain {
8
8
  app = "/app",
@@ -1,9 +1,5 @@
1
1
  import React from 'react';
2
- import { ReactNode } from 'react';
3
- import type { AppContextProps } from '../types/coreInterfaces';
4
- interface AppProps {
5
- children: ReactNode;
6
- }
2
+ import type { AppContextProps, AppProps } from '../types/coreInterfaces';
7
3
  declare const AppContext: React.Context<AppContextProps>;
8
4
  declare const AppProvider: React.FC<AppProps>;
9
5
  export { AppContext, AppProvider };
@@ -1,22 +1,8 @@
1
1
  import React from 'react';
2
- import { predefinedQuestionsType } from '../services/plugin-api';
3
- interface UseBiBotChatBotProps {
4
- clientId: string;
5
- client_session_id?: string;
6
- redirect_notice?: boolean;
7
- }
8
- interface ChatBubbleConfigProps {
9
- bgColor?: string;
10
- color?: string;
11
- title?: string;
12
- logo_url?: string;
13
- }
14
- declare const useBiBotChatBot: ({ clientId, client_session_id }: UseBiBotChatBotProps) => {
2
+ import { BiBotProps, ChatBubbleConfigProps, MESSAGES, predefinedQuestionsType } from '../types/coreInterfaces';
3
+ declare const useBiBotChatBot: ({ clientId, client_session_id, test }: BiBotProps) => {
15
4
  chatIsOpen: boolean;
16
- messages: {
17
- sender: 'user' | 'bot';
18
- text: string;
19
- }[];
5
+ messages: MESSAGES;
20
6
  isLoading: boolean;
21
7
  messageEndRef: React.RefObject<HTMLDivElement>;
22
8
  userInput: string;
@@ -1 +1 @@
1
- export declare const createPluginAxiosInstance: (params?: {}, headers?: {}) => import("axios").AxiosInstance;
1
+ export declare const createPluginAxiosInstance: (baseURL: string, params?: {}, headers?: {}) => import("axios").AxiosInstance;
package/dist/index.d.ts CHANGED
@@ -1,9 +1,4 @@
1
1
  import * as React from 'react';
2
2
  import './styles.css';
3
- interface Props {
4
- clientId: string;
5
- client_session_id?: string;
6
- redirect_notice?: boolean;
7
- }
8
- export declare const BiBot: ({ clientId, client_session_id }: Props) => React.JSX.Element;
9
- export {};
3
+ import { BiBotProps } from './types/coreInterfaces';
4
+ export declare const BiBot: ({ clientId, client_session_id, redirect_notice, test }: BiBotProps) => React.JSX.Element;
package/dist/index.js CHANGED
@@ -3266,31 +3266,7 @@ axios.HttpStatusCode = HttpStatusCode;
3266
3266
 
3267
3267
  axios.default = axios;
3268
3268
 
3269
- var baseUrls = {
3270
- inference: process.env.NODE_ENV !== 'production' ? 'https://inference.dev.bibot.thespuka.com/v0' : 'https://inference.bibot.app/v0'
3271
- };
3272
- var endpoints = {
3273
- get inference() {
3274
- return baseUrls.inference;
3275
- }
3276
- };
3277
- var domain;
3278
- (function (domain) {
3279
- domain["app"] = "/app";
3280
- domain["bibot"] = "/bibot";
3281
- domain["inference"] = "/inference";
3282
- })(domain || (domain = {}));
3283
- var resources;
3284
- (function (resources) {
3285
- resources["chatBubble"] = "/chat-bubble-config";
3286
- resources["predefinedQ"] = "/predefined-q";
3287
- resources["timeoutQ"] = "/timeout-q";
3288
- resources["q"] = "/q";
3289
- resources["predefinedQstatistics"] = "/predefined-questions-statistics";
3290
- })(resources || (resources = {}));
3291
-
3292
- var inferenceBaseURL = endpoints.inference;
3293
- var createPluginAxiosInstance = function createPluginAxiosInstance(params, headers) {
3269
+ var createPluginAxiosInstance = function createPluginAxiosInstance(baseURL, params, headers) {
3294
3270
  if (params === void 0) {
3295
3271
  params = {};
3296
3272
  }
@@ -3298,7 +3274,7 @@ var createPluginAxiosInstance = function createPluginAxiosInstance(params, heade
3298
3274
  headers = {};
3299
3275
  }
3300
3276
  var instance = axios.create(_extends({
3301
- baseURL: inferenceBaseURL,
3277
+ baseURL: baseURL,
3302
3278
  timeout: 60000,
3303
3279
  headers: _extends({
3304
3280
  'Content-Type': 'application/json'
@@ -3495,7 +3471,36 @@ var AppProvider = function AppProvider(_ref) {
3495
3471
  }, children);
3496
3472
  };
3497
3473
 
3498
- var getRemoteClientChatPredefinedQuestions = function getRemoteClientChatPredefinedQuestions(params) {
3474
+ var baseUrls = {
3475
+ inference: {
3476
+ production: 'https://inference.bibot.app/v0',
3477
+ test: 'https://inference.dev.bibot.thespuka.com/v0'
3478
+ }
3479
+ };
3480
+ var endpoints = {
3481
+ getInferenceURL: function getInferenceURL(isTest) {
3482
+ if (isTest === void 0) {
3483
+ isTest = false;
3484
+ }
3485
+ return isTest ? baseUrls.inference.test : baseUrls.inference.production;
3486
+ }
3487
+ };
3488
+ var domain;
3489
+ (function (domain) {
3490
+ domain["app"] = "/app";
3491
+ domain["bibot"] = "/bibot";
3492
+ domain["inference"] = "/inference";
3493
+ })(domain || (domain = {}));
3494
+ var resources;
3495
+ (function (resources) {
3496
+ resources["chatBubble"] = "/chat-bubble-config";
3497
+ resources["predefinedQ"] = "/predefined-q";
3498
+ resources["timeoutQ"] = "/timeout-q";
3499
+ resources["q"] = "/q";
3500
+ resources["predefinedQstatistics"] = "/predefined-questions-statistics";
3501
+ })(resources || (resources = {}));
3502
+
3503
+ var getRemoteClientChatPredefinedQuestions = function getRemoteClientChatPredefinedQuestions(pluginAxiosInstance, params) {
3499
3504
  return Promise.resolve(_catch(function () {
3500
3505
  var path = "" + domain.inference + resources.predefinedQ;
3501
3506
  return Promise.resolve(pluginAxiosInstance.get(path, {
@@ -3508,7 +3513,7 @@ var getRemoteClientChatPredefinedQuestions = function getRemoteClientChatPredefi
3508
3513
  return [];
3509
3514
  }));
3510
3515
  };
3511
- var getRemoteClientChatBubbleConfig = function getRemoteClientChatBubbleConfig(params) {
3516
+ var getRemoteClientChatBubbleConfig = function getRemoteClientChatBubbleConfig(pluginAxiosInstance, params) {
3512
3517
  try {
3513
3518
  return Promise.resolve(_catch(function () {
3514
3519
  var path = "" + domain.inference + resources.chatBubble;
@@ -3529,7 +3534,7 @@ var getRemoteClientChatBubbleConfig = function getRemoteClientChatBubbleConfig(p
3529
3534
  return Promise.reject(e);
3530
3535
  }
3531
3536
  };
3532
- var handleRetries = function handleRetries(data, attempt) {
3537
+ var handleRetries = function handleRetries(pluginAxiosInstance, data, attempt) {
3533
3538
  try {
3534
3539
  var maxAttempts = 30;
3535
3540
  var delay = 10000;
@@ -3540,11 +3545,11 @@ var handleRetries = function handleRetries(data, attempt) {
3540
3545
  return setTimeout(resolve, delay);
3541
3546
  })).then(function () {
3542
3547
  return _catch(function () {
3543
- return Promise.resolve(askTimedOutBiBot(_extends({}, data, {
3548
+ return Promise.resolve(askTimedOutBiBot(pluginAxiosInstance, _extends({}, data, {
3544
3549
  tries: attempt + 1
3545
3550
  }))).then(function (message) {
3546
3551
  if (message === defaultSlacker) {
3547
- return Promise.resolve(handleRetries(data, attempt + 1));
3552
+ return Promise.resolve(handleRetries(pluginAxiosInstance, data, attempt + 1));
3548
3553
  } else {
3549
3554
  return message;
3550
3555
  }
@@ -3557,13 +3562,13 @@ var handleRetries = function handleRetries(data, attempt) {
3557
3562
  return Promise.reject(e);
3558
3563
  }
3559
3564
  };
3560
- var askBiBot = function askBiBot(data) {
3565
+ var askBiBot = function askBiBot(pluginAxiosInstance, data) {
3561
3566
  try {
3562
3567
  return Promise.resolve(_catch(function () {
3563
3568
  var path = "" + domain.inference + resources.q;
3564
3569
  return Promise.resolve(pluginAxiosInstance.post(path, data)).then(function (response) {
3565
3570
  if (response.data.message === defaultSlacker) {
3566
- return Promise.resolve(handleRetries(data, 1));
3571
+ return Promise.resolve(handleRetries(pluginAxiosInstance, data, 1));
3567
3572
  } else {
3568
3573
  return response.data.message;
3569
3574
  }
@@ -3577,7 +3582,7 @@ var askBiBot = function askBiBot(data) {
3577
3582
  return Promise.reject(e);
3578
3583
  }
3579
3584
  };
3580
- var recordPredefinedQ = function recordPredefinedQ(data) {
3585
+ var recordPredefinedQ = function recordPredefinedQ(pluginAxiosInstance, data) {
3581
3586
  try {
3582
3587
  return Promise.resolve(_catch(function () {
3583
3588
  var path = "" + domain.inference + resources.predefinedQstatistics;
@@ -3594,7 +3599,7 @@ var recordPredefinedQ = function recordPredefinedQ(data) {
3594
3599
  return Promise.reject(e);
3595
3600
  }
3596
3601
  };
3597
- var askTimedOutBiBot = function askTimedOutBiBot(data) {
3602
+ var askTimedOutBiBot = function askTimedOutBiBot(pluginAxiosInstance, data) {
3598
3603
  try {
3599
3604
  return Promise.resolve(_catch(function () {
3600
3605
  var path = "" + domain.inference + resources.timeoutQ;
@@ -3611,7 +3616,6 @@ var askTimedOutBiBot = function askTimedOutBiBot(data) {
3611
3616
  }
3612
3617
  };
3613
3618
  var defaultSlacker = "BiBot_Retry_Later";
3614
- var pluginAxiosInstance = createPluginAxiosInstance();
3615
3619
 
3616
3620
  var useBiBotChatBot = function useBiBotChatBot(_ref) {
3617
3621
  var sendInputInquiry = function sendInputInquiry() {
@@ -3629,11 +3633,12 @@ var useBiBotChatBot = function useBiBotChatBot(_ref) {
3629
3633
  text: input
3630
3634
  }]);
3631
3635
  });
3632
- return Promise.resolve(askBiBot({
3636
+ return Promise.resolve(askBiBot(pluginAxiosInstance, {
3633
3637
  client_id: clientId,
3634
3638
  q: input,
3635
3639
  session_id: client_session_id ? client_session_id : state.sessionId,
3636
- chat_id: v4()
3640
+ chat_id: v4(),
3641
+ chat_history: messages
3637
3642
  })).then(function (response) {
3638
3643
  setMessages(function (messages) {
3639
3644
  return [].concat(messages, [{
@@ -3662,7 +3667,7 @@ var useBiBotChatBot = function useBiBotChatBot(_ref) {
3662
3667
  try {
3663
3668
  setIsLoading(true);
3664
3669
  var input = question.question.trim();
3665
- recordPredefinedQ({
3670
+ recordPredefinedQ(pluginAxiosInstance, {
3666
3671
  "client_id": clientId,
3667
3672
  "question": question.question,
3668
3673
  "q_n_a_id": question.q_n_a_id
@@ -3692,7 +3697,10 @@ var useBiBotChatBot = function useBiBotChatBot(_ref) {
3692
3697
  }
3693
3698
  };
3694
3699
  var clientId = _ref.clientId,
3695
- client_session_id = _ref.client_session_id;
3700
+ client_session_id = _ref.client_session_id,
3701
+ test = _ref.test;
3702
+ var baseURL = test ? endpoints.getInferenceURL(true) : endpoints.getInferenceURL(false);
3703
+ var pluginAxiosInstance = createPluginAxiosInstance(baseURL);
3696
3704
  var _useState = React.useState([]),
3697
3705
  predefinedQuestions = _useState[0],
3698
3706
  setPredefinedQuestions = _useState[1];
@@ -3725,13 +3733,13 @@ var useBiBotChatBot = function useBiBotChatBot(_ref) {
3725
3733
  };
3726
3734
  var getChatBubbleConfig = React.useCallback(function () {
3727
3735
  try {
3728
- return Promise.resolve(getRemoteClientChatPredefinedQuestions({
3736
+ return Promise.resolve(getRemoteClientChatPredefinedQuestions(pluginAxiosInstance, {
3729
3737
  client_id: clientId
3730
3738
  })).then(function (remotePredefinedQuestions) {
3731
3739
  if (remotePredefinedQuestions) {
3732
3740
  setPredefinedQuestions(remotePredefinedQuestions);
3733
3741
  }
3734
- return Promise.resolve(getRemoteClientChatBubbleConfig({
3742
+ return Promise.resolve(getRemoteClientChatBubbleConfig(pluginAxiosInstance, {
3735
3743
  client_id: clientId
3736
3744
  })).then(function (remoteChatBubbleConfig) {
3737
3745
  if (remoteChatBubbleConfig) {
@@ -4080,9 +4088,11 @@ var Loader = function Loader() {
4080
4088
  var PredefinedQuestions = function PredefinedQuestions(_ref) {
4081
4089
  var questions = _ref.questions,
4082
4090
  onSelect = _ref.onSelect,
4083
- clientId = _ref.clientId;
4091
+ clientId = _ref.clientId,
4092
+ test = _ref.test;
4084
4093
  var _useBiBotChatBot = useBiBotChatBot({
4085
- clientId: clientId
4094
+ clientId: clientId,
4095
+ test: test
4086
4096
  }),
4087
4097
  chatBubbleConfig = _useBiBotChatBot.chatBubbleConfig;
4088
4098
  return React.createElement("div", {
@@ -4139,11 +4149,13 @@ var ChatBubbleBiBot = function ChatBubbleBiBot(_ref2) {
4139
4149
  var _chatBubbleConfig$col2, _chatBubbleConfig$col3;
4140
4150
  var clientId = _ref2.clientId,
4141
4151
  client_session_id = _ref2.client_session_id,
4142
- redirect_notice = _ref2.redirect_notice;
4152
+ redirect_notice = _ref2.redirect_notice,
4153
+ test = _ref2.test;
4143
4154
  var _useBiBotChatBot2 = useBiBotChatBot({
4144
4155
  clientId: clientId,
4145
4156
  client_session_id: client_session_id,
4146
- redirect_notice: redirect_notice
4157
+ redirect_notice: redirect_notice,
4158
+ test: test
4147
4159
  }),
4148
4160
  chatIsOpen = _useBiBotChatBot2.chatIsOpen,
4149
4161
  messages = _useBiBotChatBot2.messages,
@@ -4352,11 +4364,14 @@ var ChatBubbleBiBot = function ChatBubbleBiBot(_ref2) {
4352
4364
 
4353
4365
  var BiBot = function BiBot(_ref) {
4354
4366
  var clientId = _ref.clientId,
4355
- client_session_id = _ref.client_session_id;
4367
+ client_session_id = _ref.client_session_id,
4368
+ redirect_notice = _ref.redirect_notice,
4369
+ test = _ref.test;
4356
4370
  return React.createElement(AppProvider, null, React.createElement(ChatBubbleBiBot, {
4357
4371
  clientId: clientId,
4358
4372
  client_session_id: client_session_id,
4359
- redirect_notice: false
4373
+ redirect_notice: redirect_notice,
4374
+ test: test
4360
4375
  }));
4361
4376
  };
4362
4377