@botonic/react 1.0.0-dev.1 → 1.0.0-dev.2

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.
Files changed (116) hide show
  1. package/lib/components/button.js +2 -0
  2. package/lib/components/button.js.map +1 -1
  3. package/lib/components/components.js +1 -1
  4. package/lib/components/image.js +47 -5
  5. package/lib/components/image.js.map +1 -1
  6. package/lib/components/index.js +6 -6
  7. package/lib/components/markdown.js +1 -1
  8. package/lib/components/multichannel/multichannel-utils.js +8 -6
  9. package/lib/components/multichannel/multichannel-utils.js.map +1 -1
  10. package/lib/components/timestamps.js +1 -1
  11. package/lib/constants.js +2 -1
  12. package/lib/constants.js.map +1 -1
  13. package/lib/dev-app.js +7 -6
  14. package/lib/dev-app.js.map +1 -1
  15. package/lib/index.d.ts +3 -0
  16. package/lib/index.js +20 -20
  17. package/lib/message-utils.js +1 -1
  18. package/lib/util/dom.js +8 -2
  19. package/lib/util/dom.js.map +1 -1
  20. package/lib/util/environment.js +1 -1
  21. package/lib/util/objects.js +1 -1
  22. package/lib/util/react.js +1 -1
  23. package/lib/util/webchat.js +1 -1
  24. package/lib/webchat/actions.js +3 -1
  25. package/lib/webchat/actions.js.map +1 -1
  26. package/lib/webchat/devices/device-adapter.js +14 -4
  27. package/lib/webchat/devices/device-adapter.js.map +1 -1
  28. package/lib/webchat/devices/scrollbar-controller.js +5 -3
  29. package/lib/webchat/devices/scrollbar-controller.js.map +1 -1
  30. package/lib/webchat/header.js +1 -1
  31. package/lib/webchat/hooks.js +14 -4
  32. package/lib/webchat/hooks.js.map +1 -1
  33. package/lib/webchat/index.js +1 -1
  34. package/lib/webchat/webchat-reducer.js +6 -0
  35. package/lib/webchat/webchat-reducer.js.map +1 -1
  36. package/lib/webchat/webchat.js +21 -4
  37. package/lib/webchat/webchat.js.map +1 -1
  38. package/lib/webchat/webview.js +1 -1
  39. package/lib/webchat-app.js +20 -9
  40. package/lib/webchat-app.js.map +1 -1
  41. package/package.json +6 -6
  42. package/src/components/button.jsx +2 -0
  43. package/src/dev-app.jsx +8 -3
  44. package/src/experimental/components/custom-message.jsx +2 -1
  45. package/src/experimental/components/message.jsx +14 -7
  46. package/src/experimental/constants.js +189 -0
  47. package/src/experimental/contexts.jsx +36 -0
  48. package/src/experimental/dev-app.jsx +14 -7
  49. package/src/experimental/index.js +32 -20
  50. package/src/experimental/msg-to-botonic.jsx +9 -9
  51. package/src/experimental/react-bot.jsx +1 -1
  52. package/src/experimental/util/dom.js +55 -0
  53. package/src/experimental/util/objects.js +39 -0
  54. package/src/experimental/util/webchat.js +61 -0
  55. package/src/experimental/webchat/actions.jsx +24 -0
  56. package/src/experimental/webchat/hooks.js +296 -0
  57. package/src/experimental/webchat/messages-reducer.js +86 -0
  58. package/src/experimental/webchat/session-view.jsx +166 -0
  59. package/src/experimental/webchat/webchat-dev.jsx +23 -19
  60. package/src/experimental/webchat/webchat-reducer.js +68 -0
  61. package/src/experimental/webchat/webchat.jsx +107 -75
  62. package/src/experimental/webchat-app.jsx +34 -15
  63. package/src/index.d.ts +1 -0
  64. package/src/util/dom.js +5 -3
  65. package/src/webchat/devices/device-adapter.js +16 -4
  66. package/src/webchat/devices/scrollbar-controller.js +9 -4
  67. package/src/webchat/webchat.jsx +2 -1
  68. package/src/webchat-app.jsx +6 -4
  69. package/lib/experimental/components/audio.js +0 -46
  70. package/lib/experimental/components/audio.js.map +0 -1
  71. package/lib/experimental/components/carousel.js +0 -194
  72. package/lib/experimental/components/carousel.js.map +0 -1
  73. package/lib/experimental/components/custom-message.js +0 -132
  74. package/lib/experimental/components/custom-message.js.map +0 -1
  75. package/lib/experimental/components/document.js +0 -69
  76. package/lib/experimental/components/document.js.map +0 -1
  77. package/lib/experimental/components/image.js +0 -47
  78. package/lib/experimental/components/image.js.map +0 -1
  79. package/lib/experimental/components/index.js +0 -184
  80. package/lib/experimental/components/index.js.map +0 -1
  81. package/lib/experimental/components/location.js +0 -54
  82. package/lib/experimental/components/location.js.map +0 -1
  83. package/lib/experimental/components/markdown.js +0 -103
  84. package/lib/experimental/components/markdown.js.map +0 -1
  85. package/lib/experimental/components/message.js +0 -353
  86. package/lib/experimental/components/message.js.map +0 -1
  87. package/lib/experimental/components/text.js +0 -80
  88. package/lib/experimental/components/text.js.map +0 -1
  89. package/lib/experimental/components/video.js +0 -49
  90. package/lib/experimental/components/video.js.map +0 -1
  91. package/lib/experimental/components/whatsapp-template.js +0 -53
  92. package/lib/experimental/components/whatsapp-template.js.map +0 -1
  93. package/lib/experimental/dev-app.js +0 -240
  94. package/lib/experimental/dev-app.js.map +0 -1
  95. package/lib/experimental/index.js +0 -1022
  96. package/lib/experimental/index.js.map +0 -1
  97. package/lib/experimental/msg-to-botonic.js +0 -162
  98. package/lib/experimental/msg-to-botonic.js.map +0 -1
  99. package/lib/experimental/node-app.js +0 -97
  100. package/lib/experimental/node-app.js.map +0 -1
  101. package/lib/experimental/react-bot.js +0 -167
  102. package/lib/experimental/react-bot.js.map +0 -1
  103. package/lib/experimental/webchat/assets/Inter-VariableFont_slnt,wght.ttf +0 -0
  104. package/lib/experimental/webchat/assets/botonic-logo-white.svg +0 -16
  105. package/lib/experimental/webchat/assets/messenger.svg +0 -10
  106. package/lib/experimental/webchat/assets/open-new-window.svg +0 -3
  107. package/lib/experimental/webchat/assets/open.svg +0 -3
  108. package/lib/experimental/webchat/assets/telegram.svg +0 -10
  109. package/lib/experimental/webchat/assets/webchat.svg +0 -21
  110. package/lib/experimental/webchat/assets/whatsapp.svg +0 -4
  111. package/lib/experimental/webchat/webchat-dev.js +0 -300
  112. package/lib/experimental/webchat/webchat-dev.js.map +0 -1
  113. package/lib/experimental/webchat/webchat.js +0 -1051
  114. package/lib/experimental/webchat/webchat.js.map +0 -1
  115. package/lib/experimental/webchat-app.js +0 -642
  116. package/lib/experimental/webchat-app.js.map +0 -1
@@ -1,642 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- var _typeof = require("@babel/runtime/helpers/typeof");
6
-
7
- Object.defineProperty(exports, "__esModule", {
8
- value: true
9
- });
10
- exports.WebchatApp = void 0;
11
-
12
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
-
14
- var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
15
-
16
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
17
-
18
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
19
-
20
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
21
-
22
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
23
-
24
- var _core = require("@botonic/core");
25
-
26
- var _lodash = _interopRequireDefault(require("lodash.merge"));
27
-
28
- var _react = _interopRequireWildcard(require("react"));
29
-
30
- var _reactDom = require("react-dom");
31
-
32
- var _constants = require("../constants");
33
-
34
- var _dom = require("../util/dom");
35
-
36
- var _msgToBotonic = require("./msg-to-botonic");
37
-
38
- var _webchat = require("./webchat/webchat");
39
-
40
- var _excluded = ["theme", "persistentMenu", "coverComponent", "blockInputs", "enableAttachments", "enableUserInput", "enableAnimations", "enableEmojiPicker", "defaultDelay", "defaultTyping", "storage", "storageKey", "onInit", "onOpen", "onClose", "onMessage", "appId", "visibility", "server"];
41
-
42
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
43
-
44
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
45
-
46
- var WebchatApp = /*#__PURE__*/function () {
47
- function WebchatApp(_ref) {
48
- var _ref$theme = _ref.theme,
49
- theme = _ref$theme === void 0 ? {} : _ref$theme,
50
- persistentMenu = _ref.persistentMenu,
51
- coverComponent = _ref.coverComponent,
52
- blockInputs = _ref.blockInputs,
53
- enableEmojiPicker = _ref.enableEmojiPicker,
54
- enableAttachments = _ref.enableAttachments,
55
- enableUserInput = _ref.enableUserInput,
56
- enableAnimations = _ref.enableAnimations,
57
- hostId = _ref.hostId,
58
- shadowDOM = _ref.shadowDOM,
59
- defaultDelay = _ref.defaultDelay,
60
- defaultTyping = _ref.defaultTyping,
61
- storage = _ref.storage,
62
- storageKey = _ref.storageKey,
63
- onInit = _ref.onInit,
64
- onOpen = _ref.onOpen,
65
- onClose = _ref.onClose,
66
- onMessage = _ref.onMessage,
67
- appId = _ref.appId,
68
- visibility = _ref.visibility,
69
- server = _ref.server;
70
- (0, _classCallCheck2["default"])(this, WebchatApp);
71
- this.theme = theme;
72
- this.persistentMenu = persistentMenu;
73
- this.coverComponent = coverComponent;
74
- this.blockInputs = blockInputs;
75
- this.enableEmojiPicker = enableEmojiPicker;
76
- this.enableAttachments = enableAttachments;
77
- this.enableUserInput = enableUserInput;
78
- this.enableAnimations = enableAnimations;
79
- this.shadowDOM = Boolean(typeof shadowDOM === 'function' ? shadowDOM() : shadowDOM);
80
-
81
- if (this.shadowDOM && !(0, _dom.isShadowDOMSupported)()) {
82
- console.warn('[botonic] ShadowDOM not supported on this browser');
83
- this.shadowDOM = false;
84
- }
85
-
86
- this.hostId = hostId || _constants.WEBCHAT.DEFAULTS.HOST_ID;
87
- this.defaultDelay = defaultDelay;
88
- this.defaultTyping = defaultTyping;
89
- this.storage = storage;
90
- this.storageKey = storageKey;
91
- this.onInit = onInit;
92
- this.onOpen = onOpen;
93
- this.onClose = onClose;
94
- this.onMessage = onMessage;
95
- this.visibility = visibility;
96
- this.server = server;
97
- this.webchatRef = /*#__PURE__*/(0, _react.createRef)();
98
- this.appId = appId;
99
- }
100
-
101
- (0, _createClass2["default"])(WebchatApp, [{
102
- key: "createRootElement",
103
- value: function createRootElement(host) {
104
- // Create root element <div id='root'> if not exists
105
- // Create shadowDOM to root element if needed
106
- if (host) {
107
- if (host.id && this.hostId) {
108
- if (host.id != this.hostId) {
109
- console.warn("[botonic] Host ID \"".concat(host.id, "\" don't match 'hostId' option: ").concat(this.hostId, ". Using value: ").concat(host.id, "."));
110
- this.hostId = host.id;
111
- }
112
- } else if (host.id) this.hostId = host.id;else if (this.hostId) host.id = this.hostId;
113
- } else {
114
- host = document.getElementById(this.hostId);
115
- }
116
-
117
- if (!host) {
118
- host = document.createElement('div');
119
- host.id = this.hostId;
120
- if (document.body.firstChild) document.body.insertBefore(host, document.body.firstChild);else document.body.appendChild(host);
121
- }
122
-
123
- this.host = this.shadowDOM ? host.attachShadow({
124
- mode: 'open'
125
- }) : host;
126
- }
127
- }, {
128
- key: "getReactMountNode",
129
- value: function getReactMountNode(node) {
130
- if (!node) node = this.host;
131
- return node.shadowRoot ? node.shadowRoot : node;
132
- }
133
- }, {
134
- key: "onInitWebchat",
135
- value: function onInitWebchat() {
136
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
137
- args[_key] = arguments[_key];
138
- }
139
-
140
- this.onInit && this.onInit.apply(this, [this].concat(args));
141
- }
142
- }, {
143
- key: "onOpenWebchat",
144
- value: function onOpenWebchat() {
145
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
146
- args[_key2] = arguments[_key2];
147
- }
148
-
149
- this.onOpen && this.onOpen.apply(this, [this].concat(args));
150
- }
151
- }, {
152
- key: "onCloseWebchat",
153
- value: function onCloseWebchat() {
154
- for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
155
- args[_key3] = arguments[_key3];
156
- }
157
-
158
- this.onClose && this.onClose.apply(this, [this].concat(args));
159
- }
160
- }, {
161
- key: "onUserInput",
162
- value: function () {
163
- var _onUserInput = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(_ref2) {
164
- var user, input;
165
- return _regenerator["default"].wrap(function _callee$(_context) {
166
- while (1) {
167
- switch (_context.prev = _context.next) {
168
- case 0:
169
- user = _ref2.user, input = _ref2.input;
170
- this.onMessage && this.onMessage(this, {
171
- from: _constants.SENDERS.user,
172
- message: input
173
- });
174
- return _context.abrupt("return", this.hubtypeService.postMessage(user, input));
175
-
176
- case 3:
177
- case "end":
178
- return _context.stop();
179
- }
180
- }
181
- }, _callee, this);
182
- }));
183
-
184
- function onUserInput(_x) {
185
- return _onUserInput.apply(this, arguments);
186
- }
187
-
188
- return onUserInput;
189
- }()
190
- }, {
191
- key: "onConnectionRegained",
192
- value: function () {
193
- var _onConnectionRegained = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
194
- return _regenerator["default"].wrap(function _callee2$(_context2) {
195
- while (1) {
196
- switch (_context2.prev = _context2.next) {
197
- case 0:
198
- return _context2.abrupt("return", this.hubtypeService.onConnectionRegained());
199
-
200
- case 1:
201
- case "end":
202
- return _context2.stop();
203
- }
204
- }
205
- }, _callee2, this);
206
- }));
207
-
208
- function onConnectionRegained() {
209
- return _onConnectionRegained.apply(this, arguments);
210
- }
211
-
212
- return onConnectionRegained;
213
- }()
214
- }, {
215
- key: "onStateChange",
216
- value: function onStateChange(_ref3) {
217
- var _this = this;
218
-
219
- var user = _ref3.session.user,
220
- messagesJSON = _ref3.messagesJSON;
221
- var lastMessage = messagesJSON[messagesJSON.length - 1];
222
- var lastMessageId = lastMessage && lastMessage.id;
223
- var lastMessageUpdateDate = this.getLastMessageUpdate();
224
-
225
- if (this.hubtypeService) {
226
- this.hubtypeService.lastMessageId = lastMessageId;
227
- this.hubtypeService.lastMessageUpdateDate = lastMessageUpdateDate;
228
- } else if (!this.hubtypeService && user) {
229
- this.hubtypeService = new _core.HubtypeService({
230
- appId: this.appId,
231
- user: user,
232
- lastMessageId: lastMessageId,
233
- lastMessageUpdateDate: lastMessageUpdateDate,
234
- onEvent: function onEvent(event) {
235
- return _this.onServiceEvent(event);
236
- },
237
- unsentInputs: function unsentInputs() {
238
- return _this.webchatRef.current.getMessages().filter(function (msg) {
239
- return msg.ack === 0 && msg.unsentInput;
240
- });
241
- },
242
- server: this.server
243
- });
244
- }
245
- }
246
- }, {
247
- key: "onServiceEvent",
248
- value: function onServiceEvent(event) {
249
- if (event.action === 'connectionChange') this.webchatRef.current.setOnline(event.online);else if (event.action === 'update_message_info') this.updateMessageInfo(event.message.id, event.message);else if (event.message.type === 'update_webchat_settings') this.updateWebchatSettings(event.message.data);else if (event.message.type === 'sender_action') this.setTyping(event.message.data === 'typing_on');else {
250
- this.onMessage && this.onMessage(this, {
251
- from: _constants.SENDERS.bot,
252
- message: event.message
253
- });
254
- this.addBotMessage(event.message);
255
- }
256
- }
257
- }, {
258
- key: "updateUser",
259
- value: function updateUser(user) {
260
- this.webchatRef.current.updateUser(user);
261
- }
262
- }, {
263
- key: "addBotMessage",
264
- value: function addBotMessage(message) {
265
- this.webchatRef.current.addBotResponse({
266
- response: (0, _msgToBotonic.msgToBotonic)(message, this.theme.message && this.theme.message.customTypes || this.theme.customMessageTypes)
267
- });
268
- }
269
- }, {
270
- key: "addBotText",
271
- value: function addBotText(text) {
272
- this.addBotMessage({
273
- type: _core.INPUT.TEXT,
274
- data: text
275
- });
276
- }
277
- }, {
278
- key: "addUserMessage",
279
- value: function addUserMessage(message) {
280
- this.webchatRef.current.addUserMessage(message);
281
- }
282
- }, {
283
- key: "addUserText",
284
- value: function addUserText(text) {
285
- this.webchatRef.current.addUserMessage({
286
- type: _core.INPUT.TEXT,
287
- data: text
288
- });
289
- }
290
- }, {
291
- key: "addUserPayload",
292
- value: function addUserPayload(payload) {
293
- this.webchatRef.current.addUserMessage({
294
- type: _core.INPUT.POSTBACK,
295
- payload: payload
296
- });
297
- }
298
- }, {
299
- key: "setTyping",
300
- value: function setTyping(typing) {
301
- this.webchatRef.current.setTyping(typing);
302
- }
303
- }, {
304
- key: "open",
305
- value: function open() {
306
- this.webchatRef.current.openWebchat();
307
- }
308
- }, {
309
- key: "close",
310
- value: function close() {
311
- this.webchatRef.current.closeWebchat();
312
- }
313
- }, {
314
- key: "toggle",
315
- value: function toggle() {
316
- this.webchatRef.current.toggleWebchat();
317
- }
318
- }, {
319
- key: "openCoverComponent",
320
- value: function openCoverComponent() {
321
- this.webchatRef.current.openCoverComponent();
322
- }
323
- }, {
324
- key: "closeCoverComponent",
325
- value: function closeCoverComponent() {
326
- this.webchatRef.current.closeCoverComponent();
327
- }
328
- }, {
329
- key: "toggleCoverComponent",
330
- value: function toggleCoverComponent() {
331
- this.webchatRef.current.toggleCoverComponent();
332
- }
333
- }, {
334
- key: "getMessages",
335
- value: function getMessages() {
336
- return this.webchatRef.current.getMessages();
337
- }
338
- }, {
339
- key: "clearMessages",
340
- value: function clearMessages() {
341
- this.webchatRef.current.clearMessages();
342
- }
343
- }, {
344
- key: "getVisibility",
345
- value: function () {
346
- var _getVisibility = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3() {
347
- return _regenerator["default"].wrap(function _callee3$(_context3) {
348
- while (1) {
349
- switch (_context3.prev = _context3.next) {
350
- case 0:
351
- return _context3.abrupt("return", this.resolveWebchatVisibility({
352
- appId: this.appId,
353
- visibility: this.visibility
354
- }));
355
-
356
- case 1:
357
- case "end":
358
- return _context3.stop();
359
- }
360
- }
361
- }, _callee3, this);
362
- }));
363
-
364
- function getVisibility() {
365
- return _getVisibility.apply(this, arguments);
366
- }
367
-
368
- return getVisibility;
369
- }()
370
- }, {
371
- key: "getLastMessageUpdate",
372
- value: function getLastMessageUpdate() {
373
- return this.webchatRef.current.getLastMessageUpdate();
374
- }
375
- }, {
376
- key: "updateMessageInfo",
377
- value: function updateMessageInfo(msgId, messageInfo) {
378
- return this.webchatRef.current.updateMessageInfo(msgId, messageInfo);
379
- }
380
- }, {
381
- key: "updateWebchatSettings",
382
- value: function updateWebchatSettings(settings) {
383
- return this.webchatRef.current.updateWebchatSettings(settings);
384
- } // eslint-disable-next-line complexity
385
-
386
- }, {
387
- key: "getComponent",
388
- value: function getComponent() {
389
- var _this2 = this;
390
-
391
- var optionsAtRuntime = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
392
- var _optionsAtRuntime$the = optionsAtRuntime.theme,
393
- theme = _optionsAtRuntime$the === void 0 ? {} : _optionsAtRuntime$the,
394
- persistentMenu = optionsAtRuntime.persistentMenu,
395
- coverComponent = optionsAtRuntime.coverComponent,
396
- blockInputs = optionsAtRuntime.blockInputs,
397
- enableAttachments = optionsAtRuntime.enableAttachments,
398
- enableUserInput = optionsAtRuntime.enableUserInput,
399
- enableAnimations = optionsAtRuntime.enableAnimations,
400
- enableEmojiPicker = optionsAtRuntime.enableEmojiPicker,
401
- defaultDelay = optionsAtRuntime.defaultDelay,
402
- defaultTyping = optionsAtRuntime.defaultTyping,
403
- storage = optionsAtRuntime.storage,
404
- storageKey = optionsAtRuntime.storageKey,
405
- onInit = optionsAtRuntime.onInit,
406
- onOpen = optionsAtRuntime.onOpen,
407
- onClose = optionsAtRuntime.onClose,
408
- onMessage = optionsAtRuntime.onMessage,
409
- appId = optionsAtRuntime.appId,
410
- visibility = optionsAtRuntime.visibility,
411
- server = optionsAtRuntime.server,
412
- webchatOptions = (0, _objectWithoutProperties2["default"])(optionsAtRuntime, _excluded);
413
- theme = (0, _lodash["default"])(this.theme, theme);
414
- persistentMenu = persistentMenu || this.persistentMenu;
415
- coverComponent = coverComponent || this.coverComponent;
416
- blockInputs = blockInputs || this.blockInputs;
417
- enableEmojiPicker = enableEmojiPicker || this.enableEmojiPicker;
418
- enableAttachments = enableAttachments || this.enableAttachments;
419
- enableUserInput = enableUserInput || this.enableUserInput;
420
- enableAnimations = enableAnimations || this.enableAnimations;
421
- defaultDelay = defaultDelay || this.defaultDelay;
422
- defaultTyping = defaultTyping || this.defaultTyping;
423
- storage = storage || this.storage;
424
- storageKey = storageKey || this.storageKey;
425
- server = server || this.server;
426
- this.onInit = onInit || this.onInit;
427
- this.onOpen = onOpen || this.onOpen;
428
- this.onClose = onClose || this.onClose;
429
- this.onMessage = onMessage || this.onMessage;
430
- this.visibility = visibility || this.visibility;
431
- this.appId = appId || this.appId;
432
- return /*#__PURE__*/_react["default"].createElement(_webchat.Webchat, (0, _extends2["default"])({}, webchatOptions, {
433
- ref: this.webchatRef,
434
- host: this.host,
435
- shadowDOM: this.shadowDOM,
436
- theme: theme,
437
- persistentMenu: persistentMenu,
438
- coverComponent: coverComponent,
439
- blockInputs: blockInputs,
440
- enableEmojiPicker: enableEmojiPicker,
441
- enableAttachments: enableAttachments,
442
- enableUserInput: enableUserInput,
443
- enableAnimations: enableAnimations,
444
- storage: storage,
445
- storageKey: storageKey,
446
- defaultDelay: defaultDelay,
447
- defaultTyping: defaultTyping,
448
- onInit: function onInit() {
449
- return _this2.onInitWebchat.apply(_this2, arguments);
450
- },
451
- onOpen: function onOpen() {
452
- return _this2.onOpenWebchat.apply(_this2, arguments);
453
- },
454
- onClose: function onClose() {
455
- return _this2.onCloseWebchat.apply(_this2, arguments);
456
- },
457
- onUserInput: function onUserInput() {
458
- return _this2.onUserInput.apply(_this2, arguments);
459
- },
460
- onStateChange: function onStateChange(webchatState) {
461
- return _this2.onStateChange(webchatState);
462
- },
463
- server: server,
464
- doAuth: function doAuth() {
465
- return _this2.doAuth.apply(_this2, arguments);
466
- }
467
- }));
468
- }
469
- }, {
470
- key: "doAuth",
471
- value: function doAuth() {// TODO: we should inject the service in question to WebchatApp and do call this one
472
- }
473
- }, {
474
- key: "isWebchatVisible",
475
- value: function () {
476
- var _isWebchatVisible = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(_ref4) {
477
- var appId, _yield$HubtypeService, status;
478
-
479
- return _regenerator["default"].wrap(function _callee4$(_context4) {
480
- while (1) {
481
- switch (_context4.prev = _context4.next) {
482
- case 0:
483
- appId = _ref4.appId;
484
- _context4.prev = 1;
485
- _context4.next = 4;
486
- return _core.HubtypeService.getWebchatVisibility({
487
- appId: appId
488
- });
489
-
490
- case 4:
491
- _yield$HubtypeService = _context4.sent;
492
- status = _yield$HubtypeService.status;
493
- return _context4.abrupt("return", status === 200);
494
-
495
- case 9:
496
- _context4.prev = 9;
497
- _context4.t0 = _context4["catch"](1);
498
- return _context4.abrupt("return", false);
499
-
500
- case 12:
501
- case "end":
502
- return _context4.stop();
503
- }
504
- }
505
- }, _callee4, null, [[1, 9]]);
506
- }));
507
-
508
- function isWebchatVisible(_x2) {
509
- return _isWebchatVisible.apply(this, arguments);
510
- }
511
-
512
- return isWebchatVisible;
513
- }()
514
- }, {
515
- key: "isOnline",
516
- value: function isOnline() {
517
- return this.webchatRef.current.isOnline();
518
- }
519
- }, {
520
- key: "resolveWebchatVisibility",
521
- value: function () {
522
- var _resolveWebchatVisibility = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(optionsAtRuntime) {
523
- var appId, visibility;
524
- return _regenerator["default"].wrap(function _callee5$(_context5) {
525
- while (1) {
526
- switch (_context5.prev = _context5.next) {
527
- case 0:
528
- appId = optionsAtRuntime.appId, visibility = optionsAtRuntime.visibility;
529
- visibility = visibility || this.visibility;
530
-
531
- if (!(visibility === undefined || visibility === true)) {
532
- _context5.next = 4;
533
- break;
534
- }
535
-
536
- return _context5.abrupt("return", true);
537
-
538
- case 4:
539
- if (!(typeof visibility === 'function' && visibility())) {
540
- _context5.next = 6;
541
- break;
542
- }
543
-
544
- return _context5.abrupt("return", true);
545
-
546
- case 6:
547
- _context5.t0 = visibility === 'dynamic';
548
-
549
- if (!_context5.t0) {
550
- _context5.next = 11;
551
- break;
552
- }
553
-
554
- _context5.next = 10;
555
- return this.isWebchatVisible({
556
- appId: appId
557
- });
558
-
559
- case 10:
560
- _context5.t0 = _context5.sent;
561
-
562
- case 11:
563
- if (!_context5.t0) {
564
- _context5.next = 13;
565
- break;
566
- }
567
-
568
- return _context5.abrupt("return", true);
569
-
570
- case 13:
571
- return _context5.abrupt("return", false);
572
-
573
- case 14:
574
- case "end":
575
- return _context5.stop();
576
- }
577
- }
578
- }, _callee5, this);
579
- }));
580
-
581
- function resolveWebchatVisibility(_x3) {
582
- return _resolveWebchatVisibility.apply(this, arguments);
583
- }
584
-
585
- return resolveWebchatVisibility;
586
- }()
587
- }, {
588
- key: "render",
589
- value: function () {
590
- var _render2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7(dest) {
591
- var _this3 = this;
592
-
593
- var optionsAtRuntime,
594
- _args7 = arguments;
595
- return _regenerator["default"].wrap(function _callee7$(_context7) {
596
- while (1) {
597
- switch (_context7.prev = _context7.next) {
598
- case 0:
599
- optionsAtRuntime = _args7.length > 1 && _args7[1] !== undefined ? _args7[1] : {};
600
- (0, _dom.onDOMLoaded)( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6() {
601
- var isVisible;
602
- return _regenerator["default"].wrap(function _callee6$(_context6) {
603
- while (1) {
604
- switch (_context6.prev = _context6.next) {
605
- case 0:
606
- _this3.createRootElement(dest);
607
-
608
- _context6.next = 3;
609
- return _this3.resolveWebchatVisibility(optionsAtRuntime);
610
-
611
- case 3:
612
- isVisible = _context6.sent;
613
- if (isVisible) (0, _reactDom.render)(_this3.getComponent(optionsAtRuntime), _this3.getReactMountNode(dest));
614
-
615
- case 5:
616
- case "end":
617
- return _context6.stop();
618
- }
619
- }
620
- }, _callee6);
621
- })));
622
-
623
- case 2:
624
- case "end":
625
- return _context7.stop();
626
- }
627
- }
628
- }, _callee7);
629
- }));
630
-
631
- function render(_x4) {
632
- return _render2.apply(this, arguments);
633
- }
634
-
635
- return render;
636
- }()
637
- }]);
638
- return WebchatApp;
639
- }();
640
-
641
- exports.WebchatApp = WebchatApp;
642
- //# sourceMappingURL=webchat-app.js.map