@hellotext/hellotext 2.4.53 → 2.5.1
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 +1 -0
- package/dist/hellotext.js +1 -1
- package/dist/webchat-emoji-en.js +1 -1
- package/dist/webchat-emoji-es.js +1 -1
- package/dist/webchat-emoji.js +1 -1
- package/index.d.ts +18 -0
- package/lib/api/index.cjs +6 -0
- package/lib/api/index.js +6 -0
- package/lib/api/whatsapp_widgets.cjs +87 -0
- package/lib/api/whatsapp_widgets.js +99 -0
- package/lib/core/configuration/whatsapp.cjs +150 -0
- package/lib/core/configuration/whatsapp.js +147 -0
- package/lib/core/configuration.cjs +6 -1
- package/lib/core/configuration.js +5 -0
- package/lib/core/index.cjs +7 -0
- package/lib/core/index.js +1 -0
- package/lib/hellotext.cjs +11 -0
- package/lib/hellotext.js +12 -1
- package/lib/models/index.cjs +8 -1
- package/lib/models/index.js +2 -1
- package/lib/models/webchat.cjs +10 -0
- package/lib/models/webchat.js +10 -0
- package/lib/models/whatsapp_widget.cjs +77 -0
- package/lib/models/whatsapp_widget.js +84 -0
- package/package.json +6 -3
- package/src/api/index.js +5 -0
- package/src/api/whatsapp_widgets.js +71 -0
- package/src/core/configuration/whatsapp.js +143 -0
- package/src/core/configuration.js +5 -0
- package/src/core/index.js +1 -0
- package/src/hellotext.js +18 -0
- package/src/models/index.js +1 -0
- package/src/models/webchat.js +11 -0
- package/src/models/whatsapp_widget.js +68 -0
|
@@ -0,0 +1,99 @@
|
|
|
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
|
+
import { Configuration, Locale } from '../core';
|
|
9
|
+
import Hellotext from '../hellotext';
|
|
10
|
+
var WhatsAppWidgetsAPI = /*#__PURE__*/function () {
|
|
11
|
+
function WhatsAppWidgetsAPI() {
|
|
12
|
+
_classCallCheck(this, WhatsAppWidgetsAPI);
|
|
13
|
+
}
|
|
14
|
+
_createClass(WhatsAppWidgetsAPI, null, [{
|
|
15
|
+
key: "endpoint",
|
|
16
|
+
get: function get() {
|
|
17
|
+
return Configuration.endpoint('public/widgets/whatsapp');
|
|
18
|
+
}
|
|
19
|
+
}, {
|
|
20
|
+
key: "get",
|
|
21
|
+
value: function () {
|
|
22
|
+
var _get = _asyncToGenerator(function* (id) {
|
|
23
|
+
var url = new URL("".concat(this.endpoint, "/").concat(id));
|
|
24
|
+
url.searchParams.append('locale', Locale.toString());
|
|
25
|
+
url.searchParams.append('placement', Configuration.whatsapp.placement);
|
|
26
|
+
this.appendWhatsAppOverrides(url);
|
|
27
|
+
var response = yield this.fetchWidget(url);
|
|
28
|
+
if (!response.ok) return null;
|
|
29
|
+
var data = yield this.parseWidgetResponse(response);
|
|
30
|
+
if (!data) return null;
|
|
31
|
+
if (!Hellotext.business.data) {
|
|
32
|
+
Hellotext.business.setData(data.business);
|
|
33
|
+
Hellotext.business.setLocale(data.locale);
|
|
34
|
+
}
|
|
35
|
+
return new DOMParser().parseFromString(data.html, 'text/html').querySelector('article');
|
|
36
|
+
});
|
|
37
|
+
function get(_x) {
|
|
38
|
+
return _get.apply(this, arguments);
|
|
39
|
+
}
|
|
40
|
+
return get;
|
|
41
|
+
}()
|
|
42
|
+
}, {
|
|
43
|
+
key: "appendWhatsAppOverrides",
|
|
44
|
+
value: function appendWhatsAppOverrides(url) {
|
|
45
|
+
var _appearance$launcher;
|
|
46
|
+
var {
|
|
47
|
+
appearance,
|
|
48
|
+
body,
|
|
49
|
+
number
|
|
50
|
+
} = Configuration.whatsapp;
|
|
51
|
+
this.appendIfSupplied(url, 'whatsapp[appearance][launcher][icon_url]', (_appearance$launcher = appearance.launcher) === null || _appearance$launcher === void 0 ? void 0 : _appearance$launcher.iconUrl);
|
|
52
|
+
this.appendIfSupplied(url, 'whatsapp[number]', number);
|
|
53
|
+
this.appendIfSupplied(url, 'whatsapp[body]', body);
|
|
54
|
+
}
|
|
55
|
+
}, {
|
|
56
|
+
key: "appendIfSupplied",
|
|
57
|
+
value: function appendIfSupplied(url, key, value) {
|
|
58
|
+
if (value === undefined || value === null) return;
|
|
59
|
+
url.searchParams.append(key, String(value));
|
|
60
|
+
}
|
|
61
|
+
}, {
|
|
62
|
+
key: "fetchWidget",
|
|
63
|
+
value: function () {
|
|
64
|
+
var _fetchWidget = _asyncToGenerator(function* (url) {
|
|
65
|
+
try {
|
|
66
|
+
return yield fetch(url, {
|
|
67
|
+
method: 'GET',
|
|
68
|
+
headers: Hellotext.headers
|
|
69
|
+
});
|
|
70
|
+
} catch (_) {
|
|
71
|
+
return {
|
|
72
|
+
ok: false
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
function fetchWidget(_x2) {
|
|
77
|
+
return _fetchWidget.apply(this, arguments);
|
|
78
|
+
}
|
|
79
|
+
return fetchWidget;
|
|
80
|
+
}()
|
|
81
|
+
}, {
|
|
82
|
+
key: "parseWidgetResponse",
|
|
83
|
+
value: function () {
|
|
84
|
+
var _parseWidgetResponse = _asyncToGenerator(function* (response) {
|
|
85
|
+
try {
|
|
86
|
+
return yield response.json();
|
|
87
|
+
} catch (_) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
function parseWidgetResponse(_x3) {
|
|
92
|
+
return _parseWidgetResponse.apply(this, arguments);
|
|
93
|
+
}
|
|
94
|
+
return parseWidgetResponse;
|
|
95
|
+
}()
|
|
96
|
+
}]);
|
|
97
|
+
return WhatsAppWidgetsAPI;
|
|
98
|
+
}();
|
|
99
|
+
export default WhatsAppWidgetsAPI;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.WhatsApp = 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
|
+
/**
|
|
13
|
+
* @typedef {'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'} Placement
|
|
14
|
+
* @description Valid placements for the WhatsApp widget.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @enum {Placement}
|
|
19
|
+
*/
|
|
20
|
+
const placements = {
|
|
21
|
+
TOP_LEFT: 'top-left',
|
|
22
|
+
TOP_RIGHT: 'top-right',
|
|
23
|
+
BOTTOM_LEFT: 'bottom-left',
|
|
24
|
+
BOTTOM_RIGHT: 'bottom-right'
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @typedef {Object} WhatsAppWidgetAppearance
|
|
29
|
+
* @property {Object} [launcher] - Launcher appearance overrides.
|
|
30
|
+
* @property {string} [launcher.iconUrl] - Image URL used for the launcher icon.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @class WhatsApp
|
|
35
|
+
* @classdesc Configuration for the standalone WhatsApp widget.
|
|
36
|
+
* @property {String} id - The id of the WhatsApp widget.
|
|
37
|
+
* @property {String} container - The container to append the widget to, defaults to 'body'.
|
|
38
|
+
* @property {Placement} placement - The placement of the widget, defaults to 'bottom-right'.
|
|
39
|
+
* @property {String} number - WhatsApp number used by the widget link.
|
|
40
|
+
* @property {String} body - Prefilled WhatsApp compose text.
|
|
41
|
+
* @property {WhatsAppWidgetAppearance} appearance - Appearance overrides.
|
|
42
|
+
*/
|
|
43
|
+
let WhatsApp = /*#__PURE__*/function () {
|
|
44
|
+
function WhatsApp() {
|
|
45
|
+
_classCallCheck(this, WhatsApp);
|
|
46
|
+
}
|
|
47
|
+
_createClass(WhatsApp, null, [{
|
|
48
|
+
key: "id",
|
|
49
|
+
get: function () {
|
|
50
|
+
return this._id;
|
|
51
|
+
},
|
|
52
|
+
set: function (value) {
|
|
53
|
+
this._id = value;
|
|
54
|
+
}
|
|
55
|
+
}, {
|
|
56
|
+
key: "container",
|
|
57
|
+
get: function () {
|
|
58
|
+
return this._container;
|
|
59
|
+
},
|
|
60
|
+
set: function (value) {
|
|
61
|
+
this._container = value;
|
|
62
|
+
}
|
|
63
|
+
}, {
|
|
64
|
+
key: "placement",
|
|
65
|
+
get: function () {
|
|
66
|
+
return this._placement;
|
|
67
|
+
},
|
|
68
|
+
set: function (value) {
|
|
69
|
+
if (!Object.values(placements).includes(value)) {
|
|
70
|
+
throw new Error(`Invalid placement value: ${value}`);
|
|
71
|
+
}
|
|
72
|
+
this._placement = value;
|
|
73
|
+
}
|
|
74
|
+
}, {
|
|
75
|
+
key: "appearance",
|
|
76
|
+
get: function () {
|
|
77
|
+
return this._appearance;
|
|
78
|
+
},
|
|
79
|
+
set: function (value) {
|
|
80
|
+
if (!this.isPlainObject(value)) {
|
|
81
|
+
throw new Error('Appearance must be an object');
|
|
82
|
+
}
|
|
83
|
+
Object.entries(value).forEach(([key, nestedValue]) => {
|
|
84
|
+
if (key !== 'launcher') {
|
|
85
|
+
throw new Error(`Invalid appearance property: ${key}`);
|
|
86
|
+
}
|
|
87
|
+
if (!this.isPlainObject(nestedValue)) {
|
|
88
|
+
throw new Error(`Appearance ${key} must be an object`);
|
|
89
|
+
}
|
|
90
|
+
Object.entries(nestedValue).forEach(([nestedKey, propertyValue]) => {
|
|
91
|
+
if (nestedKey !== 'iconUrl') {
|
|
92
|
+
throw new Error(`Invalid appearance launcher property: ${nestedKey}`);
|
|
93
|
+
}
|
|
94
|
+
if (propertyValue == null) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (typeof propertyValue !== 'string') {
|
|
98
|
+
throw new Error(`Invalid appearance ${key}.${nestedKey} value: ${propertyValue}`);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
this._appearance = value;
|
|
103
|
+
}
|
|
104
|
+
}, {
|
|
105
|
+
key: "number",
|
|
106
|
+
get: function () {
|
|
107
|
+
return this._number;
|
|
108
|
+
},
|
|
109
|
+
set: function (value) {
|
|
110
|
+
if (value != null && typeof value !== 'string') {
|
|
111
|
+
throw new Error(`Invalid number value: ${value}`);
|
|
112
|
+
}
|
|
113
|
+
this._number = value;
|
|
114
|
+
}
|
|
115
|
+
}, {
|
|
116
|
+
key: "body",
|
|
117
|
+
get: function () {
|
|
118
|
+
return this._body;
|
|
119
|
+
},
|
|
120
|
+
set: function (value) {
|
|
121
|
+
if (value != null && typeof value !== 'string') {
|
|
122
|
+
throw new Error(`Invalid body value: ${value}`);
|
|
123
|
+
}
|
|
124
|
+
this._body = value;
|
|
125
|
+
}
|
|
126
|
+
}, {
|
|
127
|
+
key: "assign",
|
|
128
|
+
value: function assign(props) {
|
|
129
|
+
if (props) {
|
|
130
|
+
Object.entries(props).forEach(([key, value]) => {
|
|
131
|
+
this[key] = value;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
136
|
+
}, {
|
|
137
|
+
key: "isPlainObject",
|
|
138
|
+
value: function isPlainObject(value) {
|
|
139
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
140
|
+
}
|
|
141
|
+
}]);
|
|
142
|
+
return WhatsApp;
|
|
143
|
+
}();
|
|
144
|
+
exports.WhatsApp = WhatsApp;
|
|
145
|
+
WhatsApp._id = void 0;
|
|
146
|
+
WhatsApp._container = 'body';
|
|
147
|
+
WhatsApp._placement = 'bottom-right';
|
|
148
|
+
WhatsApp._appearance = {};
|
|
149
|
+
WhatsApp._number = null;
|
|
150
|
+
WhatsApp._body = null;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
2
|
+
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); } }
|
|
3
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
4
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
5
|
+
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); }
|
|
6
|
+
/**
|
|
7
|
+
* @typedef {'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'} Placement
|
|
8
|
+
* @description Valid placements for the WhatsApp widget.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @enum {Placement}
|
|
13
|
+
*/
|
|
14
|
+
var placements = {
|
|
15
|
+
TOP_LEFT: 'top-left',
|
|
16
|
+
TOP_RIGHT: 'top-right',
|
|
17
|
+
BOTTOM_LEFT: 'bottom-left',
|
|
18
|
+
BOTTOM_RIGHT: 'bottom-right'
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @typedef {Object} WhatsAppWidgetAppearance
|
|
23
|
+
* @property {Object} [launcher] - Launcher appearance overrides.
|
|
24
|
+
* @property {string} [launcher.iconUrl] - Image URL used for the launcher icon.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @class WhatsApp
|
|
29
|
+
* @classdesc Configuration for the standalone WhatsApp widget.
|
|
30
|
+
* @property {String} id - The id of the WhatsApp widget.
|
|
31
|
+
* @property {String} container - The container to append the widget to, defaults to 'body'.
|
|
32
|
+
* @property {Placement} placement - The placement of the widget, defaults to 'bottom-right'.
|
|
33
|
+
* @property {String} number - WhatsApp number used by the widget link.
|
|
34
|
+
* @property {String} body - Prefilled WhatsApp compose text.
|
|
35
|
+
* @property {WhatsAppWidgetAppearance} appearance - Appearance overrides.
|
|
36
|
+
*/
|
|
37
|
+
var WhatsApp = /*#__PURE__*/function () {
|
|
38
|
+
function WhatsApp() {
|
|
39
|
+
_classCallCheck(this, WhatsApp);
|
|
40
|
+
}
|
|
41
|
+
_createClass(WhatsApp, null, [{
|
|
42
|
+
key: "id",
|
|
43
|
+
get: function get() {
|
|
44
|
+
return this._id;
|
|
45
|
+
},
|
|
46
|
+
set: function set(value) {
|
|
47
|
+
this._id = value;
|
|
48
|
+
}
|
|
49
|
+
}, {
|
|
50
|
+
key: "container",
|
|
51
|
+
get: function get() {
|
|
52
|
+
return this._container;
|
|
53
|
+
},
|
|
54
|
+
set: function set(value) {
|
|
55
|
+
this._container = value;
|
|
56
|
+
}
|
|
57
|
+
}, {
|
|
58
|
+
key: "placement",
|
|
59
|
+
get: function get() {
|
|
60
|
+
return this._placement;
|
|
61
|
+
},
|
|
62
|
+
set: function set(value) {
|
|
63
|
+
if (!Object.values(placements).includes(value)) {
|
|
64
|
+
throw new Error("Invalid placement value: ".concat(value));
|
|
65
|
+
}
|
|
66
|
+
this._placement = value;
|
|
67
|
+
}
|
|
68
|
+
}, {
|
|
69
|
+
key: "appearance",
|
|
70
|
+
get: function get() {
|
|
71
|
+
return this._appearance;
|
|
72
|
+
},
|
|
73
|
+
set: function set(value) {
|
|
74
|
+
if (!this.isPlainObject(value)) {
|
|
75
|
+
throw new Error('Appearance must be an object');
|
|
76
|
+
}
|
|
77
|
+
Object.entries(value).forEach(_ref => {
|
|
78
|
+
var [key, nestedValue] = _ref;
|
|
79
|
+
if (key !== 'launcher') {
|
|
80
|
+
throw new Error("Invalid appearance property: ".concat(key));
|
|
81
|
+
}
|
|
82
|
+
if (!this.isPlainObject(nestedValue)) {
|
|
83
|
+
throw new Error("Appearance ".concat(key, " must be an object"));
|
|
84
|
+
}
|
|
85
|
+
Object.entries(nestedValue).forEach(_ref2 => {
|
|
86
|
+
var [nestedKey, propertyValue] = _ref2;
|
|
87
|
+
if (nestedKey !== 'iconUrl') {
|
|
88
|
+
throw new Error("Invalid appearance launcher property: ".concat(nestedKey));
|
|
89
|
+
}
|
|
90
|
+
if (propertyValue == null) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (typeof propertyValue !== 'string') {
|
|
94
|
+
throw new Error("Invalid appearance ".concat(key, ".").concat(nestedKey, " value: ").concat(propertyValue));
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
this._appearance = value;
|
|
99
|
+
}
|
|
100
|
+
}, {
|
|
101
|
+
key: "number",
|
|
102
|
+
get: function get() {
|
|
103
|
+
return this._number;
|
|
104
|
+
},
|
|
105
|
+
set: function set(value) {
|
|
106
|
+
if (value != null && typeof value !== 'string') {
|
|
107
|
+
throw new Error("Invalid number value: ".concat(value));
|
|
108
|
+
}
|
|
109
|
+
this._number = value;
|
|
110
|
+
}
|
|
111
|
+
}, {
|
|
112
|
+
key: "body",
|
|
113
|
+
get: function get() {
|
|
114
|
+
return this._body;
|
|
115
|
+
},
|
|
116
|
+
set: function set(value) {
|
|
117
|
+
if (value != null && typeof value !== 'string') {
|
|
118
|
+
throw new Error("Invalid body value: ".concat(value));
|
|
119
|
+
}
|
|
120
|
+
this._body = value;
|
|
121
|
+
}
|
|
122
|
+
}, {
|
|
123
|
+
key: "assign",
|
|
124
|
+
value: function assign(props) {
|
|
125
|
+
if (props) {
|
|
126
|
+
Object.entries(props).forEach(_ref3 => {
|
|
127
|
+
var [key, value] = _ref3;
|
|
128
|
+
this[key] = value;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
}, {
|
|
134
|
+
key: "isPlainObject",
|
|
135
|
+
value: function isPlainObject(value) {
|
|
136
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
137
|
+
}
|
|
138
|
+
}]);
|
|
139
|
+
return WhatsApp;
|
|
140
|
+
}();
|
|
141
|
+
WhatsApp._id = void 0;
|
|
142
|
+
WhatsApp._container = 'body';
|
|
143
|
+
WhatsApp._placement = 'bottom-right';
|
|
144
|
+
WhatsApp._appearance = {};
|
|
145
|
+
WhatsApp._number = null;
|
|
146
|
+
WhatsApp._body = null;
|
|
147
|
+
export { WhatsApp };
|
|
@@ -7,6 +7,7 @@ exports.Configuration = void 0;
|
|
|
7
7
|
var _forms = require("./configuration/forms");
|
|
8
8
|
var _locale = require("./configuration/locale");
|
|
9
9
|
var _webchat = require("./configuration/webchat");
|
|
10
|
+
var _whatsapp = require("./configuration/whatsapp");
|
|
10
11
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
11
12
|
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); } }
|
|
12
13
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
@@ -20,6 +21,7 @@ function _toPrimitive(input, hint) { if (typeof input !== "object" || input ===
|
|
|
20
21
|
* @property {String} [session] - session id
|
|
21
22
|
* @property {Forms} [forms] - form configuration
|
|
22
23
|
* @property {Webchat} [webchat] - webchat configuration
|
|
24
|
+
* @property {WhatsApp} [whatsappWidget] - WhatsApp widget configuration
|
|
23
25
|
* @property {Locale} [locale] - locale configuration
|
|
24
26
|
*/
|
|
25
27
|
let Configuration = /*#__PURE__*/function () {
|
|
@@ -45,6 +47,8 @@ let Configuration = /*#__PURE__*/function () {
|
|
|
45
47
|
this.forms = _forms.Forms.assign(value);
|
|
46
48
|
} else if (key === 'webchat') {
|
|
47
49
|
this.webchat = _webchat.Webchat.assign(value);
|
|
50
|
+
} else if (key === 'whatsappWidget') {
|
|
51
|
+
this.whatsapp = _whatsapp.WhatsApp.assign(value);
|
|
48
52
|
} else {
|
|
49
53
|
this[key] = value;
|
|
50
54
|
}
|
|
@@ -92,4 +96,5 @@ Configuration.actionCableUrl = 'wss://www.hellotext.com/cable';
|
|
|
92
96
|
Configuration.autoGenerateSession = true;
|
|
93
97
|
Configuration.session = null;
|
|
94
98
|
Configuration.forms = _forms.Forms;
|
|
95
|
-
Configuration.webchat = _webchat.Webchat;
|
|
99
|
+
Configuration.webchat = _webchat.Webchat;
|
|
100
|
+
Configuration.whatsapp = _whatsapp.WhatsApp;
|
|
@@ -6,6 +6,7 @@ function _toPrimitive(input, hint) { if (typeof input !== "object" || input ===
|
|
|
6
6
|
import { Forms } from './configuration/forms';
|
|
7
7
|
import { Locale } from './configuration/locale';
|
|
8
8
|
import { Webchat } from './configuration/webchat';
|
|
9
|
+
import { WhatsApp } from './configuration/whatsapp';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* @class Configuration
|
|
@@ -15,6 +16,7 @@ import { Webchat } from './configuration/webchat';
|
|
|
15
16
|
* @property {String} [session] - session id
|
|
16
17
|
* @property {Forms} [forms] - form configuration
|
|
17
18
|
* @property {Webchat} [webchat] - webchat configuration
|
|
19
|
+
* @property {WhatsApp} [whatsappWidget] - WhatsApp widget configuration
|
|
18
20
|
* @property {Locale} [locale] - locale configuration
|
|
19
21
|
*/
|
|
20
22
|
var Configuration = /*#__PURE__*/function () {
|
|
@@ -41,6 +43,8 @@ var Configuration = /*#__PURE__*/function () {
|
|
|
41
43
|
this.forms = Forms.assign(value);
|
|
42
44
|
} else if (key === 'webchat') {
|
|
43
45
|
this.webchat = Webchat.assign(value);
|
|
46
|
+
} else if (key === 'whatsappWidget') {
|
|
47
|
+
this.whatsapp = WhatsApp.assign(value);
|
|
44
48
|
} else {
|
|
45
49
|
this[key] = value;
|
|
46
50
|
}
|
|
@@ -88,4 +92,5 @@ Configuration.autoGenerateSession = true;
|
|
|
88
92
|
Configuration.session = null;
|
|
89
93
|
Configuration.forms = Forms;
|
|
90
94
|
Configuration.webchat = Webchat;
|
|
95
|
+
Configuration.whatsapp = WhatsApp;
|
|
91
96
|
export { Configuration };
|
package/lib/core/index.cjs
CHANGED
|
@@ -27,8 +27,15 @@ Object.defineProperty(exports, "Webchat", {
|
|
|
27
27
|
return _webchat.Webchat;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
|
+
Object.defineProperty(exports, "WhatsApp", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _whatsapp.WhatsApp;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
30
36
|
var _configuration = require("./configuration");
|
|
31
37
|
var _locale = require("./configuration/locale");
|
|
32
38
|
var _webchat = require("./configuration/webchat");
|
|
39
|
+
var _whatsapp = require("./configuration/whatsapp");
|
|
33
40
|
var _event = _interopRequireDefault(require("./event"));
|
|
34
41
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
package/lib/core/index.js
CHANGED
package/lib/hellotext.cjs
CHANGED
|
@@ -36,12 +36,17 @@ let Hellotext = /*#__PURE__*/function () {
|
|
|
36
36
|
this.query = new _models.Query();
|
|
37
37
|
const businessData = await this.business.hydrate();
|
|
38
38
|
const webchatConfig = config.webchat === false ? false : this.mergeWebchatConfig(businessData && businessData.webchat || {}, config.webchat || {});
|
|
39
|
+
const whatsappConfig = config.whatsappWidget === false ? false : this.mergeWhatsAppConfig(businessData && businessData.whatsapp || {}, config.whatsappWidget || {});
|
|
39
40
|
const hasExplicitBehaviourOverride = config.webchat && config.webchat !== false && Object.prototype.hasOwnProperty.call(config.webchat, 'behaviour');
|
|
40
41
|
_core.Configuration.webchat.behaviourOverride = hasExplicitBehaviourOverride;
|
|
41
42
|
if (webchatConfig && webchatConfig.id) {
|
|
42
43
|
_core.Configuration.webchat.assign(webchatConfig);
|
|
43
44
|
this.webchat = await _models.Webchat.load(webchatConfig.id);
|
|
44
45
|
}
|
|
46
|
+
if (whatsappConfig && whatsappConfig.id) {
|
|
47
|
+
_core.Configuration.whatsapp.assign(whatsappConfig);
|
|
48
|
+
this.whatsapp = await _models.WhatsAppWidget.load(whatsappConfig.id);
|
|
49
|
+
}
|
|
45
50
|
if (typeof MutationObserver !== 'undefined') {
|
|
46
51
|
this.forms.collectExistingFormsOnPage();
|
|
47
52
|
}
|
|
@@ -51,6 +56,11 @@ let Hellotext = /*#__PURE__*/function () {
|
|
|
51
56
|
value: function mergeWebchatConfig(dashboardConfig, localConfig) {
|
|
52
57
|
return this.deepMergePlainObjects(dashboardConfig, localConfig);
|
|
53
58
|
}
|
|
59
|
+
}, {
|
|
60
|
+
key: "mergeWhatsAppConfig",
|
|
61
|
+
value: function mergeWhatsAppConfig(dashboardConfig, localConfig) {
|
|
62
|
+
return this.deepMergePlainObjects(dashboardConfig, localConfig);
|
|
63
|
+
}
|
|
54
64
|
}, {
|
|
55
65
|
key: "deepMergePlainObjects",
|
|
56
66
|
value: function deepMergePlainObjects(base, override) {
|
|
@@ -226,5 +236,6 @@ Hellotext.eventEmitter = new _core.Event();
|
|
|
226
236
|
Hellotext.forms = void 0;
|
|
227
237
|
Hellotext.business = void 0;
|
|
228
238
|
Hellotext.webchat = void 0;
|
|
239
|
+
Hellotext.whatsapp = void 0;
|
|
229
240
|
var _default = Hellotext;
|
|
230
241
|
exports.default = _default;
|
package/lib/hellotext.js
CHANGED
|
@@ -10,7 +10,7 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typ
|
|
|
10
10
|
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); }
|
|
11
11
|
import { Configuration, Event } from './core';
|
|
12
12
|
import API, { Response, keepaliveFor } from './api';
|
|
13
|
-
import { Business, Fingerprint, FormCollection, Page, Query, Session, User, Webchat } from './models';
|
|
13
|
+
import { Business, Fingerprint, FormCollection, Page, Query, Session, User, Webchat, WhatsAppWidget } from './models';
|
|
14
14
|
import { NotInitializedError } from './errors';
|
|
15
15
|
var Hellotext = /*#__PURE__*/function () {
|
|
16
16
|
function Hellotext() {
|
|
@@ -35,12 +35,17 @@ var Hellotext = /*#__PURE__*/function () {
|
|
|
35
35
|
this.query = new Query();
|
|
36
36
|
var businessData = yield this.business.hydrate();
|
|
37
37
|
var webchatConfig = config.webchat === false ? false : this.mergeWebchatConfig(businessData && businessData.webchat || {}, config.webchat || {});
|
|
38
|
+
var whatsappConfig = config.whatsappWidget === false ? false : this.mergeWhatsAppConfig(businessData && businessData.whatsapp || {}, config.whatsappWidget || {});
|
|
38
39
|
var hasExplicitBehaviourOverride = config.webchat && config.webchat !== false && Object.prototype.hasOwnProperty.call(config.webchat, 'behaviour');
|
|
39
40
|
Configuration.webchat.behaviourOverride = hasExplicitBehaviourOverride;
|
|
40
41
|
if (webchatConfig && webchatConfig.id) {
|
|
41
42
|
Configuration.webchat.assign(webchatConfig);
|
|
42
43
|
this.webchat = yield Webchat.load(webchatConfig.id);
|
|
43
44
|
}
|
|
45
|
+
if (whatsappConfig && whatsappConfig.id) {
|
|
46
|
+
Configuration.whatsapp.assign(whatsappConfig);
|
|
47
|
+
this.whatsapp = yield WhatsAppWidget.load(whatsappConfig.id);
|
|
48
|
+
}
|
|
44
49
|
if (typeof MutationObserver !== 'undefined') {
|
|
45
50
|
this.forms.collectExistingFormsOnPage();
|
|
46
51
|
}
|
|
@@ -55,6 +60,11 @@ var Hellotext = /*#__PURE__*/function () {
|
|
|
55
60
|
value: function mergeWebchatConfig(dashboardConfig, localConfig) {
|
|
56
61
|
return this.deepMergePlainObjects(dashboardConfig, localConfig);
|
|
57
62
|
}
|
|
63
|
+
}, {
|
|
64
|
+
key: "mergeWhatsAppConfig",
|
|
65
|
+
value: function mergeWhatsAppConfig(dashboardConfig, localConfig) {
|
|
66
|
+
return this.deepMergePlainObjects(dashboardConfig, localConfig);
|
|
67
|
+
}
|
|
58
68
|
}, {
|
|
59
69
|
key: "deepMergePlainObjects",
|
|
60
70
|
value: function deepMergePlainObjects(base, override) {
|
|
@@ -240,4 +250,5 @@ Hellotext.eventEmitter = new Event();
|
|
|
240
250
|
Hellotext.forms = void 0;
|
|
241
251
|
Hellotext.business = void 0;
|
|
242
252
|
Hellotext.webchat = void 0;
|
|
253
|
+
Hellotext.whatsapp = void 0;
|
|
243
254
|
export default Hellotext;
|
package/lib/models/index.cjs
CHANGED
|
@@ -69,6 +69,12 @@ Object.defineProperty(exports, "Webchat", {
|
|
|
69
69
|
return _webchat.Webchat;
|
|
70
70
|
}
|
|
71
71
|
});
|
|
72
|
+
Object.defineProperty(exports, "WhatsAppWidget", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function () {
|
|
75
|
+
return _whatsapp_widget.WhatsAppWidget;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
72
78
|
var _business = require("./business");
|
|
73
79
|
var _cookies = require("./cookies");
|
|
74
80
|
var _fingerprint = require("./fingerprint");
|
|
@@ -79,4 +85,5 @@ var _query = require("./query");
|
|
|
79
85
|
var _session = require("./session");
|
|
80
86
|
var _user = require("./user");
|
|
81
87
|
var _utm = require("./utm");
|
|
82
|
-
var _webchat = require("./webchat");
|
|
88
|
+
var _webchat = require("./webchat");
|
|
89
|
+
var _whatsapp_widget = require("./whatsapp_widget");
|
package/lib/models/index.js
CHANGED
|
@@ -8,4 +8,5 @@ export { Query } from './query';
|
|
|
8
8
|
export { Session } from './session';
|
|
9
9
|
export { User } from './user';
|
|
10
10
|
export { UTM } from './utm';
|
|
11
|
-
export { Webchat } from './webchat';
|
|
11
|
+
export { Webchat } from './webchat';
|
|
12
|
+
export { WhatsAppWidget } from './whatsapp_widget';
|
package/lib/models/webchat.cjs
CHANGED
|
@@ -29,6 +29,7 @@ let Webchat = /*#__PURE__*/function () {
|
|
|
29
29
|
return false;
|
|
30
30
|
}
|
|
31
31
|
this.containerToAppendTo.appendChild(this.data.html);
|
|
32
|
+
this.markCoexistingWidgets();
|
|
32
33
|
this.mounted = true;
|
|
33
34
|
return true;
|
|
34
35
|
}
|
|
@@ -66,6 +67,15 @@ let Webchat = /*#__PURE__*/function () {
|
|
|
66
67
|
get: function () {
|
|
67
68
|
return _business.Business.waitForStylesheet(_business.Business.latestStylesheet);
|
|
68
69
|
}
|
|
70
|
+
}, {
|
|
71
|
+
key: "markCoexistingWidgets",
|
|
72
|
+
value: function markCoexistingWidgets() {
|
|
73
|
+
const webchat = this.data.html;
|
|
74
|
+
const whatsapp = document.querySelector('.hellotext--whatsapp-widget');
|
|
75
|
+
if (!webchat || !whatsapp) return;
|
|
76
|
+
webchat.classList.add('hellotext--with-whatsapp-widget');
|
|
77
|
+
whatsapp.classList.add('hellotext--with-webchat');
|
|
78
|
+
}
|
|
69
79
|
}], [{
|
|
70
80
|
key: "load",
|
|
71
81
|
value: async function load(id) {
|
package/lib/models/webchat.js
CHANGED
|
@@ -25,6 +25,7 @@ var Webchat = /*#__PURE__*/function () {
|
|
|
25
25
|
return false;
|
|
26
26
|
}
|
|
27
27
|
this.containerToAppendTo.appendChild(this.data.html);
|
|
28
|
+
this.markCoexistingWidgets();
|
|
28
29
|
this.mounted = true;
|
|
29
30
|
return true;
|
|
30
31
|
});
|
|
@@ -67,6 +68,15 @@ var Webchat = /*#__PURE__*/function () {
|
|
|
67
68
|
get: function get() {
|
|
68
69
|
return Business.waitForStylesheet(Business.latestStylesheet);
|
|
69
70
|
}
|
|
71
|
+
}, {
|
|
72
|
+
key: "markCoexistingWidgets",
|
|
73
|
+
value: function markCoexistingWidgets() {
|
|
74
|
+
var webchat = this.data.html;
|
|
75
|
+
var whatsapp = document.querySelector('.hellotext--whatsapp-widget');
|
|
76
|
+
if (!webchat || !whatsapp) return;
|
|
77
|
+
webchat.classList.add('hellotext--with-whatsapp-widget');
|
|
78
|
+
whatsapp.classList.add('hellotext--with-webchat');
|
|
79
|
+
}
|
|
70
80
|
}], [{
|
|
71
81
|
key: "load",
|
|
72
82
|
value: function () {
|