@hellotext/hellotext 1.8.3 → 1.8.5
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.
- package/__tests__/core/configuration/webchat_test.js +163 -0
- package/__tests__/hellotext_test.js +97 -101
- package/dist/hellotext.js +1 -1
- package/docs/webchat.md +101 -0
- package/jest.config.js +1 -0
- package/jest.setup.js +9 -0
- package/lib/api/index.js +6 -0
- package/lib/api/web_chat/messages.js +74 -0
- package/lib/api/web_chats.js +53 -0
- package/lib/api/webchat/messages.js +85 -0
- package/lib/api/webchats.js +53 -0
- package/lib/builders/logo_builder.js +2 -1
- package/lib/channels/application_channel.js +68 -0
- package/lib/channels/web_chat_channel.js +97 -0
- package/lib/channels/webchat_channel.js +112 -0
- package/lib/controllers/mixins/usePopover.js +61 -0
- package/lib/controllers/web_chat/pagination_controller.js +81 -0
- package/lib/controllers/webchat/emoji_picker_controller.js +134 -0
- package/lib/controllers/webchat_controller.js +446 -0
- package/lib/core/configuration/web_chat.js +168 -0
- package/lib/core/configuration/webchat.js +185 -0
- package/lib/core/configuration.js +6 -1
- package/lib/core/event.js +1 -1
- package/lib/hellotext.js +18 -9
- package/lib/index.js +4 -0
- package/lib/models/business.js +9 -1
- package/lib/models/index.js +7 -0
- package/lib/models/session.js +2 -0
- package/lib/models/web_chat.js +51 -0
- package/lib/models/webchat.js +51 -0
- package/package.json +8 -7
- package/src/api/index.js +5 -0
- package/src/api/webchat/messages.js +55 -0
- package/src/api/webchats.js +30 -0
- package/src/builders/logo_builder.js +8 -4
- package/src/channels/application_channel.js +45 -0
- package/src/channels/webchat_channel.js +77 -0
- package/src/controllers/mixins/usePopover.js +50 -0
- package/src/controllers/webchat/emoji_picker_controller.js +82 -0
- package/src/controllers/webchat_controller.js +448 -0
- package/src/core/configuration/webchat.js +176 -0
- package/src/core/configuration.js +5 -0
- package/src/core/event.js +10 -1
- package/src/hellotext.js +7 -2
- package/src/index.js +5 -0
- package/src/models/business.js +11 -1
- package/src/models/index.js +1 -0
- package/src/models/session.js +7 -5
- package/src/models/webchat.js +28 -0
- package/styles/index.css +4 -0
- package/webpack.config.js +1 -1
package/docs/webchat.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
## Webchat
|
|
2
|
+
|
|
3
|
+
Hellotext allows you to build webchats via the dashboard and allow Hellotext.js to load a given webchat with
|
|
4
|
+
a specific ID and show it to the user. A webchat can be specified when initializing the library by passing a `webchat` property
|
|
5
|
+
to the configuration option.
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
Hellotext.initialize('PUBLIC_BUSINESS_ID', {
|
|
9
|
+
webchat: {
|
|
10
|
+
id,
|
|
11
|
+
container,
|
|
12
|
+
placement,
|
|
13
|
+
classes,
|
|
14
|
+
triggerClasses,
|
|
15
|
+
style: {
|
|
16
|
+
primaryColor,
|
|
17
|
+
secondaryColor,
|
|
18
|
+
typography
|
|
19
|
+
},
|
|
20
|
+
behaviour,
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
| Property | Description | Type | Default |
|
|
26
|
+
|----------------|------------------------------------------------------------------------------------------------------------------------------------------|--------|----------------|
|
|
27
|
+
| id | The id of the webchat to load. **required** | String | null |
|
|
28
|
+
| container | The container to append the webchat to, must be a valid CSS selector. If none specified, the webchat is appended at the end of the body. | String | `body` |
|
|
29
|
+
| placement | The placement of the webchat, determined according to the parent `container`. | Enum | `bottom-right` |
|
|
30
|
+
| classes | An array or comma separated String of additional CSS classes to apply to the webchat popover. | String | null |
|
|
31
|
+
| triggerClasses | An array or comma separated String of additional CSS classes to apply to the webchat trigger. | String | null |
|
|
32
|
+
| style | Style overrides to the WebChat's style configuration as created on the dashboard. | Object | null |
|
|
33
|
+
| behaviour | The behaviour of the webchat when it is open and a click was made outside of it | Enum | `popover` |
|
|
34
|
+
|
|
35
|
+
### Position
|
|
36
|
+
|
|
37
|
+
The default position for a webchat is `bottom-right`, but you can specify any of the following values
|
|
38
|
+
|
|
39
|
+
- `bottom-left`
|
|
40
|
+
- `bottom-right`
|
|
41
|
+
- `top-left`
|
|
42
|
+
- `top-right`
|
|
43
|
+
|
|
44
|
+
### Style
|
|
45
|
+
|
|
46
|
+
The following properties are accepted for the `style` object.
|
|
47
|
+
|
|
48
|
+
- `primaryColor` - The primary color of the Webchat. Must be either in hex or rgb/a formats. Affects the following elements:
|
|
49
|
+
- Trigger background
|
|
50
|
+
- Popover header background
|
|
51
|
+
- Agent icon color
|
|
52
|
+
- Toolbar button hover
|
|
53
|
+
- Incoming message background
|
|
54
|
+
|
|
55
|
+
The primary color is controlled via a `--webchat-primary-color` CSS variable.
|
|
56
|
+
|
|
57
|
+
- `secondaryColor` - The secondary color of the webchat. Must be either in hex or rgb/a formats. Affects the following elements:
|
|
58
|
+
- Trigger icon color
|
|
59
|
+
- Popover header text color
|
|
60
|
+
- Agent icon background
|
|
61
|
+
- Incoming message text color
|
|
62
|
+
|
|
63
|
+
The secondary color is controlled via a `--webchat-secondary-color` CSS variable.
|
|
64
|
+
- `typography` - The font family to use for the webchat.
|
|
65
|
+
|
|
66
|
+
All properties accept a valid CSS value, for example, `primaryColor: '#EEEEEE'` or `secondaryColor: '#ff0000'`.
|
|
67
|
+
|
|
68
|
+
### behaviour
|
|
69
|
+
|
|
70
|
+
Determines how the webchat functions when it is open and a click is made outside of it. The following values are accepted.
|
|
71
|
+
|
|
72
|
+
- `popover` - Closes the webchat when a click is made outside of it. This is the default behaviour.
|
|
73
|
+
- `modal` - Prevents the webchat from closing when a click is made outside of it. The webchat can only be closed by clicking on the trigger.
|
|
74
|
+
|
|
75
|
+
### Events
|
|
76
|
+
|
|
77
|
+
The webchat emits the following events which can be listened to, to add an event listener you can `Hellotext.addEventListener(event, callback)`.
|
|
78
|
+
|
|
79
|
+
- `webchat:mounted` - Emitted when the webchat is mounted
|
|
80
|
+
- `webchat:opened` - Emitted when the webchat is opened
|
|
81
|
+
- `webchat:closed` - Emitted when the webchat is closed
|
|
82
|
+
|
|
83
|
+
- `webchat:message:sent` - Emitted when a message is sent by the user. The message is passed as an argument to the callback, containing the following properties
|
|
84
|
+
|
|
85
|
+
```javascript
|
|
86
|
+
{
|
|
87
|
+
id: 'xxxxxx'
|
|
88
|
+
body: 'The message the client sent',
|
|
89
|
+
attachments: [], // An array of File objects that reference the attachments the user sent.
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
- `webchat:message:received` - Emitted when a message is received by the webchat from Hellotext. The message is passed as an argument to the callback, containing the following properties
|
|
94
|
+
|
|
95
|
+
```javascript
|
|
96
|
+
{
|
|
97
|
+
id: 'xxxxxx',
|
|
98
|
+
body: 'The message the client received from Hellotext',
|
|
99
|
+
attachments: [], // An Array of URLs referencing the attachments the user received.
|
|
100
|
+
}
|
|
101
|
+
```
|
package/jest.config.js
CHANGED
package/jest.setup.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require('whatwg-fetch');
|
|
2
|
+
|
|
1
3
|
global.crypto.randomUUID = () => {
|
|
2
4
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
3
5
|
const r = (Math.random() * 16) | 0;
|
|
@@ -5,3 +7,10 @@ global.crypto.randomUUID = () => {
|
|
|
5
7
|
return v.toString(16);
|
|
6
8
|
});
|
|
7
9
|
};
|
|
10
|
+
|
|
11
|
+
global.fetch = jest.fn(() =>
|
|
12
|
+
Promise.resolve({
|
|
13
|
+
json: () => Promise.resolve({}),
|
|
14
|
+
text: () => Promise.resolve(''),
|
|
15
|
+
})
|
|
16
|
+
);
|
package/lib/api/index.js
CHANGED
|
@@ -13,6 +13,7 @@ exports.default = void 0;
|
|
|
13
13
|
var _businesses = _interopRequireDefault(require("./businesses"));
|
|
14
14
|
var _events = _interopRequireDefault(require("./events"));
|
|
15
15
|
var _forms = _interopRequireDefault(require("./forms"));
|
|
16
|
+
var _webchats = _interopRequireDefault(require("./webchats"));
|
|
16
17
|
var _response = require("./response");
|
|
17
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
19
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
@@ -39,6 +40,11 @@ var API = /*#__PURE__*/function () {
|
|
|
39
40
|
get: function get() {
|
|
40
41
|
return _forms.default;
|
|
41
42
|
}
|
|
43
|
+
}, {
|
|
44
|
+
key: "webchats",
|
|
45
|
+
get: function get() {
|
|
46
|
+
return _webchats.default;
|
|
47
|
+
}
|
|
42
48
|
}]);
|
|
43
49
|
return API;
|
|
44
50
|
}();
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _hellotext = _interopRequireDefault(require("../../hellotext"));
|
|
8
|
+
var _core = require("../../core");
|
|
9
|
+
var _response = require("../response");
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
12
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
13
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
14
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
15
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
16
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
17
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
18
|
+
var WebChatMessagesAPI = /*#__PURE__*/function () {
|
|
19
|
+
function WebChatMessagesAPI(webChatId) {
|
|
20
|
+
_classCallCheck(this, WebChatMessagesAPI);
|
|
21
|
+
this.webChatId = webChatId;
|
|
22
|
+
}
|
|
23
|
+
_createClass(WebChatMessagesAPI, [{
|
|
24
|
+
key: "index",
|
|
25
|
+
value: function () {
|
|
26
|
+
var _index = _asyncToGenerator(function* (params) {
|
|
27
|
+
var url = new URL(this.url);
|
|
28
|
+
Object.entries(params).forEach(_ref => {
|
|
29
|
+
var [key, value] = _ref;
|
|
30
|
+
url.searchParams.append(key, value);
|
|
31
|
+
});
|
|
32
|
+
return yield fetch(url, {
|
|
33
|
+
method: 'GET',
|
|
34
|
+
headers: _hellotext.default.headers
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
function index(_x) {
|
|
38
|
+
return _index.apply(this, arguments);
|
|
39
|
+
}
|
|
40
|
+
return index;
|
|
41
|
+
}()
|
|
42
|
+
}, {
|
|
43
|
+
key: "create",
|
|
44
|
+
value: function () {
|
|
45
|
+
var _create = _asyncToGenerator(function* (formData) {
|
|
46
|
+
var response = yield fetch(this.url, {
|
|
47
|
+
method: 'POST',
|
|
48
|
+
headers: {
|
|
49
|
+
Authorization: "Bearer ".concat(_hellotext.default.business.id)
|
|
50
|
+
},
|
|
51
|
+
body: formData
|
|
52
|
+
});
|
|
53
|
+
return new _response.Response(response.ok, response);
|
|
54
|
+
});
|
|
55
|
+
function create(_x2) {
|
|
56
|
+
return _create.apply(this, arguments);
|
|
57
|
+
}
|
|
58
|
+
return create;
|
|
59
|
+
}()
|
|
60
|
+
}, {
|
|
61
|
+
key: "url",
|
|
62
|
+
get: function get() {
|
|
63
|
+
return WebChatMessagesAPI.endpoint.replace(':id', this.webChatId);
|
|
64
|
+
}
|
|
65
|
+
}], [{
|
|
66
|
+
key: "endpoint",
|
|
67
|
+
get: function get() {
|
|
68
|
+
return _core.Configuration.endpoint("public/webchats/:id/messages");
|
|
69
|
+
}
|
|
70
|
+
}]);
|
|
71
|
+
return WebChatMessagesAPI;
|
|
72
|
+
}();
|
|
73
|
+
var _default = WebChatMessagesAPI;
|
|
74
|
+
exports.default = _default;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _hellotext = _interopRequireDefault(require("../hellotext"));
|
|
8
|
+
var _core = require("../core");
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
11
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
12
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
13
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
14
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
15
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
16
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
17
|
+
var WebChatsAPI = /*#__PURE__*/function () {
|
|
18
|
+
function WebChatsAPI() {
|
|
19
|
+
_classCallCheck(this, WebChatsAPI);
|
|
20
|
+
}
|
|
21
|
+
_createClass(WebChatsAPI, null, [{
|
|
22
|
+
key: "endpoint",
|
|
23
|
+
get: function get() {
|
|
24
|
+
return _core.Configuration.endpoint('public/webchats');
|
|
25
|
+
}
|
|
26
|
+
}, {
|
|
27
|
+
key: "get",
|
|
28
|
+
value: function () {
|
|
29
|
+
var _get = _asyncToGenerator(function* (id) {
|
|
30
|
+
var url = new URL("".concat(this.endpoint, "/").concat(id));
|
|
31
|
+
url.searchParams.append('session', _hellotext.default.session);
|
|
32
|
+
Object.entries(_core.Configuration.webChat.style).forEach(_ref => {
|
|
33
|
+
var [key, value] = _ref;
|
|
34
|
+
url.searchParams.append("style[".concat(key, "]"), value);
|
|
35
|
+
});
|
|
36
|
+
url.searchParams.append('placement', _core.Configuration.webChat.placement);
|
|
37
|
+
var response = yield fetch(url, {
|
|
38
|
+
method: 'GET',
|
|
39
|
+
headers: _hellotext.default.headers
|
|
40
|
+
});
|
|
41
|
+
var htmlText = yield response.text();
|
|
42
|
+
return new DOMParser().parseFromString(htmlText, "text/html").querySelector('article');
|
|
43
|
+
});
|
|
44
|
+
function get(_x) {
|
|
45
|
+
return _get.apply(this, arguments);
|
|
46
|
+
}
|
|
47
|
+
return get;
|
|
48
|
+
}()
|
|
49
|
+
}]);
|
|
50
|
+
return WebChatsAPI;
|
|
51
|
+
}();
|
|
52
|
+
var _default = WebChatsAPI;
|
|
53
|
+
exports.default = _default;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _hellotext = _interopRequireDefault(require("../../hellotext"));
|
|
8
|
+
var _core = require("../../core");
|
|
9
|
+
var _response = require("../response");
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
12
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
13
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
14
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
15
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
16
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
17
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
18
|
+
var WebchatMessagesAPI = /*#__PURE__*/function () {
|
|
19
|
+
function WebchatMessagesAPI(webchatId) {
|
|
20
|
+
_classCallCheck(this, WebchatMessagesAPI);
|
|
21
|
+
this.webchatId = webchatId;
|
|
22
|
+
}
|
|
23
|
+
_createClass(WebchatMessagesAPI, [{
|
|
24
|
+
key: "index",
|
|
25
|
+
value: function () {
|
|
26
|
+
var _index = _asyncToGenerator(function* (params) {
|
|
27
|
+
var url = new URL(this.url);
|
|
28
|
+
Object.entries(params).forEach(_ref => {
|
|
29
|
+
var [key, value] = _ref;
|
|
30
|
+
url.searchParams.append(key, value);
|
|
31
|
+
});
|
|
32
|
+
return yield fetch(url, {
|
|
33
|
+
method: 'GET',
|
|
34
|
+
headers: _hellotext.default.headers
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
function index(_x) {
|
|
38
|
+
return _index.apply(this, arguments);
|
|
39
|
+
}
|
|
40
|
+
return index;
|
|
41
|
+
}()
|
|
42
|
+
}, {
|
|
43
|
+
key: "create",
|
|
44
|
+
value: function () {
|
|
45
|
+
var _create = _asyncToGenerator(function* (formData) {
|
|
46
|
+
var response = yield fetch(this.url, {
|
|
47
|
+
method: 'POST',
|
|
48
|
+
headers: {
|
|
49
|
+
Authorization: "Bearer ".concat(_hellotext.default.business.id)
|
|
50
|
+
},
|
|
51
|
+
body: formData
|
|
52
|
+
});
|
|
53
|
+
return new _response.Response(response.ok, response);
|
|
54
|
+
});
|
|
55
|
+
function create(_x2) {
|
|
56
|
+
return _create.apply(this, arguments);
|
|
57
|
+
}
|
|
58
|
+
return create;
|
|
59
|
+
}()
|
|
60
|
+
}, {
|
|
61
|
+
key: "markAsSeen",
|
|
62
|
+
value: function markAsSeen() {
|
|
63
|
+
fetch(this.url + '/seen', {
|
|
64
|
+
method: 'PATCH',
|
|
65
|
+
headers: _hellotext.default.headers,
|
|
66
|
+
body: JSON.stringify({
|
|
67
|
+
session: _hellotext.default.session
|
|
68
|
+
})
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}, {
|
|
72
|
+
key: "url",
|
|
73
|
+
get: function get() {
|
|
74
|
+
return WebchatMessagesAPI.endpoint.replace(':id', this.webchatId);
|
|
75
|
+
}
|
|
76
|
+
}], [{
|
|
77
|
+
key: "endpoint",
|
|
78
|
+
get: function get() {
|
|
79
|
+
return _core.Configuration.endpoint("public/webchats/:id/messages");
|
|
80
|
+
}
|
|
81
|
+
}]);
|
|
82
|
+
return WebchatMessagesAPI;
|
|
83
|
+
}();
|
|
84
|
+
var _default = WebchatMessagesAPI;
|
|
85
|
+
exports.default = _default;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _hellotext = _interopRequireDefault(require("../hellotext"));
|
|
8
|
+
var _core = require("../core");
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
11
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
12
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
13
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
14
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
15
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
16
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
17
|
+
var WebchatsAPI = /*#__PURE__*/function () {
|
|
18
|
+
function WebchatsAPI() {
|
|
19
|
+
_classCallCheck(this, WebchatsAPI);
|
|
20
|
+
}
|
|
21
|
+
_createClass(WebchatsAPI, null, [{
|
|
22
|
+
key: "endpoint",
|
|
23
|
+
get: function get() {
|
|
24
|
+
return _core.Configuration.endpoint('public/webchats');
|
|
25
|
+
}
|
|
26
|
+
}, {
|
|
27
|
+
key: "get",
|
|
28
|
+
value: function () {
|
|
29
|
+
var _get = _asyncToGenerator(function* (id) {
|
|
30
|
+
var url = new URL("".concat(this.endpoint, "/").concat(id));
|
|
31
|
+
url.searchParams.append('session', _hellotext.default.session);
|
|
32
|
+
Object.entries(_core.Configuration.webchat.style).forEach(_ref => {
|
|
33
|
+
var [key, value] = _ref;
|
|
34
|
+
url.searchParams.append("style[".concat(key, "]"), value);
|
|
35
|
+
});
|
|
36
|
+
url.searchParams.append('placement', _core.Configuration.webchat.placement);
|
|
37
|
+
var response = yield fetch(url, {
|
|
38
|
+
method: 'GET',
|
|
39
|
+
headers: _hellotext.default.headers
|
|
40
|
+
});
|
|
41
|
+
var htmlText = yield response.text();
|
|
42
|
+
return new DOMParser().parseFromString(htmlText, "text/html").querySelector('article');
|
|
43
|
+
});
|
|
44
|
+
function get(_x) {
|
|
45
|
+
return _get.apply(this, arguments);
|
|
46
|
+
}
|
|
47
|
+
return get;
|
|
48
|
+
}()
|
|
49
|
+
}]);
|
|
50
|
+
return WebchatsAPI;
|
|
51
|
+
}();
|
|
52
|
+
var _default = WebchatsAPI;
|
|
53
|
+
exports.default = _default;
|
|
@@ -31,7 +31,8 @@ var LogoBuilder = /*#__PURE__*/function () {
|
|
|
31
31
|
}();
|
|
32
32
|
exports.LogoBuilder = LogoBuilder;
|
|
33
33
|
function _template2() {
|
|
34
|
-
|
|
34
|
+
var url = "https://www.hellotext.com?hello_session=".concat(_hellotext.default.session);
|
|
35
|
+
return "\n <div data-logo-container>\n <small>".concat(_hellotext.default.business.locale.white_label.powered_by, "</small>\n \n <a href=\"").concat(url, "\" rel=\"noreferrer\" target=\"_blank\">\n <svg data-hello-brand viewBox=\"0 0 224 43\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <title>Hellotext</title>\n <path d=\"M28.2760919,19.3224299 L28.2760919,31.1946615 C28.2760919,32.2088722 27.5005873,32.9844452 26.4864658,32.9844452 L21.0579334,32.9844452 C20.043812,32.9844452 19.2683073,32.2088722 19.2683073,31.1946615 L19.2683073,19.9786839 C19.2683073,16.7570733 17.4190271,14.7883113 14.4959712,14.7883113 C11.0360274,14.7883113 8.76916774,17.11503 8.76916774,21.1122135 L8.76916774,31.3139804 C8.76916774,32.3281911 7.99366311,33.1037641 6.97954167,33.1037641 L1.78962607,33.1037641 C0.77550463,33.1037641 0,32.3281911 0,31.3139804 L0,3.45301476 C0,2.43880402 0.77550463,1.6632311 1.78962607,1.6632311 L6.97954167,1.6632311 C7.99366311,1.6632311 8.76916774,2.43880402 8.76916774,3.45301476 L8.76916774,9.06100356 L8.11297151,16.3991166 L8.70951354,16.458776 C9.78328918,11.6860196 13.5415039,8.52406846 18.4331485,8.52406846 C24.3389145,8.52406846 28.2760919,12.8195492 28.2760919,19.3224299 Z M61.1455574,26.3622456 C58.9980061,30.7173858 53.6291279,33.5213803 47.0671656,33.5213803 C37.9997269,33.5213803 31.4377646,28.2116887 31.4377646,20.7542568 C31.4377646,13.6547816 37.2838764,8.52406846 46.0530442,8.52406846 C53.7484363,8.52406846 59.1769687,12.4615925 59.8928191,18.8451542 C60.0121275,19.9190244 59.1769687,20.8735757 58.103193,20.8735757 L40.1472781,20.8735757 C40.4455492,24.8110998 43.1299883,27.2571374 47.186474,27.2571374 C50.2288383,27.2571374 52.8536232,25.7656511 54.1660157,23.4389323 C54.5835951,22.6633594 55.5380623,22.3054026 56.3732212,22.6036999 L60.1314359,23.9758674 C61.0859032,24.2741647 61.622791,25.4076943 61.1455574,26.3622456 Z M40.5648576,17.3536679 L50.706072,17.2343489 C50.0498757,14.7286518 48.3795581,13.5354627 45.8740816,13.5354627 C43.3089509,13.5354627 41.4000164,14.9672896 40.5648576,17.3536679 Z M120.143563,20.9928946 C120.143563,28.2116887 113.641255,33.4617208 104.693125,33.4617208 C95.8046489,33.4617208 89.361995,28.2116887 89.361995,20.9928946 C89.361995,13.7741005 95.8046489,8.52406846 104.693125,8.52406846 C113.641255,8.52406846 120.143563,13.7741005 120.143563,20.9928946 Z M111.076125,21.1122135 C111.076125,17.2940084 108.45134,14.7883113 104.633471,14.7883113 C100.93491,14.7883113 98.3697796,17.2940084 98.3697796,20.9332352 C98.3697796,24.7514403 100.994564,27.2571374 104.812433,27.2571374 C108.570648,27.2571374 111.076125,24.7514403 111.076125,21.1122135 Z M141.559422,26.8395213 C141.261151,25.5866727 139.82945,25.0497376 138.815329,25.8253105 C137.443282,26.8395213 136.190544,27.2571374 134.99746,27.2571374 C132.909563,27.2571374 131.835787,26.0042889 131.835787,23.796889 L131.835787,13.9530789 L139.471525,13.9530789 C140.24703,13.9530789 140.903226,13.2968249 140.903226,12.521252 L140.903226,10.4928305 C140.903226,9.71725757 140.24703,9.06100356 139.471525,9.06100356 L131.835787,9.06100356 L131.835787,3.45301476 C131.835787,2.43880402 131.060282,1.6632311 130.046161,1.6632311 L125.214171,1.6632311 C124.200049,1.6632311 123.424545,2.43880402 123.424545,3.45301476 L123.424545,9.06100356 L123.424545,13.9530789 L123.424545,24.7514403 C123.424545,30.2401102 127.182759,33.5213803 133.565759,33.5213803 C136.727432,33.5213803 139.471525,32.6861479 141.499768,31.0753426 C142.036656,30.6577264 142.275272,29.9418129 142.09631,29.2855589 L141.559422,26.8395213 Z M173.414766,26.3622456 C171.267215,30.7173858 165.898337,33.5213803 159.336374,33.5213803 C150.268936,33.5213803 143.706973,28.2116887 143.706973,20.7542568 C143.706973,13.6547816 149.553085,8.52406846 158.322253,8.52406846 C166.017645,8.52406846 171.446177,12.4615925 172.162028,18.8451542 C172.281336,19.9190244 171.446177,20.8735757 170.372402,20.8735757 L152.416487,20.8735757 C152.714758,24.8110998 155.399197,27.2571374 159.455683,27.2571374 C162.498047,27.2571374 165.122832,25.7656511 166.435224,23.4389323 C166.852804,22.6633594 167.807271,22.3054026 168.64243,22.6036999 L172.400645,23.9758674 C173.414766,24.2741647 173.892,25.4076943 173.414766,26.3622456 Z M152.834066,17.3536679 L162.975281,17.2343489 C162.319084,14.7286518 160.648767,13.5354627 158.14329,13.5354627 C155.637814,13.5354627 153.669225,14.9672896 152.834066,17.3536679 Z M192.862036,20.8139163 L201.094316,12.0439763 C202.168092,10.9104467 201.332933,9.00134411 199.781923,9.00134411 L194.711316,9.00134411 C194.174428,9.00134411 193.637541,9.23998193 193.279615,9.71725757 L188.507279,15.8621815 L183.734943,9.71725757 C183.377018,9.29964138 182.899784,9.00134411 182.303242,9.00134411 L177.113327,9.00134411 C175.562317,9.00134411 174.727159,10.8507872 175.800934,12.0439763 L184.092868,20.8735757 L175.502663,30.0014724 C174.428888,31.135002 175.204392,33.0441046 176.815056,33.0441046 L181.945317,33.0441046 C182.482205,33.0441046 183.019093,32.8054668 183.377018,32.3878506 L188.447625,25.9446294 L193.577886,32.3878506 C193.935812,32.8054668 194.413045,33.0441046 194.949933,33.0441046 L200.139849,33.0441046 C201.690858,33.0441046 202.526017,31.1946615 201.452241,30.0611318 L192.862036,20.8139163 Z M223.941875,29.2258995 L223.345333,26.8395213 C223.047062,25.5866727 221.615362,25.0497376 220.60124,25.8253105 C219.229193,26.8395213 217.976455,27.2571374 216.783371,27.2571374 C214.695474,27.2571374 213.621698,26.0042889 213.621698,23.796889 L213.621698,13.9530789 L221.257436,13.9530789 C222.032941,13.9530789 222.689137,13.2968249 222.689137,12.521252 L222.689137,10.4928305 C222.689137,9.71725757 222.032941,9.06100356 221.257436,9.06100356 L213.621698,9.06100356 L213.621698,3.45301476 C213.621698,2.43880402 212.846194,1.6632311 211.832072,1.6632311 L207.000082,1.6632311 C205.985961,1.6632311 205.210456,2.43880402 205.210456,3.45301476 L205.210456,9.06100356 L205.210456,13.9530789 L205.210456,24.7514403 C205.210456,30.2401102 208.968671,33.5213803 215.35167,33.5213803 C218.513343,33.5213803 221.257436,32.6861479 223.285679,31.0753426 C223.882221,30.5980669 224.120838,29.8821535 223.941875,29.2258995 Z M77.6697714,6.01837134 C78.2663134,5.30245788 78.2663134,4.22858768 77.6101172,3.57233367 L74.5677529,0.529701449 C73.8519024,-0.186212015 72.6588184,-0.186212015 71.942968,0.589360904 C61.3841742,12.4615925 61.3841742,30.5384075 71.942968,42.4106391 C72.5991642,43.186212 73.8519024,43.186212 74.5677529,42.4702986 L77.6101172,39.4276663 C78.2663134,38.7714123 78.3259676,37.6975421 77.6697714,36.9816287 C69.9147251,28.1520293 69.9147251,14.8479707 77.6697714,6.01837134 Z M87.1547896,10.6718089 L84.1124252,7.62917663 C83.3965748,6.91326317 82.1438366,6.91326317 81.4876403,7.74849554 C78.2663134,11.6263601 76.4766873,16.458776 76.4766873,21.5298297 C76.4766873,26.6008834 78.2663134,31.4332993 81.4876403,35.3111639 C82.1438366,36.0867368 83.3965748,36.1463963 84.1124252,35.4304828 L87.1547896,32.3878506 C87.8109858,31.7315966 87.87064,30.7173858 87.3337522,30.0611318 C85.4248177,27.6747536 84.351042,24.6917809 84.351042,21.5894892 C84.351042,18.4871975 85.3651635,15.5042247 87.3337522,13.1178465 C87.87064,12.3422736 87.8109858,11.3280629 87.1547896,10.6718089 Z\" id=\"hellotext\" fill=\"currentColor\"></path>\n </svg>\n </a>\n </div>\n ");
|
|
35
36
|
}
|
|
36
37
|
Object.defineProperty(LogoBuilder, _template, {
|
|
37
38
|
value: _template2
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
8
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
9
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
10
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
11
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
12
|
+
var ApplicationChannel = /*#__PURE__*/function () {
|
|
13
|
+
function ApplicationChannel() {
|
|
14
|
+
_classCallCheck(this, ApplicationChannel);
|
|
15
|
+
}
|
|
16
|
+
_createClass(ApplicationChannel, [{
|
|
17
|
+
key: "send",
|
|
18
|
+
value: function send(_ref) {
|
|
19
|
+
var {
|
|
20
|
+
command,
|
|
21
|
+
identifier
|
|
22
|
+
} = _ref;
|
|
23
|
+
var data = {
|
|
24
|
+
command,
|
|
25
|
+
identifier: JSON.stringify(identifier)
|
|
26
|
+
};
|
|
27
|
+
if (this.webSocket.readyState === WebSocket.OPEN) {
|
|
28
|
+
this.webSocket.send(JSON.stringify(data));
|
|
29
|
+
} else {
|
|
30
|
+
this.webSocket.addEventListener('open', () => {
|
|
31
|
+
this.webSocket.send(JSON.stringify(data));
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}, {
|
|
36
|
+
key: "onMessage",
|
|
37
|
+
value: function onMessage(callback) {
|
|
38
|
+
this.webSocket.addEventListener('message', event => {
|
|
39
|
+
var data = JSON.parse(event.data);
|
|
40
|
+
var {
|
|
41
|
+
type,
|
|
42
|
+
message
|
|
43
|
+
} = data;
|
|
44
|
+
if (this.ignoredEvents.includes(type)) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
callback(message);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}, {
|
|
51
|
+
key: "webSocket",
|
|
52
|
+
get: function get() {
|
|
53
|
+
if (!ApplicationChannel.webSocket) {
|
|
54
|
+
return ApplicationChannel.webSocket = new WebSocket("ws://localhost:3000/cable");
|
|
55
|
+
}
|
|
56
|
+
return ApplicationChannel.webSocket;
|
|
57
|
+
}
|
|
58
|
+
}, {
|
|
59
|
+
key: "ignoredEvents",
|
|
60
|
+
get: function get() {
|
|
61
|
+
return ['ping', 'confirm_subscription', 'welcome'];
|
|
62
|
+
}
|
|
63
|
+
}]);
|
|
64
|
+
return ApplicationChannel;
|
|
65
|
+
}();
|
|
66
|
+
ApplicationChannel.webSocket = void 0;
|
|
67
|
+
var _default = ApplicationChannel;
|
|
68
|
+
exports.default = _default;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _application_channel = _interopRequireDefault(require("./application_channel"));
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
10
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
11
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
12
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
13
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
14
|
+
function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
|
|
15
|
+
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
|
16
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
17
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
18
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
19
|
+
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
20
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
21
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
22
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
23
|
+
var WebChatChannel = /*#__PURE__*/function (_ApplicationChannel) {
|
|
24
|
+
_inherits(WebChatChannel, _ApplicationChannel);
|
|
25
|
+
var _super = _createSuper(WebChatChannel);
|
|
26
|
+
function WebChatChannel(id, session) {
|
|
27
|
+
var _this;
|
|
28
|
+
_classCallCheck(this, WebChatChannel);
|
|
29
|
+
_this = _super.call(this);
|
|
30
|
+
_this.id = id;
|
|
31
|
+
_this.session = session;
|
|
32
|
+
_this.subscribe();
|
|
33
|
+
return _this;
|
|
34
|
+
}
|
|
35
|
+
_createClass(WebChatChannel, [{
|
|
36
|
+
key: "subscribe",
|
|
37
|
+
value: function subscribe() {
|
|
38
|
+
var params = {
|
|
39
|
+
channel: "WebChatChannel",
|
|
40
|
+
id: this.id,
|
|
41
|
+
session: this.session
|
|
42
|
+
};
|
|
43
|
+
this.send({
|
|
44
|
+
command: 'subscribe',
|
|
45
|
+
identifier: params
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}, {
|
|
49
|
+
key: "unsubscribe",
|
|
50
|
+
value: function unsubscribe() {
|
|
51
|
+
var params = {
|
|
52
|
+
channel: "WebChatChannel",
|
|
53
|
+
id: this.id,
|
|
54
|
+
session: this.session
|
|
55
|
+
};
|
|
56
|
+
this.send({
|
|
57
|
+
command: 'unsubscribe',
|
|
58
|
+
identifier: params
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}, {
|
|
62
|
+
key: "onMessage",
|
|
63
|
+
value: function onMessage(callback) {
|
|
64
|
+
_get(_getPrototypeOf(WebChatChannel.prototype), "onMessage", this).call(this, message => {
|
|
65
|
+
if (message.type !== 'message') return;
|
|
66
|
+
callback(message);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}, {
|
|
70
|
+
key: "onConversationAssignment",
|
|
71
|
+
value: function onConversationAssignment(callback) {
|
|
72
|
+
_get(_getPrototypeOf(WebChatChannel.prototype), "onMessage", this).call(this, message => {
|
|
73
|
+
if (message.type === 'conversation.assigned') {
|
|
74
|
+
callback(message);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}, {
|
|
79
|
+
key: "onAgentOnline",
|
|
80
|
+
value: function onAgentOnline(callback) {
|
|
81
|
+
_get(_getPrototypeOf(WebChatChannel.prototype), "onMessage", this).call(this, message => {
|
|
82
|
+
if (message.type === 'agent_is_online') {
|
|
83
|
+
callback(message);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}, {
|
|
88
|
+
key: "updateSubscription",
|
|
89
|
+
value: function updateSubscription() {
|
|
90
|
+
this.unsubscribe();
|
|
91
|
+
this.subscribe();
|
|
92
|
+
}
|
|
93
|
+
}]);
|
|
94
|
+
return WebChatChannel;
|
|
95
|
+
}(_application_channel.default);
|
|
96
|
+
var _default = WebChatChannel;
|
|
97
|
+
exports.default = _default;
|