@hellotext/hellotext 2.1.1 → 2.1.3
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/dist/hellotext.js +1 -1
- package/lib/api/forms.cjs +2 -1
- package/lib/api/forms.js +2 -1
- package/lib/api/webchat/messages.cjs +4 -3
- package/lib/api/webchat/messages.js +4 -2
- package/lib/api/webchats.cjs +2 -0
- package/lib/api/webchats.js +3 -1
- package/lib/builders/logo_builder.cjs +1 -1
- package/lib/builders/logo_builder.js +1 -1
- package/lib/controllers/webchat/emoji_picker_controller.cjs +6 -6
- package/lib/controllers/webchat/emoji_picker_controller.js +5 -14
- package/lib/controllers/webchat_controller.cjs +63 -15
- package/lib/controllers/webchat_controller.js +63 -15
- package/lib/core/configuration/locale.cjs +87 -0
- package/lib/core/configuration/locale.js +81 -0
- package/lib/core/configuration.cjs +10 -0
- package/lib/core/configuration.js +10 -0
- package/lib/core/index.cjs +15 -1
- package/lib/core/index.js +4 -2
- package/lib/locales/en.cjs +1 -1
- package/lib/locales/en.js +1 -1
- package/lib/locales/es.cjs +1 -1
- package/lib/locales/es.js +1 -1
- package/lib/models/business.cjs +11 -0
- package/lib/models/business.js +11 -0
- package/lib/models/form_collection.cjs +1 -0
- package/lib/models/form_collection.js +2 -1
- package/lib/models/index.cjs +4 -4
- package/lib/models/index.js +4 -4
- package/package.json +2 -1
- package/src/api/forms.js +3 -1
- package/src/api/webchat/messages.js +8 -6
- package/src/api/webchats.js +3 -1
- package/src/builders/logo_builder.js +1 -1
- package/src/controllers/webchat/emoji_picker_controller.js +9 -15
- package/src/controllers/webchat_controller.js +69 -19
- package/src/core/configuration/locale.js +50 -0
- package/src/core/configuration.js +10 -0
- package/src/core/index.js +3 -1
- package/src/locales/en.js +4 -4
- package/src/locales/es.js +4 -4
- package/src/models/business.js +12 -0
- package/src/models/form_collection.js +2 -1
- package/src/models/index.js +3 -3
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Locale = 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
|
+
function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }
|
|
13
|
+
var id = 0;
|
|
14
|
+
function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
|
|
15
|
+
var _fromHtmlLangProperty = /*#__PURE__*/_classPrivateFieldLooseKey("fromHtmlLangProperty");
|
|
16
|
+
var _fromMetaTag = /*#__PURE__*/_classPrivateFieldLooseKey("fromMetaTag");
|
|
17
|
+
var _fromBrowserLanguage = /*#__PURE__*/_classPrivateFieldLooseKey("fromBrowserLanguage");
|
|
18
|
+
/**
|
|
19
|
+
* @class Locale
|
|
20
|
+
* @classdesc
|
|
21
|
+
* Handles locale detection and configuration for the Hellotext library.
|
|
22
|
+
* Provides automatic locale detection from HTML lang attribute, meta tags,
|
|
23
|
+
* and browser language with fallback to 'en'.
|
|
24
|
+
*/
|
|
25
|
+
let Locale = /*#__PURE__*/function () {
|
|
26
|
+
function Locale() {
|
|
27
|
+
_classCallCheck(this, Locale);
|
|
28
|
+
}
|
|
29
|
+
_createClass(Locale, null, [{
|
|
30
|
+
key: "identifier",
|
|
31
|
+
get:
|
|
32
|
+
/**
|
|
33
|
+
* Gets the effective locale identifier.
|
|
34
|
+
* Falls back to auto-detection if not explicitly set.
|
|
35
|
+
* @returns {string} The locale identifier
|
|
36
|
+
*/
|
|
37
|
+
function () {
|
|
38
|
+
if (this._identifier) return this._identifier;
|
|
39
|
+
return _classPrivateFieldLooseBase(this, _fromHtmlLangProperty)[_fromHtmlLangProperty] || _classPrivateFieldLooseBase(this, _fromMetaTag)[_fromMetaTag] || _classPrivateFieldLooseBase(this, _fromBrowserLanguage)[_fromBrowserLanguage] || 'en';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Returns the locale identifier as a string.
|
|
44
|
+
* @returns {string} The locale identifier
|
|
45
|
+
*/,
|
|
46
|
+
set:
|
|
47
|
+
/**
|
|
48
|
+
* Sets the locale identifier explicitly.
|
|
49
|
+
* @param {string} value - The locale identifier (e.g., 'en', 'es')
|
|
50
|
+
*/
|
|
51
|
+
function (value) {
|
|
52
|
+
this._identifier = value;
|
|
53
|
+
}
|
|
54
|
+
}, {
|
|
55
|
+
key: "toString",
|
|
56
|
+
value: function toString() {
|
|
57
|
+
return this.identifier;
|
|
58
|
+
}
|
|
59
|
+
}]);
|
|
60
|
+
return Locale;
|
|
61
|
+
}();
|
|
62
|
+
exports.Locale = Locale;
|
|
63
|
+
function _get_fromHtmlLangProperty() {
|
|
64
|
+
var _document, _document$documentEle;
|
|
65
|
+
return (_document = document) === null || _document === void 0 ? void 0 : (_document$documentEle = _document.documentElement) === null || _document$documentEle === void 0 ? void 0 : _document$documentEle.lang;
|
|
66
|
+
}
|
|
67
|
+
function _get_fromMetaTag() {
|
|
68
|
+
var _document2, _document2$querySelec;
|
|
69
|
+
return (_document2 = document) === null || _document2 === void 0 ? void 0 : (_document2$querySelec = _document2.querySelector('meta[name="locale"]')) === null || _document2$querySelec === void 0 ? void 0 : _document2$querySelec.content;
|
|
70
|
+
}
|
|
71
|
+
function _get_fromBrowserLanguage() {
|
|
72
|
+
var _navigator, _navigator$language;
|
|
73
|
+
return (_navigator = navigator) === null || _navigator === void 0 ? void 0 : (_navigator$language = _navigator.language) === null || _navigator$language === void 0 ? void 0 : _navigator$language.split('-')[0]; // Extract primary language
|
|
74
|
+
}
|
|
75
|
+
Object.defineProperty(Locale, _fromBrowserLanguage, {
|
|
76
|
+
get: _get_fromBrowserLanguage,
|
|
77
|
+
set: void 0
|
|
78
|
+
});
|
|
79
|
+
Object.defineProperty(Locale, _fromMetaTag, {
|
|
80
|
+
get: _get_fromMetaTag,
|
|
81
|
+
set: void 0
|
|
82
|
+
});
|
|
83
|
+
Object.defineProperty(Locale, _fromHtmlLangProperty, {
|
|
84
|
+
get: _get_fromHtmlLangProperty,
|
|
85
|
+
set: void 0
|
|
86
|
+
});
|
|
87
|
+
Locale._identifier = void 0;
|
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }
|
|
7
|
+
var id = 0;
|
|
8
|
+
function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
|
|
9
|
+
var _fromHtmlLangProperty = /*#__PURE__*/_classPrivateFieldLooseKey("fromHtmlLangProperty");
|
|
10
|
+
var _fromMetaTag = /*#__PURE__*/_classPrivateFieldLooseKey("fromMetaTag");
|
|
11
|
+
var _fromBrowserLanguage = /*#__PURE__*/_classPrivateFieldLooseKey("fromBrowserLanguage");
|
|
12
|
+
/**
|
|
13
|
+
* @class Locale
|
|
14
|
+
* @classdesc
|
|
15
|
+
* Handles locale detection and configuration for the Hellotext library.
|
|
16
|
+
* Provides automatic locale detection from HTML lang attribute, meta tags,
|
|
17
|
+
* and browser language with fallback to 'en'.
|
|
18
|
+
*/
|
|
19
|
+
var Locale = /*#__PURE__*/function () {
|
|
20
|
+
function Locale() {
|
|
21
|
+
_classCallCheck(this, Locale);
|
|
22
|
+
}
|
|
23
|
+
_createClass(Locale, null, [{
|
|
24
|
+
key: "identifier",
|
|
25
|
+
get:
|
|
26
|
+
/**
|
|
27
|
+
* Gets the effective locale identifier.
|
|
28
|
+
* Falls back to auto-detection if not explicitly set.
|
|
29
|
+
* @returns {string} The locale identifier
|
|
30
|
+
*/
|
|
31
|
+
function get() {
|
|
32
|
+
if (this._identifier) return this._identifier;
|
|
33
|
+
return _classPrivateFieldLooseBase(this, _fromHtmlLangProperty)[_fromHtmlLangProperty] || _classPrivateFieldLooseBase(this, _fromMetaTag)[_fromMetaTag] || _classPrivateFieldLooseBase(this, _fromBrowserLanguage)[_fromBrowserLanguage] || 'en';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Returns the locale identifier as a string.
|
|
38
|
+
* @returns {string} The locale identifier
|
|
39
|
+
*/,
|
|
40
|
+
set:
|
|
41
|
+
/**
|
|
42
|
+
* Sets the locale identifier explicitly.
|
|
43
|
+
* @param {string} value - The locale identifier (e.g., 'en', 'es')
|
|
44
|
+
*/
|
|
45
|
+
function set(value) {
|
|
46
|
+
this._identifier = value;
|
|
47
|
+
}
|
|
48
|
+
}, {
|
|
49
|
+
key: "toString",
|
|
50
|
+
value: function toString() {
|
|
51
|
+
return this.identifier;
|
|
52
|
+
}
|
|
53
|
+
}]);
|
|
54
|
+
return Locale;
|
|
55
|
+
}();
|
|
56
|
+
function _get_fromHtmlLangProperty() {
|
|
57
|
+
var _document, _document$documentEle;
|
|
58
|
+
return (_document = document) === null || _document === void 0 ? void 0 : (_document$documentEle = _document.documentElement) === null || _document$documentEle === void 0 ? void 0 : _document$documentEle.lang;
|
|
59
|
+
}
|
|
60
|
+
function _get_fromMetaTag() {
|
|
61
|
+
var _document2, _document2$querySelec;
|
|
62
|
+
return (_document2 = document) === null || _document2 === void 0 ? void 0 : (_document2$querySelec = _document2.querySelector('meta[name="locale"]')) === null || _document2$querySelec === void 0 ? void 0 : _document2$querySelec.content;
|
|
63
|
+
}
|
|
64
|
+
function _get_fromBrowserLanguage() {
|
|
65
|
+
var _navigator, _navigator$language;
|
|
66
|
+
return (_navigator = navigator) === null || _navigator === void 0 ? void 0 : (_navigator$language = _navigator.language) === null || _navigator$language === void 0 ? void 0 : _navigator$language.split('-')[0]; // Extract primary language
|
|
67
|
+
}
|
|
68
|
+
Object.defineProperty(Locale, _fromBrowserLanguage, {
|
|
69
|
+
get: _get_fromBrowserLanguage,
|
|
70
|
+
set: void 0
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(Locale, _fromMetaTag, {
|
|
73
|
+
get: _get_fromMetaTag,
|
|
74
|
+
set: void 0
|
|
75
|
+
});
|
|
76
|
+
Object.defineProperty(Locale, _fromHtmlLangProperty, {
|
|
77
|
+
get: _get_fromHtmlLangProperty,
|
|
78
|
+
set: void 0
|
|
79
|
+
});
|
|
80
|
+
Locale._identifier = void 0;
|
|
81
|
+
export { Locale };
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.Configuration = void 0;
|
|
7
7
|
var _forms = require("./configuration/forms");
|
|
8
|
+
var _locale = require("./configuration/locale");
|
|
8
9
|
var _webchat = require("./configuration/webchat");
|
|
9
10
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
10
11
|
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); } }
|
|
@@ -19,6 +20,7 @@ function _toPrimitive(input, hint) { if (typeof input !== "object" || input ===
|
|
|
19
20
|
* @property {String} [session] - session id
|
|
20
21
|
* @property {Forms} [forms] - form configuration
|
|
21
22
|
* @property {Webchat} [webchat] - webchat configuration
|
|
23
|
+
* @property {Locale} [locale] - locale configuration
|
|
22
24
|
*/
|
|
23
25
|
let Configuration = /*#__PURE__*/function () {
|
|
24
26
|
function Configuration() {
|
|
@@ -49,6 +51,14 @@ let Configuration = /*#__PURE__*/function () {
|
|
|
49
51
|
}
|
|
50
52
|
return this;
|
|
51
53
|
}
|
|
54
|
+
}, {
|
|
55
|
+
key: "locale",
|
|
56
|
+
get: function () {
|
|
57
|
+
return _locale.Locale.toString();
|
|
58
|
+
},
|
|
59
|
+
set: function (locale) {
|
|
60
|
+
_locale.Locale.identifier = locale;
|
|
61
|
+
}
|
|
52
62
|
}, {
|
|
53
63
|
key: "endpoint",
|
|
54
64
|
value: function endpoint(path) {
|
|
@@ -4,6 +4,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
|
|
|
4
4
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
5
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
6
|
import { Forms } from './configuration/forms';
|
|
7
|
+
import { Locale } from './configuration/locale';
|
|
7
8
|
import { Webchat } from './configuration/webchat';
|
|
8
9
|
|
|
9
10
|
/**
|
|
@@ -14,6 +15,7 @@ import { Webchat } from './configuration/webchat';
|
|
|
14
15
|
* @property {String} [session] - session id
|
|
15
16
|
* @property {Forms} [forms] - form configuration
|
|
16
17
|
* @property {Webchat} [webchat] - webchat configuration
|
|
18
|
+
* @property {Locale} [locale] - locale configuration
|
|
17
19
|
*/
|
|
18
20
|
var Configuration = /*#__PURE__*/function () {
|
|
19
21
|
function Configuration() {
|
|
@@ -45,6 +47,14 @@ var Configuration = /*#__PURE__*/function () {
|
|
|
45
47
|
}
|
|
46
48
|
return this;
|
|
47
49
|
}
|
|
50
|
+
}, {
|
|
51
|
+
key: "locale",
|
|
52
|
+
get: function get() {
|
|
53
|
+
return Locale.toString();
|
|
54
|
+
},
|
|
55
|
+
set: function set(locale) {
|
|
56
|
+
Locale.identifier = locale;
|
|
57
|
+
}
|
|
48
58
|
}, {
|
|
49
59
|
key: "endpoint",
|
|
50
60
|
value: function endpoint(path) {
|
package/lib/core/index.cjs
CHANGED
|
@@ -15,6 +15,20 @@ Object.defineProperty(exports, "Event", {
|
|
|
15
15
|
return _event.default;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
-
|
|
18
|
+
Object.defineProperty(exports, "Locale", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _locale.Locale;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "Webchat", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _webchat.Webchat;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
19
30
|
var _configuration = require("./configuration");
|
|
31
|
+
var _locale = require("./configuration/locale");
|
|
32
|
+
var _webchat = require("./configuration/webchat");
|
|
33
|
+
var _event = _interopRequireDefault(require("./event"));
|
|
20
34
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
package/lib/core/index.js
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { Configuration } from './configuration';
|
|
2
|
+
export { Locale } from './configuration/locale';
|
|
3
|
+
export { Webchat } from './configuration/webchat';
|
|
4
|
+
export { default as Event } from './event';
|
package/lib/locales/en.cjs
CHANGED
package/lib/locales/en.js
CHANGED
package/lib/locales/es.cjs
CHANGED
package/lib/locales/es.js
CHANGED
package/lib/models/business.cjs
CHANGED
|
@@ -43,6 +43,17 @@ let Business = /*#__PURE__*/function () {
|
|
|
43
43
|
get: function () {
|
|
44
44
|
return this.data.whitelist !== 'disabled';
|
|
45
45
|
}
|
|
46
|
+
}, {
|
|
47
|
+
key: "setLocale",
|
|
48
|
+
value: function setLocale(locale) {
|
|
49
|
+
if (!_locales.default[locale]) {
|
|
50
|
+
return console.warn(`Locale ${locale} not found`);
|
|
51
|
+
}
|
|
52
|
+
if (!this.data) {
|
|
53
|
+
this.data = {};
|
|
54
|
+
}
|
|
55
|
+
this.data.locale = locale;
|
|
56
|
+
}
|
|
46
57
|
}, {
|
|
47
58
|
key: "locale",
|
|
48
59
|
get: function () {
|
package/lib/models/business.js
CHANGED
|
@@ -36,6 +36,17 @@ var Business = /*#__PURE__*/function () {
|
|
|
36
36
|
get: function get() {
|
|
37
37
|
return this.data.whitelist !== 'disabled';
|
|
38
38
|
}
|
|
39
|
+
}, {
|
|
40
|
+
key: "setLocale",
|
|
41
|
+
value: function setLocale(locale) {
|
|
42
|
+
if (!locales[locale]) {
|
|
43
|
+
return console.warn("Locale ".concat(locale, " not found"));
|
|
44
|
+
}
|
|
45
|
+
if (!this.data) {
|
|
46
|
+
this.data = {};
|
|
47
|
+
}
|
|
48
|
+
this.data.locale = locale;
|
|
49
|
+
}
|
|
39
50
|
}, {
|
|
40
51
|
key: "locale",
|
|
41
52
|
get: function get() {
|
|
@@ -91,6 +91,7 @@ let FormCollection = /*#__PURE__*/function () {
|
|
|
91
91
|
if (this.includes(data.id)) return;
|
|
92
92
|
if (!_hellotext.default.business.data) {
|
|
93
93
|
_hellotext.default.business.setData(data.business);
|
|
94
|
+
_hellotext.default.business.setLocale(_core.Locale.toString());
|
|
94
95
|
}
|
|
95
96
|
if (!_hellotext.default.business.enabledWhitelist) {
|
|
96
97
|
console.warn('No whitelist has been configured. It is advised to whitelist the domain to avoid bots from submitting forms.');
|
|
@@ -10,7 +10,7 @@ var id = 0;
|
|
|
10
10
|
function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
|
|
11
11
|
import API from '../api/forms';
|
|
12
12
|
import Hellotext from '../hellotext';
|
|
13
|
-
import { Configuration } from '../core';
|
|
13
|
+
import { Configuration, Locale } from '../core';
|
|
14
14
|
import { Form } from './form';
|
|
15
15
|
import { NotInitializedError } from '../errors';
|
|
16
16
|
var _formIdsToFetch = /*#__PURE__*/_classPrivateFieldLooseKey("formIdsToFetch");
|
|
@@ -92,6 +92,7 @@ var FormCollection = /*#__PURE__*/function () {
|
|
|
92
92
|
if (this.includes(data.id)) return;
|
|
93
93
|
if (!Hellotext.business.data) {
|
|
94
94
|
Hellotext.business.setData(data.business);
|
|
95
|
+
Hellotext.business.setLocale(Locale.toString());
|
|
95
96
|
}
|
|
96
97
|
if (!Hellotext.business.enabledWhitelist) {
|
|
97
98
|
console.warn('No whitelist has been configured. It is advised to whitelist the domain to avoid bots from submitting forms.');
|
package/lib/models/index.cjs
CHANGED
|
@@ -46,9 +46,9 @@ Object.defineProperty(exports, "Webchat", {
|
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
48
|
var _business = require("./business");
|
|
49
|
-
var _form = require("./form");
|
|
50
|
-
var _query = require("./query");
|
|
51
49
|
var _cookies = require("./cookies");
|
|
50
|
+
var _form = require("./form");
|
|
52
51
|
var _form_collection = require("./form_collection");
|
|
53
|
-
var
|
|
54
|
-
var _session = require("./session");
|
|
52
|
+
var _query = require("./query");
|
|
53
|
+
var _session = require("./session");
|
|
54
|
+
var _webchat = require("./webchat");
|
package/lib/models/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { Business } from './business';
|
|
2
|
-
export { Form } from './form';
|
|
3
|
-
export { Query } from './query';
|
|
4
2
|
export { Cookies } from './cookies';
|
|
3
|
+
export { Form } from './form';
|
|
5
4
|
export { FormCollection } from './form_collection';
|
|
6
|
-
export {
|
|
7
|
-
export { Session } from './session';
|
|
5
|
+
export { Query } from './query';
|
|
6
|
+
export { Session } from './session';
|
|
7
|
+
export { Webchat } from './webchat';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hellotext/hellotext",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.3",
|
|
4
4
|
"description": "Hellotext JavaScript Client",
|
|
5
5
|
"source": "src/index.js",
|
|
6
6
|
"main": "lib/index.cjs",
|
|
@@ -91,6 +91,7 @@
|
|
|
91
91
|
"url": "https://github.com/hellotext/hellotext.js/issues"
|
|
92
92
|
},
|
|
93
93
|
"dependencies": {
|
|
94
|
+
"@emoji-mart/data": "^1.2.1",
|
|
94
95
|
"@floating-ui/dom": "^1.7.3",
|
|
95
96
|
"@hotwired/stimulus": "^3.0.0",
|
|
96
97
|
"emoji-mart": "^5.6.0"
|
package/src/api/forms.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { Configuration, Locale } from '../core'
|
|
1
2
|
import Hellotext from '../hellotext'
|
|
2
|
-
import { Configuration } from '../core'
|
|
3
3
|
|
|
4
4
|
import { Response } from './response'
|
|
5
5
|
|
|
@@ -10,7 +10,9 @@ export default class FormsAPI {
|
|
|
10
10
|
|
|
11
11
|
static async get(id) {
|
|
12
12
|
const url = new URL(`${this.endpoint}/${id}`)
|
|
13
|
+
|
|
13
14
|
url.searchParams.append('session', Hellotext.session)
|
|
15
|
+
url.searchParams.append('locale', Locale.toString())
|
|
14
16
|
|
|
15
17
|
return fetch(url, {
|
|
16
18
|
method: 'GET',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import Hellotext from '../../hellotext'
|
|
2
1
|
import { Configuration } from '../../core'
|
|
2
|
+
import Hellotext from '../../hellotext'
|
|
3
3
|
|
|
4
4
|
import { Response } from '../response'
|
|
5
5
|
|
|
@@ -31,19 +31,21 @@ class WebchatMessagesAPI {
|
|
|
31
31
|
headers: {
|
|
32
32
|
Authorization: `Bearer ${Hellotext.business.id}`,
|
|
33
33
|
},
|
|
34
|
-
body: formData
|
|
34
|
+
body: formData,
|
|
35
35
|
})
|
|
36
36
|
|
|
37
37
|
return new Response(response.ok, response)
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
markAsSeen() {
|
|
41
|
-
|
|
40
|
+
markAsSeen(messageId = null) {
|
|
41
|
+
const url = messageId ? this.url + `/${messageId}` : this.url + '/seen'
|
|
42
|
+
|
|
43
|
+
fetch(url, {
|
|
42
44
|
method: 'PATCH',
|
|
43
45
|
headers: Hellotext.headers,
|
|
44
46
|
body: JSON.stringify({
|
|
45
|
-
session: Hellotext.session
|
|
46
|
-
})
|
|
47
|
+
session: Hellotext.session,
|
|
48
|
+
}),
|
|
47
49
|
})
|
|
48
50
|
}
|
|
49
51
|
|
package/src/api/webchats.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Configuration } from '../core'
|
|
1
|
+
import { Configuration, Locale } from '../core'
|
|
2
2
|
import Hellotext from '../hellotext'
|
|
3
3
|
|
|
4
4
|
class WebchatsAPI {
|
|
@@ -10,6 +10,7 @@ class WebchatsAPI {
|
|
|
10
10
|
const url = new URL(`${this.endpoint}/${id}`)
|
|
11
11
|
|
|
12
12
|
url.searchParams.append('session', Hellotext.session)
|
|
13
|
+
url.searchParams.append('locale', Locale.toString())
|
|
13
14
|
|
|
14
15
|
Object.entries(Configuration.webchat.style).forEach(([key, value]) => {
|
|
15
16
|
url.searchParams.append(`style[${key}]`, value)
|
|
@@ -26,6 +27,7 @@ class WebchatsAPI {
|
|
|
26
27
|
|
|
27
28
|
if (!Hellotext.business.data) {
|
|
28
29
|
Hellotext.business.setData(data.business)
|
|
30
|
+
Hellotext.business.setLocale(data.locale)
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
return new DOMParser().parseFromString(data.html, 'text/html').querySelector('article')
|
|
@@ -14,7 +14,7 @@ class LogoBuilder {
|
|
|
14
14
|
return `
|
|
15
15
|
<div data-logo-container>
|
|
16
16
|
<small>${Hellotext.business.locale.white_label.powered_by}</small>
|
|
17
|
-
|
|
17
|
+
|
|
18
18
|
<a href="${url}" rel="noreferrer" target="_blank">
|
|
19
19
|
<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">
|
|
20
20
|
<title>Hellotext</title>
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
+
import { autoPlacement, offset, shift } from '@floating-ui/dom'
|
|
1
2
|
import { Controller } from '@hotwired/stimulus'
|
|
2
|
-
|
|
3
|
+
|
|
4
|
+
import en from '@emoji-mart/data/i18n/en.json'
|
|
5
|
+
import es from '@emoji-mart/data/i18n/es.json'
|
|
3
6
|
|
|
4
7
|
import { Picker } from 'emoji-mart'
|
|
5
8
|
|
|
6
9
|
import { usePopover } from '../mixins/usePopover'
|
|
7
10
|
|
|
8
11
|
export default class extends Controller {
|
|
9
|
-
static targets = [
|
|
10
|
-
'button',
|
|
11
|
-
'popover',
|
|
12
|
-
]
|
|
12
|
+
static targets = ['button', 'popover']
|
|
13
13
|
|
|
14
14
|
static values = {
|
|
15
|
-
placement: { type: String, default:
|
|
15
|
+
placement: { type: String, default: 'bottom-end' },
|
|
16
16
|
open: { type: Boolean, default: false },
|
|
17
17
|
autoPlacement: { type: Boolean, default: false },
|
|
18
18
|
disabled: { type: Boolean, default: false },
|
|
19
19
|
size: { type: Number, default: 24 },
|
|
20
|
-
perLine: { type: Number, default: 9 }
|
|
20
|
+
perLine: { type: Number, default: 9 },
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
initialize() {
|
|
@@ -62,13 +62,7 @@ export default class extends Controller {
|
|
|
62
62
|
skinTonePosition: 'none',
|
|
63
63
|
emojiSize: this.sizeValue,
|
|
64
64
|
perLine: this.perLineValue,
|
|
65
|
-
|
|
66
|
-
const response = await fetch(
|
|
67
|
-
'https://cdn.jsdelivr.net/npm/@emoji-mart/data',
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
return response.json()
|
|
71
|
-
}
|
|
65
|
+
i18n: Hellotext.business.locale === 'es' ? es : en,
|
|
72
66
|
})
|
|
73
67
|
}
|
|
74
68
|
|
|
@@ -76,7 +70,7 @@ export default class extends Controller {
|
|
|
76
70
|
return [
|
|
77
71
|
offset(5),
|
|
78
72
|
shift({ padding: 24 }),
|
|
79
|
-
autoPlacement({ allowedPlacements: ['top', 'bottom'
|
|
73
|
+
autoPlacement({ allowedPlacements: ['top', 'bottom'] }),
|
|
80
74
|
]
|
|
81
75
|
}
|
|
82
76
|
}
|