@hellotext/hellotext 2.5.7 → 2.5.8
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/README.md +0 -25
- package/dist/hellotext.js +1 -1
- package/index.d.ts +0 -6
- package/lib/api/acks.cjs +17 -31
- package/lib/api/acks.js +17 -42
- package/lib/api/businesses.cjs +14 -28
- package/lib/api/businesses.js +13 -36
- package/lib/api/events.cjs +26 -40
- package/lib/api/events.js +28 -52
- package/lib/api/forms.cjs +24 -40
- package/lib/api/forms.js +24 -57
- package/lib/api/identifications.cjs +15 -29
- package/lib/api/identifications.js +15 -40
- package/lib/api/index.cjs +25 -51
- package/lib/api/index.js +27 -54
- package/lib/api/push/identities.cjs +30 -46
- package/lib/api/push/identities.js +30 -63
- package/lib/api/response.cjs +30 -52
- package/lib/api/response.js +31 -60
- package/lib/api/submissions.cjs +18 -34
- package/lib/api/submissions.js +18 -48
- package/lib/api/webchat/messages.cjs +44 -64
- package/lib/api/webchat/messages.js +44 -80
- package/lib/api/webchats.cjs +37 -56
- package/lib/api/webchats.js +37 -65
- package/lib/api/whatsapp_widgets.cjs +49 -72
- package/lib/api/whatsapp_widgets.js +48 -91
- package/lib/builders/input_builder.cjs +36 -48
- package/lib/builders/input_builder.js +36 -48
- package/lib/builders/logo_builder.cjs +10 -29
- package/lib/builders/logo_builder.js +20 -28
- package/lib/channels/application_channel.cjs +136 -178
- package/lib/channels/application_channel.js +137 -180
- package/lib/channels/webchat_channel.cjs +125 -170
- package/lib/channels/webchat_channel.js +125 -170
- package/lib/controllers/form_controller.cjs +82 -121
- package/lib/controllers/form_controller.js +82 -130
- package/lib/controllers/message_controller.cjs +211 -282
- package/lib/controllers/message_controller.js +209 -284
- package/lib/controllers/mixins/usePopover.cjs +3 -6
- package/lib/controllers/mixins/usePopover.js +17 -22
- package/lib/controllers/webchat/emoji_picker_controller.cjs +106 -150
- package/lib/controllers/webchat/emoji_picker_controller.js +105 -170
- package/lib/controllers/webchat/useBehaviour.js +5 -5
- package/lib/controllers/webchat/useOpeningSequence.js +6 -6
- package/lib/controllers/webchat/useTeaser.js +9 -9
- package/lib/controllers/webchat_controller.cjs +916 -1088
- package/lib/controllers/webchat_controller.js +926 -1152
- package/lib/core/configuration/forms.cjs +21 -35
- package/lib/core/configuration/forms.js +20 -35
- package/lib/core/configuration/locale.cjs +36 -71
- package/lib/core/configuration/locale.js +36 -70
- package/lib/core/configuration/push.cjs +9 -21
- package/lib/core/configuration/push.js +8 -20
- package/lib/core/configuration/webchat.cjs +142 -182
- package/lib/core/configuration/webchat.js +145 -189
- package/lib/core/configuration/whatsapp.cjs +76 -102
- package/lib/core/configuration/whatsapp.js +76 -105
- package/lib/core/configuration.cjs +60 -78
- package/lib/core/configuration.js +59 -78
- package/lib/core/event.cjs +36 -59
- package/lib/core/event.js +35 -61
- package/lib/core/sanitize_html.js +4 -4
- package/lib/errors/invalid_event.cjs +5 -26
- package/lib/errors/invalid_event.js +5 -26
- package/lib/errors/not_initialized_error.cjs +5 -26
- package/lib/errors/not_initialized_error.js +5 -26
- package/lib/hellotext.cjs +185 -223
- package/lib/hellotext.js +188 -247
- package/lib/index.js +1 -1
- package/lib/models/business.cjs +114 -152
- package/lib/models/business.js +117 -162
- package/lib/models/cookies.cjs +34 -51
- package/lib/models/cookies.js +34 -51
- package/lib/models/fingerprint.cjs +8 -23
- package/lib/models/fingerprint.js +25 -58
- package/lib/models/form.cjs +106 -142
- package/lib/models/form.js +105 -153
- package/lib/models/form_collection.cjs +63 -101
- package/lib/models/form_collection.js +61 -107
- package/lib/models/page.cjs +106 -129
- package/lib/models/page.js +106 -131
- package/lib/models/push.cjs +278 -322
- package/lib/models/push.js +284 -357
- package/lib/models/query.cjs +21 -41
- package/lib/models/query.js +21 -41
- package/lib/models/session.cjs +33 -65
- package/lib/models/session.js +30 -63
- package/lib/models/user.cjs +29 -51
- package/lib/models/user.js +29 -51
- package/lib/models/utm.cjs +15 -27
- package/lib/models/utm.js +17 -32
- package/lib/models/webchat.cjs +52 -76
- package/lib/models/webchat.js +52 -90
- package/lib/models/whatsapp_widget.cjs +41 -59
- package/lib/models/whatsapp_widget.js +41 -73
- package/lib/vanilla.cjs +4 -7
- package/lib/vanilla.js +2 -1
- package/package.json +1 -9
- package/src/index.bundle.js +0 -1
- package/src/vanilla.js +2 -1
- package/styles/index.css +0 -30
package/lib/api/submissions.cjs
CHANGED
|
@@ -8,40 +8,24 @@ var _hellotext = _interopRequireDefault(require("../hellotext"));
|
|
|
8
8
|
var _core = require("../core");
|
|
9
9
|
var _response = require("./response");
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
15
|
-
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); }
|
|
16
|
-
let SubmissionsAPI = /*#__PURE__*/function () {
|
|
17
|
-
function SubmissionsAPI() {
|
|
18
|
-
_classCallCheck(this, SubmissionsAPI);
|
|
11
|
+
class SubmissionsAPI {
|
|
12
|
+
static get endpoint() {
|
|
13
|
+
return _core.Configuration.endpoint('public/submissions');
|
|
19
14
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
key: "verifyOTP",
|
|
36
|
-
value: async function verifyOTP(id, otp) {
|
|
37
|
-
const response = await fetch(`${this.endpoint}/${id}/otps/${otp}/verify`, {
|
|
38
|
-
method: 'POST',
|
|
39
|
-
headers: _hellotext.default.headers
|
|
40
|
-
});
|
|
41
|
-
return new _response.Response(response.ok, response);
|
|
42
|
-
}
|
|
43
|
-
}]);
|
|
44
|
-
return SubmissionsAPI;
|
|
45
|
-
}();
|
|
15
|
+
static async resendOTP(id) {
|
|
16
|
+
const response = await fetch(`${this.endpoint}/${id}/otps`, {
|
|
17
|
+
method: 'POST',
|
|
18
|
+
headers: _hellotext.default.headers
|
|
19
|
+
});
|
|
20
|
+
return new _response.Response(response.ok, response);
|
|
21
|
+
}
|
|
22
|
+
static async verifyOTP(id, otp) {
|
|
23
|
+
const response = await fetch(`${this.endpoint}/${id}/otps/${otp}/verify`, {
|
|
24
|
+
method: 'POST',
|
|
25
|
+
headers: _hellotext.default.headers
|
|
26
|
+
});
|
|
27
|
+
return new _response.Response(response.ok, response);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
46
30
|
var _default = SubmissionsAPI;
|
|
47
31
|
exports.default = _default;
|
package/lib/api/submissions.js
CHANGED
|
@@ -1,53 +1,23 @@
|
|
|
1
|
-
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); } }
|
|
2
|
-
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); }); }; }
|
|
3
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
4
|
-
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); } }
|
|
5
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
6
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
7
|
-
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); }
|
|
8
1
|
import Hellotext from '../hellotext';
|
|
9
2
|
import { Configuration } from '../core';
|
|
10
3
|
import { Response } from './response';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
class SubmissionsAPI {
|
|
5
|
+
static get endpoint() {
|
|
6
|
+
return Configuration.endpoint('public/submissions');
|
|
14
7
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
function resendOTP(_x) {
|
|
31
|
-
return _resendOTP.apply(this, arguments);
|
|
32
|
-
}
|
|
33
|
-
return resendOTP;
|
|
34
|
-
}()
|
|
35
|
-
}, {
|
|
36
|
-
key: "verifyOTP",
|
|
37
|
-
value: function () {
|
|
38
|
-
var _verifyOTP = _asyncToGenerator(function* (id, otp) {
|
|
39
|
-
var response = yield fetch("".concat(this.endpoint, "/").concat(id, "/otps/").concat(otp, "/verify"), {
|
|
40
|
-
method: 'POST',
|
|
41
|
-
headers: Hellotext.headers
|
|
42
|
-
});
|
|
43
|
-
return new Response(response.ok, response);
|
|
44
|
-
});
|
|
45
|
-
function verifyOTP(_x2, _x3) {
|
|
46
|
-
return _verifyOTP.apply(this, arguments);
|
|
47
|
-
}
|
|
48
|
-
return verifyOTP;
|
|
49
|
-
}()
|
|
50
|
-
}]);
|
|
51
|
-
return SubmissionsAPI;
|
|
52
|
-
}();
|
|
8
|
+
static async resendOTP(id) {
|
|
9
|
+
const response = await fetch(`${this.endpoint}/${id}/otps`, {
|
|
10
|
+
method: 'POST',
|
|
11
|
+
headers: Hellotext.headers
|
|
12
|
+
});
|
|
13
|
+
return new Response(response.ok, response);
|
|
14
|
+
}
|
|
15
|
+
static async verifyOTP(id, otp) {
|
|
16
|
+
const response = await fetch(`${this.endpoint}/${id}/otps/${otp}/verify`, {
|
|
17
|
+
method: 'POST',
|
|
18
|
+
headers: Hellotext.headers
|
|
19
|
+
});
|
|
20
|
+
return new Response(response.ok, response);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
53
23
|
export default SubmissionsAPI;
|
|
@@ -8,72 +8,52 @@ var _core = require("../../core");
|
|
|
8
8
|
var _hellotext = _interopRequireDefault(require("../../hellotext"));
|
|
9
9
|
var _response = require("../response");
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
let WebchatMessagesAPI = /*#__PURE__*/function () {
|
|
17
|
-
function WebchatMessagesAPI(webchatId) {
|
|
18
|
-
_classCallCheck(this, WebchatMessagesAPI);
|
|
11
|
+
class WebchatMessagesAPI {
|
|
12
|
+
static get endpoint() {
|
|
13
|
+
return _core.Configuration.endpoint(`public/webchats/:id/messages`);
|
|
14
|
+
}
|
|
15
|
+
constructor(webchatId) {
|
|
19
16
|
this.webchatId = webchatId;
|
|
20
17
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
18
|
+
async index(params) {
|
|
19
|
+
const url = new URL(this.url);
|
|
20
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
21
|
+
url.searchParams.append(key, value);
|
|
22
|
+
});
|
|
23
|
+
return await fetch(url, {
|
|
24
|
+
method: 'GET',
|
|
25
|
+
headers: _hellotext.default.headers
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
catchUp(afterId) {
|
|
29
|
+
return this.index({
|
|
30
|
+
after_id: afterId,
|
|
31
|
+
session: _hellotext.default.session
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
async create(formData) {
|
|
35
|
+
const response = await fetch(this.url, {
|
|
36
|
+
method: 'POST',
|
|
37
|
+
headers: {
|
|
38
|
+
Authorization: `Bearer ${_hellotext.default.business.id}`
|
|
39
|
+
},
|
|
40
|
+
body: formData
|
|
41
|
+
});
|
|
42
|
+
return new _response.Response(response.ok, response);
|
|
43
|
+
}
|
|
44
|
+
markAsSeen(messageId = null) {
|
|
45
|
+
const url = messageId ? this.url + `/${messageId}` : this.url + '/seen';
|
|
46
|
+
fetch(url, {
|
|
47
|
+
method: 'PATCH',
|
|
48
|
+
headers: _hellotext.default.headers,
|
|
49
|
+
body: JSON.stringify({
|
|
38
50
|
session: _hellotext.default.session
|
|
39
|
-
})
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
headers: {
|
|
47
|
-
Authorization: `Bearer ${_hellotext.default.business.id}`
|
|
48
|
-
},
|
|
49
|
-
body: formData
|
|
50
|
-
});
|
|
51
|
-
return new _response.Response(response.ok, response);
|
|
52
|
-
}
|
|
53
|
-
}, {
|
|
54
|
-
key: "markAsSeen",
|
|
55
|
-
value: function markAsSeen(messageId = null) {
|
|
56
|
-
const url = messageId ? this.url + `/${messageId}` : this.url + '/seen';
|
|
57
|
-
fetch(url, {
|
|
58
|
-
method: 'PATCH',
|
|
59
|
-
headers: _hellotext.default.headers,
|
|
60
|
-
body: JSON.stringify({
|
|
61
|
-
session: _hellotext.default.session
|
|
62
|
-
})
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
}, {
|
|
66
|
-
key: "url",
|
|
67
|
-
get: function () {
|
|
68
|
-
return WebchatMessagesAPI.endpoint.replace(':id', this.webchatId);
|
|
69
|
-
}
|
|
70
|
-
}], [{
|
|
71
|
-
key: "endpoint",
|
|
72
|
-
get: function () {
|
|
73
|
-
return _core.Configuration.endpoint(`public/webchats/:id/messages`);
|
|
74
|
-
}
|
|
75
|
-
}]);
|
|
76
|
-
return WebchatMessagesAPI;
|
|
77
|
-
}();
|
|
51
|
+
})
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
get url() {
|
|
55
|
+
return WebchatMessagesAPI.endpoint.replace(':id', this.webchatId);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
78
58
|
var _default = WebchatMessagesAPI;
|
|
79
59
|
exports.default = _default;
|
|
@@ -1,87 +1,51 @@
|
|
|
1
|
-
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); } }
|
|
2
|
-
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); }); }; }
|
|
3
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
4
|
-
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); } }
|
|
5
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
6
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
7
|
-
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); }
|
|
8
1
|
import { Configuration } from '../../core';
|
|
9
2
|
import Hellotext from '../../hellotext';
|
|
10
3
|
import { Response } from '../response';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
class WebchatMessagesAPI {
|
|
5
|
+
static get endpoint() {
|
|
6
|
+
return Configuration.endpoint(`public/webchats/:id/messages`);
|
|
7
|
+
}
|
|
8
|
+
constructor(webchatId) {
|
|
14
9
|
this.webchatId = webchatId;
|
|
15
10
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
value
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
11
|
+
async index(params) {
|
|
12
|
+
const url = new URL(this.url);
|
|
13
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
14
|
+
url.searchParams.append(key, value);
|
|
15
|
+
});
|
|
16
|
+
return await fetch(url, {
|
|
17
|
+
method: 'GET',
|
|
18
|
+
headers: Hellotext.headers
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
catchUp(afterId) {
|
|
22
|
+
return this.index({
|
|
23
|
+
after_id: afterId,
|
|
24
|
+
session: Hellotext.session
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
async create(formData) {
|
|
28
|
+
const response = await fetch(this.url, {
|
|
29
|
+
method: 'POST',
|
|
30
|
+
headers: {
|
|
31
|
+
Authorization: `Bearer ${Hellotext.business.id}`
|
|
32
|
+
},
|
|
33
|
+
body: formData
|
|
34
|
+
});
|
|
35
|
+
return new Response(response.ok, response);
|
|
36
|
+
}
|
|
37
|
+
markAsSeen(messageId = null) {
|
|
38
|
+
const url = messageId ? this.url + `/${messageId}` : this.url + '/seen';
|
|
39
|
+
fetch(url, {
|
|
40
|
+
method: 'PATCH',
|
|
41
|
+
headers: Hellotext.headers,
|
|
42
|
+
body: JSON.stringify({
|
|
40
43
|
session: Hellotext.session
|
|
41
|
-
})
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
method: 'POST',
|
|
49
|
-
headers: {
|
|
50
|
-
Authorization: "Bearer ".concat(Hellotext.business.id)
|
|
51
|
-
},
|
|
52
|
-
body: formData
|
|
53
|
-
});
|
|
54
|
-
return new Response(response.ok, response);
|
|
55
|
-
});
|
|
56
|
-
function create(_x2) {
|
|
57
|
-
return _create.apply(this, arguments);
|
|
58
|
-
}
|
|
59
|
-
return create;
|
|
60
|
-
}()
|
|
61
|
-
}, {
|
|
62
|
-
key: "markAsSeen",
|
|
63
|
-
value: function markAsSeen() {
|
|
64
|
-
var messageId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
65
|
-
var url = messageId ? this.url + "/".concat(messageId) : this.url + '/seen';
|
|
66
|
-
fetch(url, {
|
|
67
|
-
method: 'PATCH',
|
|
68
|
-
headers: Hellotext.headers,
|
|
69
|
-
body: JSON.stringify({
|
|
70
|
-
session: Hellotext.session
|
|
71
|
-
})
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
}, {
|
|
75
|
-
key: "url",
|
|
76
|
-
get: function get() {
|
|
77
|
-
return WebchatMessagesAPI.endpoint.replace(':id', this.webchatId);
|
|
78
|
-
}
|
|
79
|
-
}], [{
|
|
80
|
-
key: "endpoint",
|
|
81
|
-
get: function get() {
|
|
82
|
-
return Configuration.endpoint("public/webchats/:id/messages");
|
|
83
|
-
}
|
|
84
|
-
}]);
|
|
85
|
-
return WebchatMessagesAPI;
|
|
86
|
-
}();
|
|
44
|
+
})
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
get url() {
|
|
48
|
+
return WebchatMessagesAPI.endpoint.replace(':id', this.webchatId);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
87
51
|
export default WebchatMessagesAPI;
|
package/lib/api/webchats.cjs
CHANGED
|
@@ -7,63 +7,44 @@ exports.default = void 0;
|
|
|
7
7
|
var _core = require("../core");
|
|
8
8
|
var _hellotext = _interopRequireDefault(require("../hellotext"));
|
|
9
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
14
|
-
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); }
|
|
15
|
-
let WebchatsAPI = /*#__PURE__*/function () {
|
|
16
|
-
function WebchatsAPI() {
|
|
17
|
-
_classCallCheck(this, WebchatsAPI);
|
|
10
|
+
class WebchatsAPI {
|
|
11
|
+
static get endpoint() {
|
|
12
|
+
return _core.Configuration.endpoint('public/webchats');
|
|
18
13
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
static async get(id) {
|
|
15
|
+
const url = new URL(`${this.endpoint}/${id}`);
|
|
16
|
+
url.searchParams.append('session', _hellotext.default.session);
|
|
17
|
+
url.searchParams.append('locale', _core.Locale.toString());
|
|
18
|
+
Object.entries(_core.Configuration.webchat.style).forEach(([key, value]) => {
|
|
19
|
+
url.searchParams.append(`style[${key}]`, value);
|
|
20
|
+
});
|
|
21
|
+
this.appendWebchatOverrides(url);
|
|
22
|
+
url.searchParams.append('placement', _core.Configuration.webchat.placement);
|
|
23
|
+
const response = await fetch(url, {
|
|
24
|
+
method: 'GET',
|
|
25
|
+
headers: _hellotext.default.headers
|
|
26
|
+
});
|
|
27
|
+
const data = await response.json();
|
|
28
|
+
if (!_hellotext.default.business.data) {
|
|
29
|
+
_hellotext.default.business.setData(data.business);
|
|
30
|
+
_hellotext.default.business.setLocale(data.locale);
|
|
23
31
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
_hellotext.default.business.setData(data.business);
|
|
42
|
-
_hellotext.default.business.setLocale(data.locale);
|
|
43
|
-
}
|
|
44
|
-
return new DOMParser().parseFromString(data.html, 'text/html').querySelector('article');
|
|
45
|
-
}
|
|
46
|
-
}, {
|
|
47
|
-
key: "appendWebchatOverrides",
|
|
48
|
-
value: function appendWebchatOverrides(url) {
|
|
49
|
-
var _appearance$header, _appearance$launcher;
|
|
50
|
-
const {
|
|
51
|
-
appearance,
|
|
52
|
-
whatsapp
|
|
53
|
-
} = _core.Configuration.webchat;
|
|
54
|
-
this.appendIfSupplied(url, 'webchat[appearance][header][name]', (_appearance$header = appearance.header) === null || _appearance$header === void 0 ? void 0 : _appearance$header.name);
|
|
55
|
-
this.appendIfSupplied(url, 'webchat[appearance][launcher][icon_url]', (_appearance$launcher = appearance.launcher) === null || _appearance$launcher === void 0 ? void 0 : _appearance$launcher.iconUrl);
|
|
56
|
-
this.appendIfSupplied(url, 'webchat[handoff][identifier]', whatsapp.number);
|
|
57
|
-
this.appendIfSupplied(url, 'webchat[handoff][restrict_to_channel]', whatsapp.restrictToChannel);
|
|
58
|
-
}
|
|
59
|
-
}, {
|
|
60
|
-
key: "appendIfSupplied",
|
|
61
|
-
value: function appendIfSupplied(url, key, value) {
|
|
62
|
-
if (value === undefined || value === null) return;
|
|
63
|
-
url.searchParams.append(key, String(value));
|
|
64
|
-
}
|
|
65
|
-
}]);
|
|
66
|
-
return WebchatsAPI;
|
|
67
|
-
}();
|
|
32
|
+
return new DOMParser().parseFromString(data.html, 'text/html').querySelector('article');
|
|
33
|
+
}
|
|
34
|
+
static appendWebchatOverrides(url) {
|
|
35
|
+
const {
|
|
36
|
+
appearance,
|
|
37
|
+
whatsapp
|
|
38
|
+
} = _core.Configuration.webchat;
|
|
39
|
+
this.appendIfSupplied(url, 'webchat[appearance][header][name]', appearance.header?.name);
|
|
40
|
+
this.appendIfSupplied(url, 'webchat[appearance][launcher][icon_url]', appearance.launcher?.iconUrl);
|
|
41
|
+
this.appendIfSupplied(url, 'webchat[handoff][identifier]', whatsapp.number);
|
|
42
|
+
this.appendIfSupplied(url, 'webchat[handoff][restrict_to_channel]', whatsapp.restrictToChannel);
|
|
43
|
+
}
|
|
44
|
+
static appendIfSupplied(url, key, value) {
|
|
45
|
+
if (value === undefined || value === null) return;
|
|
46
|
+
url.searchParams.append(key, String(value));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
68
49
|
var _default = WebchatsAPI;
|
|
69
50
|
exports.default = _default;
|
package/lib/api/webchats.js
CHANGED
|
@@ -1,70 +1,42 @@
|
|
|
1
|
-
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); } }
|
|
2
|
-
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); }); }; }
|
|
3
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
4
|
-
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); } }
|
|
5
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
6
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
7
|
-
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); }
|
|
8
1
|
import { Configuration, Locale } from '../core';
|
|
9
2
|
import Hellotext from '../hellotext';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
3
|
+
class WebchatsAPI {
|
|
4
|
+
static get endpoint() {
|
|
5
|
+
return Configuration.endpoint('public/webchats');
|
|
13
6
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
static async get(id) {
|
|
8
|
+
const url = new URL(`${this.endpoint}/${id}`);
|
|
9
|
+
url.searchParams.append('session', Hellotext.session);
|
|
10
|
+
url.searchParams.append('locale', Locale.toString());
|
|
11
|
+
Object.entries(Configuration.webchat.style).forEach(([key, value]) => {
|
|
12
|
+
url.searchParams.append(`style[${key}]`, value);
|
|
13
|
+
});
|
|
14
|
+
this.appendWebchatOverrides(url);
|
|
15
|
+
url.searchParams.append('placement', Configuration.webchat.placement);
|
|
16
|
+
const response = await fetch(url, {
|
|
17
|
+
method: 'GET',
|
|
18
|
+
headers: Hellotext.headers
|
|
19
|
+
});
|
|
20
|
+
const data = await response.json();
|
|
21
|
+
if (!Hellotext.business.data) {
|
|
22
|
+
Hellotext.business.setData(data.business);
|
|
23
|
+
Hellotext.business.setLocale(data.locale);
|
|
18
24
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
var data = yield response.json();
|
|
37
|
-
if (!Hellotext.business.data) {
|
|
38
|
-
Hellotext.business.setData(data.business);
|
|
39
|
-
Hellotext.business.setLocale(data.locale);
|
|
40
|
-
}
|
|
41
|
-
return new DOMParser().parseFromString(data.html, 'text/html').querySelector('article');
|
|
42
|
-
});
|
|
43
|
-
function get(_x) {
|
|
44
|
-
return _get.apply(this, arguments);
|
|
45
|
-
}
|
|
46
|
-
return get;
|
|
47
|
-
}()
|
|
48
|
-
}, {
|
|
49
|
-
key: "appendWebchatOverrides",
|
|
50
|
-
value: function appendWebchatOverrides(url) {
|
|
51
|
-
var _appearance$header, _appearance$launcher;
|
|
52
|
-
var {
|
|
53
|
-
appearance,
|
|
54
|
-
whatsapp
|
|
55
|
-
} = Configuration.webchat;
|
|
56
|
-
this.appendIfSupplied(url, 'webchat[appearance][header][name]', (_appearance$header = appearance.header) === null || _appearance$header === void 0 ? void 0 : _appearance$header.name);
|
|
57
|
-
this.appendIfSupplied(url, 'webchat[appearance][launcher][icon_url]', (_appearance$launcher = appearance.launcher) === null || _appearance$launcher === void 0 ? void 0 : _appearance$launcher.iconUrl);
|
|
58
|
-
this.appendIfSupplied(url, 'webchat[handoff][identifier]', whatsapp.number);
|
|
59
|
-
this.appendIfSupplied(url, 'webchat[handoff][restrict_to_channel]', whatsapp.restrictToChannel);
|
|
60
|
-
}
|
|
61
|
-
}, {
|
|
62
|
-
key: "appendIfSupplied",
|
|
63
|
-
value: function appendIfSupplied(url, key, value) {
|
|
64
|
-
if (value === undefined || value === null) return;
|
|
65
|
-
url.searchParams.append(key, String(value));
|
|
66
|
-
}
|
|
67
|
-
}]);
|
|
68
|
-
return WebchatsAPI;
|
|
69
|
-
}();
|
|
25
|
+
return new DOMParser().parseFromString(data.html, 'text/html').querySelector('article');
|
|
26
|
+
}
|
|
27
|
+
static appendWebchatOverrides(url) {
|
|
28
|
+
const {
|
|
29
|
+
appearance,
|
|
30
|
+
whatsapp
|
|
31
|
+
} = Configuration.webchat;
|
|
32
|
+
this.appendIfSupplied(url, 'webchat[appearance][header][name]', appearance.header?.name);
|
|
33
|
+
this.appendIfSupplied(url, 'webchat[appearance][launcher][icon_url]', appearance.launcher?.iconUrl);
|
|
34
|
+
this.appendIfSupplied(url, 'webchat[handoff][identifier]', whatsapp.number);
|
|
35
|
+
this.appendIfSupplied(url, 'webchat[handoff][restrict_to_channel]', whatsapp.restrictToChannel);
|
|
36
|
+
}
|
|
37
|
+
static appendIfSupplied(url, key, value) {
|
|
38
|
+
if (value === undefined || value === null) return;
|
|
39
|
+
url.searchParams.append(key, String(value));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
70
42
|
export default WebchatsAPI;
|