@hellotext/hellotext 2.1.2 → 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.
Files changed (44) hide show
  1. package/dist/hellotext.js +1 -1
  2. package/lib/api/forms.cjs +2 -1
  3. package/lib/api/forms.js +2 -1
  4. package/lib/api/webchat/messages.cjs +4 -3
  5. package/lib/api/webchat/messages.js +4 -2
  6. package/lib/api/webchats.cjs +2 -0
  7. package/lib/api/webchats.js +3 -1
  8. package/lib/builders/logo_builder.cjs +1 -1
  9. package/lib/builders/logo_builder.js +1 -1
  10. package/lib/controllers/webchat/emoji_picker_controller.cjs +6 -6
  11. package/lib/controllers/webchat/emoji_picker_controller.js +5 -14
  12. package/lib/controllers/webchat_controller.cjs +34 -6
  13. package/lib/controllers/webchat_controller.js +34 -6
  14. package/lib/core/configuration/locale.cjs +87 -0
  15. package/lib/core/configuration/locale.js +81 -0
  16. package/lib/core/configuration.cjs +10 -0
  17. package/lib/core/configuration.js +10 -0
  18. package/lib/core/index.cjs +15 -1
  19. package/lib/core/index.js +4 -2
  20. package/lib/locales/en.cjs +1 -1
  21. package/lib/locales/en.js +1 -1
  22. package/lib/locales/es.cjs +1 -1
  23. package/lib/locales/es.js +1 -1
  24. package/lib/models/business.cjs +11 -0
  25. package/lib/models/business.js +11 -0
  26. package/lib/models/form_collection.cjs +1 -0
  27. package/lib/models/form_collection.js +2 -1
  28. package/lib/models/index.cjs +4 -4
  29. package/lib/models/index.js +4 -4
  30. package/package.json +2 -1
  31. package/src/api/forms.js +3 -1
  32. package/src/api/webchat/messages.js +8 -6
  33. package/src/api/webchats.js +3 -1
  34. package/src/builders/logo_builder.js +1 -1
  35. package/src/controllers/webchat/emoji_picker_controller.js +9 -15
  36. package/src/controllers/webchat_controller.js +32 -10
  37. package/src/core/configuration/locale.js +50 -0
  38. package/src/core/configuration.js +10 -0
  39. package/src/core/index.js +3 -1
  40. package/src/locales/en.js +4 -4
  41. package/src/locales/es.js +4 -4
  42. package/src/models/business.js +12 -0
  43. package/src/models/form_collection.js +2 -1
  44. package/src/models/index.js +3 -3
@@ -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) {
@@ -15,6 +15,20 @@ Object.defineProperty(exports, "Event", {
15
15
  return _event.default;
16
16
  }
17
17
  });
18
- var _event = _interopRequireDefault(require("./event"));
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 { default as Event } from './event';
2
- export { Configuration } from './configuration';
1
+ export { Configuration } from './configuration';
2
+ export { Locale } from './configuration/locale';
3
+ export { Webchat } from './configuration/webchat';
4
+ export { default as Event } from './event';
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _default = {
8
8
  white_label: {
9
- powered_by: 'Powered by'
9
+ powered_by: 'By'
10
10
  },
11
11
  errors: {
12
12
  parameter_not_unique: 'This value is taken.',
package/lib/locales/en.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export default {
2
2
  white_label: {
3
- powered_by: 'Powered by'
3
+ powered_by: 'By'
4
4
  },
5
5
  errors: {
6
6
  parameter_not_unique: 'This value is taken.',
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _default = {
8
8
  white_label: {
9
- powered_by: 'Desarrollado por'
9
+ powered_by: 'Por'
10
10
  },
11
11
  errors: {
12
12
  parameter_not_unique: 'Este valor ya está en uso.',
package/lib/locales/es.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export default {
2
2
  white_label: {
3
- powered_by: 'Desarrollado por'
3
+ powered_by: 'Por'
4
4
  },
5
5
  errors: {
6
6
  parameter_not_unique: 'Este valor ya está en uso.',
@@ -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 () {
@@ -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.');
@@ -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 _webchat = require("./webchat");
54
- var _session = require("./session");
52
+ var _query = require("./query");
53
+ var _session = require("./session");
54
+ var _webchat = require("./webchat");
@@ -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 { Webchat } from './webchat';
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.2",
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
- fetch(this.url + '/seen', {
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
 
@@ -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
- import { computePosition, autoUpdate, shift, autoPlacement, offset } from '@floating-ui/dom'
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: "bottom-end" },
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
- data: async () => {
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
  }
@@ -5,6 +5,7 @@ import WebchatMessagesAPI from '../api/webchat/messages'
5
5
  import WebchatChannel from '../channels/webchat_channel'
6
6
  import Hellotext from '../hellotext'
7
7
 
8
+ import { Locale } from '../core'
8
9
  import { Webchat as WebchatConfiguration, behaviors } from '../core/configuration/webchat'
9
10
 
10
11
  import { LogoBuilder } from '../builders/logo_builder'
@@ -21,8 +22,11 @@ export default class extends Controller {
21
22
  autoPlacement: { type: Boolean, default: false },
22
23
  disabled: { type: Boolean, default: false },
23
24
  nextPage: { type: Number, default: undefined },
25
+ fullScreenThreshold: { type: Number, default: 1024 },
24
26
  }
25
27
 
28
+ static classes = ['fadeOut']
29
+
26
30
  static targets = [
27
31
  'trigger',
28
32
  'popover',
@@ -88,7 +92,7 @@ export default class extends Controller {
88
92
  this.toolbarTarget.appendChild(LogoBuilder.build())
89
93
  }
90
94
 
91
- if (localStorage.getItem(`hellotext--webchat--${this.idValue}`) === 'opened') {
95
+ if (this.shouldOpenOnMount) {
92
96
  this.openValue = true
93
97
  }
94
98
 
@@ -205,8 +209,18 @@ export default class extends Controller {
205
209
  }
206
210
  }
207
211
 
212
+ closePopover() {
213
+ this.popoverTarget.classList.add(...this.fadeOutClasses)
214
+
215
+ setTimeout(() => {
216
+ this.openValue = false
217
+ }, 250)
218
+ }
219
+
208
220
  onPopoverOpened() {
209
- this.inputTarget.focus()
221
+ if (!this.onMobile) {
222
+ this.inputTarget.focus()
223
+ }
210
224
 
211
225
  if (!this.scrolled) {
212
226
  requestAnimationFrame(() => {
@@ -220,7 +234,6 @@ export default class extends Controller {
220
234
  }
221
235
 
222
236
  Hellotext.eventEmitter.dispatch('webchat:opened')
223
-
224
237
  localStorage.setItem(`hellotext--webchat--${this.idValue}`, 'opened')
225
238
 
226
239
  if (this.unreadCounterTarget.style.display === 'none') return
@@ -233,11 +246,6 @@ export default class extends Controller {
233
246
 
234
247
  onPopoverClosed() {
235
248
  Hellotext.eventEmitter.dispatch('webchat:closed')
236
-
237
- setTimeout(() => {
238
- this.inputTarget.value = ''
239
- })
240
-
241
249
  localStorage.setItem(`hellotext--webchat--${this.idValue}`, 'closed')
242
250
  }
243
251
 
@@ -266,7 +274,7 @@ export default class extends Controller {
266
274
  }
267
275
 
268
276
  onMessageReceived(message) {
269
- const { body, attachments } = message
277
+ const { id, body, attachments } = message
270
278
 
271
279
  const div = document.createElement('div')
272
280
  div.innerHTML = body
@@ -297,7 +305,10 @@ export default class extends Controller {
297
305
  element.scrollIntoView({ behavior: 'smooth' })
298
306
  this.setOfflineTimeout()
299
307
 
300
- if (this.openValue) return
308
+ if (this.openValue) {
309
+ this.messagesAPI.markAsSeen(id)
310
+ return
311
+ }
301
312
 
302
313
  this.unreadCounterTarget.style.display = 'flex'
303
314
 
@@ -345,6 +356,7 @@ export default class extends Controller {
345
356
  })
346
357
 
347
358
  formData.append('session', Hellotext.session)
359
+ formData.append('locale', Locale.toString())
348
360
 
349
361
  const element = this.messageTemplateTarget.cloneNode(true)
350
362
 
@@ -541,4 +553,14 @@ export default class extends Controller {
541
553
  get middlewares() {
542
554
  return [offset(5), shift({ padding: 24 }), flip()]
543
555
  }
556
+
557
+ get shouldOpenOnMount() {
558
+ return (
559
+ localStorage.getItem(`hellotext--webchat--${this.idValue}`) === 'opened' && !this.onMobile
560
+ )
561
+ }
562
+
563
+ get onMobile() {
564
+ return window.matchMedia(`(max-width: ${this.fullScreenThresholdValue}px)`).matches
565
+ }
544
566
  }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @class Locale
3
+ * @classdesc
4
+ * Handles locale detection and configuration for the Hellotext library.
5
+ * Provides automatic locale detection from HTML lang attribute, meta tags,
6
+ * and browser language with fallback to 'en'.
7
+ */
8
+ class Locale {
9
+ static _identifier
10
+
11
+ /**
12
+ * Sets the locale identifier explicitly.
13
+ * @param {string} value - The locale identifier (e.g., 'en', 'es')
14
+ */
15
+ static set identifier(value) {
16
+ this._identifier = value
17
+ }
18
+
19
+ /**
20
+ * Gets the effective locale identifier.
21
+ * Falls back to auto-detection if not explicitly set.
22
+ * @returns {string} The locale identifier
23
+ */
24
+ static get identifier() {
25
+ if (this._identifier) return this._identifier
26
+ return this.#fromHtmlLangProperty || this.#fromMetaTag || this.#fromBrowserLanguage || 'en'
27
+ }
28
+
29
+ /**
30
+ * Returns the locale identifier as a string.
31
+ * @returns {string} The locale identifier
32
+ */
33
+ static toString() {
34
+ return this.identifier
35
+ }
36
+
37
+ static get #fromHtmlLangProperty() {
38
+ return document?.documentElement?.lang
39
+ }
40
+
41
+ static get #fromMetaTag() {
42
+ return document?.querySelector('meta[name="locale"]')?.content
43
+ }
44
+
45
+ static get #fromBrowserLanguage() {
46
+ return navigator?.language?.split('-')[0] // Extract primary language
47
+ }
48
+ }
49
+
50
+ export { Locale }
@@ -1,4 +1,5 @@
1
1
  import { Forms } from './configuration/forms'
2
+ import { Locale } from './configuration/locale'
2
3
  import { Webchat } from './configuration/webchat'
3
4
 
4
5
  /**
@@ -9,6 +10,7 @@ import { Webchat } from './configuration/webchat'
9
10
  * @property {String} [session] - session id
10
11
  * @property {Forms} [forms] - form configuration
11
12
  * @property {Webchat} [webchat] - webchat configuration
13
+ * @property {Locale} [locale] - locale configuration
12
14
  */
13
15
  class Configuration {
14
16
  static apiRoot = 'https://api.hellotext.com/v1'
@@ -43,6 +45,14 @@ class Configuration {
43
45
  return this
44
46
  }
45
47
 
48
+ static set locale(locale) {
49
+ Locale.identifier = locale
50
+ }
51
+
52
+ static get locale() {
53
+ return Locale.toString()
54
+ }
55
+
46
56
  static endpoint(path) {
47
57
  return `${this.apiRoot}/${path}`
48
58
  }
package/src/core/index.js CHANGED
@@ -1,2 +1,4 @@
1
- export { default as Event } from './event'
2
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/src/locales/en.js CHANGED
@@ -1,15 +1,15 @@
1
1
  export default {
2
2
  white_label: {
3
- powered_by: 'Powered by',
3
+ powered_by: 'By',
4
4
  },
5
5
  errors: {
6
6
  parameter_not_unique: 'This value is taken.',
7
- blank: 'This field is required.'
7
+ blank: 'This field is required.',
8
8
  },
9
9
  forms: {
10
10
  phone: 'Click the link sent via SMS to verify your submission.',
11
11
  email: 'Click the link sent via email to verify your submission.',
12
12
  phone_and_email: 'Click the links sent via SMS and email to verify your submission.',
13
- none: 'Your submission has been received.'
14
- }
13
+ none: 'Your submission has been received.',
14
+ },
15
15
  }
package/src/locales/es.js CHANGED
@@ -1,15 +1,15 @@
1
1
  export default {
2
2
  white_label: {
3
- powered_by: 'Desarrollado por',
3
+ powered_by: 'Por',
4
4
  },
5
5
  errors: {
6
6
  parameter_not_unique: 'Este valor ya está en uso.',
7
- blank: 'Este campo es obligatorio.'
7
+ blank: 'Este campo es obligatorio.',
8
8
  },
9
9
  forms: {
10
10
  phone: 'Haga clic en el enlace enviado por SMS para verificar su envío.',
11
11
  email: 'Haga clic en el enlace enviado por e-mail para verificar su envío.',
12
12
  phone_and_email: 'Haga clic en los enlaces enviados por SMS y e-mail para verificar su envío.',
13
- none: 'Su envío ha sido recibido.'
14
- }
13
+ none: 'Su envío ha sido recibido.',
14
+ },
15
15
  }
@@ -30,6 +30,18 @@ class Business {
30
30
  return this.data.whitelist !== 'disabled'
31
31
  }
32
32
 
33
+ setLocale(locale) {
34
+ if (!locales[locale]) {
35
+ return console.warn(`Locale ${locale} not found`)
36
+ }
37
+
38
+ if (!this.data) {
39
+ this.data = {}
40
+ }
41
+
42
+ this.data.locale = locale
43
+ }
44
+
33
45
  get locale() {
34
46
  return locales[this.data.locale]
35
47
  }
@@ -1,7 +1,7 @@
1
1
  import API from '../api/forms'
2
2
  import Hellotext from '../hellotext'
3
3
 
4
- import { Configuration } from '../core'
4
+ import { Configuration, Locale } from '../core'
5
5
  import { Form } from './form'
6
6
 
7
7
  import { NotInitializedError } from '../errors'
@@ -84,6 +84,7 @@ class FormCollection {
84
84
 
85
85
  if (!Hellotext.business.data) {
86
86
  Hellotext.business.setData(data.business)
87
+ Hellotext.business.setLocale(Locale.toString())
87
88
  }
88
89
 
89
90
  if (!Hellotext.business.enabledWhitelist) {
@@ -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 { Webchat } from './webchat'
5
+ export { Query } from './query'
7
6
  export { Session } from './session'
7
+ export { Webchat } from './webchat'