@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.
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 +63 -15
  13. package/lib/controllers/webchat_controller.js +63 -15
  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 +69 -19
  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
package/lib/api/forms.cjs CHANGED
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _hellotext = _interopRequireDefault(require("../hellotext"));
8
7
  var _core = require("../core");
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
11
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -27,6 +27,7 @@ let FormsAPI = /*#__PURE__*/function () {
27
27
  value: async function get(id) {
28
28
  const url = new URL(`${this.endpoint}/${id}`);
29
29
  url.searchParams.append('session', _hellotext.default.session);
30
+ url.searchParams.append('locale', _core.Locale.toString());
30
31
  return fetch(url, {
31
32
  method: 'GET',
32
33
  headers: _hellotext.default.headers
package/lib/api/forms.js CHANGED
@@ -8,8 +8,8 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
8
8
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
9
9
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
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
+ import { Configuration, Locale } from '../core';
11
12
  import Hellotext from '../hellotext';
12
- import { Configuration } from '../core';
13
13
  import { Response } from './response';
14
14
  var FormsAPI = /*#__PURE__*/function () {
15
15
  function FormsAPI() {
@@ -26,6 +26,7 @@ var FormsAPI = /*#__PURE__*/function () {
26
26
  var _get = _asyncToGenerator(function* (id) {
27
27
  var url = new URL("".concat(this.endpoint, "/").concat(id));
28
28
  url.searchParams.append('session', Hellotext.session);
29
+ url.searchParams.append('locale', Locale.toString());
29
30
  return fetch(url, {
30
31
  method: 'GET',
31
32
  headers: Hellotext.headers
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _hellotext = _interopRequireDefault(require("../../hellotext"));
8
7
  var _core = require("../../core");
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
11
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -44,8 +44,9 @@ let WebchatMessagesAPI = /*#__PURE__*/function () {
44
44
  }
45
45
  }, {
46
46
  key: "markAsSeen",
47
- value: function markAsSeen() {
48
- fetch(this.url + '/seen', {
47
+ value: function markAsSeen(messageId = null) {
48
+ const url = messageId ? this.url + `/${messageId}` : this.url + '/seen';
49
+ fetch(url, {
49
50
  method: 'PATCH',
50
51
  headers: _hellotext.default.headers,
51
52
  body: JSON.stringify({
@@ -5,8 +5,8 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
5
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
6
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
7
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 Hellotext from '../../hellotext';
9
8
  import { Configuration } from '../../core';
9
+ import Hellotext from '../../hellotext';
10
10
  import { Response } from '../response';
11
11
  var WebchatMessagesAPI = /*#__PURE__*/function () {
12
12
  function WebchatMessagesAPI(webchatId) {
@@ -53,7 +53,9 @@ var WebchatMessagesAPI = /*#__PURE__*/function () {
53
53
  }, {
54
54
  key: "markAsSeen",
55
55
  value: function markAsSeen() {
56
- fetch(this.url + '/seen', {
56
+ var messageId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
57
+ var url = messageId ? this.url + "/".concat(messageId) : this.url + '/seen';
58
+ fetch(url, {
57
59
  method: 'PATCH',
58
60
  headers: Hellotext.headers,
59
61
  body: JSON.stringify({
@@ -26,6 +26,7 @@ let WebchatsAPI = /*#__PURE__*/function () {
26
26
  value: async function get(id) {
27
27
  const url = new URL(`${this.endpoint}/${id}`);
28
28
  url.searchParams.append('session', _hellotext.default.session);
29
+ url.searchParams.append('locale', _core.Locale.toString());
29
30
  Object.entries(_core.Configuration.webchat.style).forEach(([key, value]) => {
30
31
  url.searchParams.append(`style[${key}]`, value);
31
32
  });
@@ -37,6 +38,7 @@ let WebchatsAPI = /*#__PURE__*/function () {
37
38
  const data = await response.json();
38
39
  if (!_hellotext.default.business.data) {
39
40
  _hellotext.default.business.setData(data.business);
41
+ _hellotext.default.business.setLocale(data.locale);
40
42
  }
41
43
  return new DOMParser().parseFromString(data.html, 'text/html').querySelector('article');
42
44
  }
@@ -5,7 +5,7 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
5
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
6
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
7
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 } from '../core';
8
+ import { Configuration, Locale } from '../core';
9
9
  import Hellotext from '../hellotext';
10
10
  var WebchatsAPI = /*#__PURE__*/function () {
11
11
  function WebchatsAPI() {
@@ -22,6 +22,7 @@ var WebchatsAPI = /*#__PURE__*/function () {
22
22
  var _get = _asyncToGenerator(function* (id) {
23
23
  var url = new URL("".concat(this.endpoint, "/").concat(id));
24
24
  url.searchParams.append('session', Hellotext.session);
25
+ url.searchParams.append('locale', Locale.toString());
25
26
  Object.entries(Configuration.webchat.style).forEach(_ref => {
26
27
  var [key, value] = _ref;
27
28
  url.searchParams.append("style[".concat(key, "]"), value);
@@ -34,6 +35,7 @@ var WebchatsAPI = /*#__PURE__*/function () {
34
35
  var data = yield response.json();
35
36
  if (!Hellotext.business.data) {
36
37
  Hellotext.business.setData(data.business);
38
+ Hellotext.business.setLocale(data.locale);
37
39
  }
38
40
  return new DOMParser().parseFromString(data.html, 'text/html').querySelector('article');
39
41
  });
@@ -35,7 +35,7 @@ function _template2() {
35
35
  return `
36
36
  <div data-logo-container>
37
37
  <small>${_hellotext.default.business.locale.white_label.powered_by}</small>
38
-
38
+
39
39
  <a href="${url}" rel="noreferrer" target="_blank">
40
40
  <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">
41
41
  <title>Hellotext</title>
@@ -24,7 +24,7 @@ var LogoBuilder = /*#__PURE__*/function () {
24
24
  }();
25
25
  function _template2() {
26
26
  var url = "https://www.hellotext.com?hello_session=".concat(Hellotext.session);
27
- return "\n <div data-logo-container>\n <small>".concat(Hellotext.business.locale.white_label.powered_by, "</small>\n \n <a href=\"").concat(url, "\" rel=\"noreferrer\" target=\"_blank\">\n <svg data-hello-brand viewBox=\"0 0 224 43\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <title>Hellotext</title>\n <path d=\"M28.2760919,19.3224299 L28.2760919,31.1946615 C28.2760919,32.2088722 27.5005873,32.9844452 26.4864658,32.9844452 L21.0579334,32.9844452 C20.043812,32.9844452 19.2683073,32.2088722 19.2683073,31.1946615 L19.2683073,19.9786839 C19.2683073,16.7570733 17.4190271,14.7883113 14.4959712,14.7883113 C11.0360274,14.7883113 8.76916774,17.11503 8.76916774,21.1122135 L8.76916774,31.3139804 C8.76916774,32.3281911 7.99366311,33.1037641 6.97954167,33.1037641 L1.78962607,33.1037641 C0.77550463,33.1037641 0,32.3281911 0,31.3139804 L0,3.45301476 C0,2.43880402 0.77550463,1.6632311 1.78962607,1.6632311 L6.97954167,1.6632311 C7.99366311,1.6632311 8.76916774,2.43880402 8.76916774,3.45301476 L8.76916774,9.06100356 L8.11297151,16.3991166 L8.70951354,16.458776 C9.78328918,11.6860196 13.5415039,8.52406846 18.4331485,8.52406846 C24.3389145,8.52406846 28.2760919,12.8195492 28.2760919,19.3224299 Z M61.1455574,26.3622456 C58.9980061,30.7173858 53.6291279,33.5213803 47.0671656,33.5213803 C37.9997269,33.5213803 31.4377646,28.2116887 31.4377646,20.7542568 C31.4377646,13.6547816 37.2838764,8.52406846 46.0530442,8.52406846 C53.7484363,8.52406846 59.1769687,12.4615925 59.8928191,18.8451542 C60.0121275,19.9190244 59.1769687,20.8735757 58.103193,20.8735757 L40.1472781,20.8735757 C40.4455492,24.8110998 43.1299883,27.2571374 47.186474,27.2571374 C50.2288383,27.2571374 52.8536232,25.7656511 54.1660157,23.4389323 C54.5835951,22.6633594 55.5380623,22.3054026 56.3732212,22.6036999 L60.1314359,23.9758674 C61.0859032,24.2741647 61.622791,25.4076943 61.1455574,26.3622456 Z M40.5648576,17.3536679 L50.706072,17.2343489 C50.0498757,14.7286518 48.3795581,13.5354627 45.8740816,13.5354627 C43.3089509,13.5354627 41.4000164,14.9672896 40.5648576,17.3536679 Z M120.143563,20.9928946 C120.143563,28.2116887 113.641255,33.4617208 104.693125,33.4617208 C95.8046489,33.4617208 89.361995,28.2116887 89.361995,20.9928946 C89.361995,13.7741005 95.8046489,8.52406846 104.693125,8.52406846 C113.641255,8.52406846 120.143563,13.7741005 120.143563,20.9928946 Z M111.076125,21.1122135 C111.076125,17.2940084 108.45134,14.7883113 104.633471,14.7883113 C100.93491,14.7883113 98.3697796,17.2940084 98.3697796,20.9332352 C98.3697796,24.7514403 100.994564,27.2571374 104.812433,27.2571374 C108.570648,27.2571374 111.076125,24.7514403 111.076125,21.1122135 Z M141.559422,26.8395213 C141.261151,25.5866727 139.82945,25.0497376 138.815329,25.8253105 C137.443282,26.8395213 136.190544,27.2571374 134.99746,27.2571374 C132.909563,27.2571374 131.835787,26.0042889 131.835787,23.796889 L131.835787,13.9530789 L139.471525,13.9530789 C140.24703,13.9530789 140.903226,13.2968249 140.903226,12.521252 L140.903226,10.4928305 C140.903226,9.71725757 140.24703,9.06100356 139.471525,9.06100356 L131.835787,9.06100356 L131.835787,3.45301476 C131.835787,2.43880402 131.060282,1.6632311 130.046161,1.6632311 L125.214171,1.6632311 C124.200049,1.6632311 123.424545,2.43880402 123.424545,3.45301476 L123.424545,9.06100356 L123.424545,13.9530789 L123.424545,24.7514403 C123.424545,30.2401102 127.182759,33.5213803 133.565759,33.5213803 C136.727432,33.5213803 139.471525,32.6861479 141.499768,31.0753426 C142.036656,30.6577264 142.275272,29.9418129 142.09631,29.2855589 L141.559422,26.8395213 Z M173.414766,26.3622456 C171.267215,30.7173858 165.898337,33.5213803 159.336374,33.5213803 C150.268936,33.5213803 143.706973,28.2116887 143.706973,20.7542568 C143.706973,13.6547816 149.553085,8.52406846 158.322253,8.52406846 C166.017645,8.52406846 171.446177,12.4615925 172.162028,18.8451542 C172.281336,19.9190244 171.446177,20.8735757 170.372402,20.8735757 L152.416487,20.8735757 C152.714758,24.8110998 155.399197,27.2571374 159.455683,27.2571374 C162.498047,27.2571374 165.122832,25.7656511 166.435224,23.4389323 C166.852804,22.6633594 167.807271,22.3054026 168.64243,22.6036999 L172.400645,23.9758674 C173.414766,24.2741647 173.892,25.4076943 173.414766,26.3622456 Z M152.834066,17.3536679 L162.975281,17.2343489 C162.319084,14.7286518 160.648767,13.5354627 158.14329,13.5354627 C155.637814,13.5354627 153.669225,14.9672896 152.834066,17.3536679 Z M192.862036,20.8139163 L201.094316,12.0439763 C202.168092,10.9104467 201.332933,9.00134411 199.781923,9.00134411 L194.711316,9.00134411 C194.174428,9.00134411 193.637541,9.23998193 193.279615,9.71725757 L188.507279,15.8621815 L183.734943,9.71725757 C183.377018,9.29964138 182.899784,9.00134411 182.303242,9.00134411 L177.113327,9.00134411 C175.562317,9.00134411 174.727159,10.8507872 175.800934,12.0439763 L184.092868,20.8735757 L175.502663,30.0014724 C174.428888,31.135002 175.204392,33.0441046 176.815056,33.0441046 L181.945317,33.0441046 C182.482205,33.0441046 183.019093,32.8054668 183.377018,32.3878506 L188.447625,25.9446294 L193.577886,32.3878506 C193.935812,32.8054668 194.413045,33.0441046 194.949933,33.0441046 L200.139849,33.0441046 C201.690858,33.0441046 202.526017,31.1946615 201.452241,30.0611318 L192.862036,20.8139163 Z M223.941875,29.2258995 L223.345333,26.8395213 C223.047062,25.5866727 221.615362,25.0497376 220.60124,25.8253105 C219.229193,26.8395213 217.976455,27.2571374 216.783371,27.2571374 C214.695474,27.2571374 213.621698,26.0042889 213.621698,23.796889 L213.621698,13.9530789 L221.257436,13.9530789 C222.032941,13.9530789 222.689137,13.2968249 222.689137,12.521252 L222.689137,10.4928305 C222.689137,9.71725757 222.032941,9.06100356 221.257436,9.06100356 L213.621698,9.06100356 L213.621698,3.45301476 C213.621698,2.43880402 212.846194,1.6632311 211.832072,1.6632311 L207.000082,1.6632311 C205.985961,1.6632311 205.210456,2.43880402 205.210456,3.45301476 L205.210456,9.06100356 L205.210456,13.9530789 L205.210456,24.7514403 C205.210456,30.2401102 208.968671,33.5213803 215.35167,33.5213803 C218.513343,33.5213803 221.257436,32.6861479 223.285679,31.0753426 C223.882221,30.5980669 224.120838,29.8821535 223.941875,29.2258995 Z M77.6697714,6.01837134 C78.2663134,5.30245788 78.2663134,4.22858768 77.6101172,3.57233367 L74.5677529,0.529701449 C73.8519024,-0.186212015 72.6588184,-0.186212015 71.942968,0.589360904 C61.3841742,12.4615925 61.3841742,30.5384075 71.942968,42.4106391 C72.5991642,43.186212 73.8519024,43.186212 74.5677529,42.4702986 L77.6101172,39.4276663 C78.2663134,38.7714123 78.3259676,37.6975421 77.6697714,36.9816287 C69.9147251,28.1520293 69.9147251,14.8479707 77.6697714,6.01837134 Z M87.1547896,10.6718089 L84.1124252,7.62917663 C83.3965748,6.91326317 82.1438366,6.91326317 81.4876403,7.74849554 C78.2663134,11.6263601 76.4766873,16.458776 76.4766873,21.5298297 C76.4766873,26.6008834 78.2663134,31.4332993 81.4876403,35.3111639 C82.1438366,36.0867368 83.3965748,36.1463963 84.1124252,35.4304828 L87.1547896,32.3878506 C87.8109858,31.7315966 87.87064,30.7173858 87.3337522,30.0611318 C85.4248177,27.6747536 84.351042,24.6917809 84.351042,21.5894892 C84.351042,18.4871975 85.3651635,15.5042247 87.3337522,13.1178465 C87.87064,12.3422736 87.8109858,11.3280629 87.1547896,10.6718089 Z\" id=\"hellotext\" fill=\"currentColor\"></path>\n </svg>\n </a>\n </div>\n ");
27
+ return "\n <div data-logo-container>\n <small>".concat(Hellotext.business.locale.white_label.powered_by, "</small>\n\n <a href=\"").concat(url, "\" rel=\"noreferrer\" target=\"_blank\">\n <svg data-hello-brand viewBox=\"0 0 224 43\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <title>Hellotext</title>\n <path d=\"M28.2760919,19.3224299 L28.2760919,31.1946615 C28.2760919,32.2088722 27.5005873,32.9844452 26.4864658,32.9844452 L21.0579334,32.9844452 C20.043812,32.9844452 19.2683073,32.2088722 19.2683073,31.1946615 L19.2683073,19.9786839 C19.2683073,16.7570733 17.4190271,14.7883113 14.4959712,14.7883113 C11.0360274,14.7883113 8.76916774,17.11503 8.76916774,21.1122135 L8.76916774,31.3139804 C8.76916774,32.3281911 7.99366311,33.1037641 6.97954167,33.1037641 L1.78962607,33.1037641 C0.77550463,33.1037641 0,32.3281911 0,31.3139804 L0,3.45301476 C0,2.43880402 0.77550463,1.6632311 1.78962607,1.6632311 L6.97954167,1.6632311 C7.99366311,1.6632311 8.76916774,2.43880402 8.76916774,3.45301476 L8.76916774,9.06100356 L8.11297151,16.3991166 L8.70951354,16.458776 C9.78328918,11.6860196 13.5415039,8.52406846 18.4331485,8.52406846 C24.3389145,8.52406846 28.2760919,12.8195492 28.2760919,19.3224299 Z M61.1455574,26.3622456 C58.9980061,30.7173858 53.6291279,33.5213803 47.0671656,33.5213803 C37.9997269,33.5213803 31.4377646,28.2116887 31.4377646,20.7542568 C31.4377646,13.6547816 37.2838764,8.52406846 46.0530442,8.52406846 C53.7484363,8.52406846 59.1769687,12.4615925 59.8928191,18.8451542 C60.0121275,19.9190244 59.1769687,20.8735757 58.103193,20.8735757 L40.1472781,20.8735757 C40.4455492,24.8110998 43.1299883,27.2571374 47.186474,27.2571374 C50.2288383,27.2571374 52.8536232,25.7656511 54.1660157,23.4389323 C54.5835951,22.6633594 55.5380623,22.3054026 56.3732212,22.6036999 L60.1314359,23.9758674 C61.0859032,24.2741647 61.622791,25.4076943 61.1455574,26.3622456 Z M40.5648576,17.3536679 L50.706072,17.2343489 C50.0498757,14.7286518 48.3795581,13.5354627 45.8740816,13.5354627 C43.3089509,13.5354627 41.4000164,14.9672896 40.5648576,17.3536679 Z M120.143563,20.9928946 C120.143563,28.2116887 113.641255,33.4617208 104.693125,33.4617208 C95.8046489,33.4617208 89.361995,28.2116887 89.361995,20.9928946 C89.361995,13.7741005 95.8046489,8.52406846 104.693125,8.52406846 C113.641255,8.52406846 120.143563,13.7741005 120.143563,20.9928946 Z M111.076125,21.1122135 C111.076125,17.2940084 108.45134,14.7883113 104.633471,14.7883113 C100.93491,14.7883113 98.3697796,17.2940084 98.3697796,20.9332352 C98.3697796,24.7514403 100.994564,27.2571374 104.812433,27.2571374 C108.570648,27.2571374 111.076125,24.7514403 111.076125,21.1122135 Z M141.559422,26.8395213 C141.261151,25.5866727 139.82945,25.0497376 138.815329,25.8253105 C137.443282,26.8395213 136.190544,27.2571374 134.99746,27.2571374 C132.909563,27.2571374 131.835787,26.0042889 131.835787,23.796889 L131.835787,13.9530789 L139.471525,13.9530789 C140.24703,13.9530789 140.903226,13.2968249 140.903226,12.521252 L140.903226,10.4928305 C140.903226,9.71725757 140.24703,9.06100356 139.471525,9.06100356 L131.835787,9.06100356 L131.835787,3.45301476 C131.835787,2.43880402 131.060282,1.6632311 130.046161,1.6632311 L125.214171,1.6632311 C124.200049,1.6632311 123.424545,2.43880402 123.424545,3.45301476 L123.424545,9.06100356 L123.424545,13.9530789 L123.424545,24.7514403 C123.424545,30.2401102 127.182759,33.5213803 133.565759,33.5213803 C136.727432,33.5213803 139.471525,32.6861479 141.499768,31.0753426 C142.036656,30.6577264 142.275272,29.9418129 142.09631,29.2855589 L141.559422,26.8395213 Z M173.414766,26.3622456 C171.267215,30.7173858 165.898337,33.5213803 159.336374,33.5213803 C150.268936,33.5213803 143.706973,28.2116887 143.706973,20.7542568 C143.706973,13.6547816 149.553085,8.52406846 158.322253,8.52406846 C166.017645,8.52406846 171.446177,12.4615925 172.162028,18.8451542 C172.281336,19.9190244 171.446177,20.8735757 170.372402,20.8735757 L152.416487,20.8735757 C152.714758,24.8110998 155.399197,27.2571374 159.455683,27.2571374 C162.498047,27.2571374 165.122832,25.7656511 166.435224,23.4389323 C166.852804,22.6633594 167.807271,22.3054026 168.64243,22.6036999 L172.400645,23.9758674 C173.414766,24.2741647 173.892,25.4076943 173.414766,26.3622456 Z M152.834066,17.3536679 L162.975281,17.2343489 C162.319084,14.7286518 160.648767,13.5354627 158.14329,13.5354627 C155.637814,13.5354627 153.669225,14.9672896 152.834066,17.3536679 Z M192.862036,20.8139163 L201.094316,12.0439763 C202.168092,10.9104467 201.332933,9.00134411 199.781923,9.00134411 L194.711316,9.00134411 C194.174428,9.00134411 193.637541,9.23998193 193.279615,9.71725757 L188.507279,15.8621815 L183.734943,9.71725757 C183.377018,9.29964138 182.899784,9.00134411 182.303242,9.00134411 L177.113327,9.00134411 C175.562317,9.00134411 174.727159,10.8507872 175.800934,12.0439763 L184.092868,20.8735757 L175.502663,30.0014724 C174.428888,31.135002 175.204392,33.0441046 176.815056,33.0441046 L181.945317,33.0441046 C182.482205,33.0441046 183.019093,32.8054668 183.377018,32.3878506 L188.447625,25.9446294 L193.577886,32.3878506 C193.935812,32.8054668 194.413045,33.0441046 194.949933,33.0441046 L200.139849,33.0441046 C201.690858,33.0441046 202.526017,31.1946615 201.452241,30.0611318 L192.862036,20.8139163 Z M223.941875,29.2258995 L223.345333,26.8395213 C223.047062,25.5866727 221.615362,25.0497376 220.60124,25.8253105 C219.229193,26.8395213 217.976455,27.2571374 216.783371,27.2571374 C214.695474,27.2571374 213.621698,26.0042889 213.621698,23.796889 L213.621698,13.9530789 L221.257436,13.9530789 C222.032941,13.9530789 222.689137,13.2968249 222.689137,12.521252 L222.689137,10.4928305 C222.689137,9.71725757 222.032941,9.06100356 221.257436,9.06100356 L213.621698,9.06100356 L213.621698,3.45301476 C213.621698,2.43880402 212.846194,1.6632311 211.832072,1.6632311 L207.000082,1.6632311 C205.985961,1.6632311 205.210456,2.43880402 205.210456,3.45301476 L205.210456,9.06100356 L205.210456,13.9530789 L205.210456,24.7514403 C205.210456,30.2401102 208.968671,33.5213803 215.35167,33.5213803 C218.513343,33.5213803 221.257436,32.6861479 223.285679,31.0753426 C223.882221,30.5980669 224.120838,29.8821535 223.941875,29.2258995 Z M77.6697714,6.01837134 C78.2663134,5.30245788 78.2663134,4.22858768 77.6101172,3.57233367 L74.5677529,0.529701449 C73.8519024,-0.186212015 72.6588184,-0.186212015 71.942968,0.589360904 C61.3841742,12.4615925 61.3841742,30.5384075 71.942968,42.4106391 C72.5991642,43.186212 73.8519024,43.186212 74.5677529,42.4702986 L77.6101172,39.4276663 C78.2663134,38.7714123 78.3259676,37.6975421 77.6697714,36.9816287 C69.9147251,28.1520293 69.9147251,14.8479707 77.6697714,6.01837134 Z M87.1547896,10.6718089 L84.1124252,7.62917663 C83.3965748,6.91326317 82.1438366,6.91326317 81.4876403,7.74849554 C78.2663134,11.6263601 76.4766873,16.458776 76.4766873,21.5298297 C76.4766873,26.6008834 78.2663134,31.4332993 81.4876403,35.3111639 C82.1438366,36.0867368 83.3965748,36.1463963 84.1124252,35.4304828 L87.1547896,32.3878506 C87.8109858,31.7315966 87.87064,30.7173858 87.3337522,30.0611318 C85.4248177,27.6747536 84.351042,24.6917809 84.351042,21.5894892 C84.351042,18.4871975 85.3651635,15.5042247 87.3337522,13.1178465 C87.87064,12.3422736 87.8109858,11.3280629 87.1547896,10.6718089 Z\" id=\"hellotext\" fill=\"currentColor\"></path>\n </svg>\n </a>\n </div>\n ");
28
28
  }
29
29
  Object.defineProperty(LogoBuilder, _template, {
30
30
  value: _template2
@@ -4,10 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _stimulus = require("@hotwired/stimulus");
8
7
  var _dom = require("@floating-ui/dom");
8
+ var _stimulus = require("@hotwired/stimulus");
9
+ var _en = _interopRequireDefault(require("@emoji-mart/data/i18n/en.json"));
10
+ var _es = _interopRequireDefault(require("@emoji-mart/data/i18n/es.json"));
9
11
  var _emojiMart = require("emoji-mart");
10
12
  var _usePopover = require("../mixins/usePopover");
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
14
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
12
15
  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); } }
13
16
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
@@ -78,10 +81,7 @@ let _default = /*#__PURE__*/function (_Controller) {
78
81
  skinTonePosition: 'none',
79
82
  emojiSize: this.sizeValue,
80
83
  perLine: this.perLineValue,
81
- data: async () => {
82
- const response = await fetch('https://cdn.jsdelivr.net/npm/@emoji-mart/data');
83
- return response.json();
84
- }
84
+ i18n: Hellotext.business.locale === 'es' ? _es.default : _en.default
85
85
  });
86
86
  }
87
87
  }, {
@@ -101,7 +101,7 @@ _default.targets = ['button', 'popover'];
101
101
  _default.values = {
102
102
  placement: {
103
103
  type: String,
104
- default: "bottom-end"
104
+ default: 'bottom-end'
105
105
  },
106
106
  open: {
107
107
  type: Boolean,
@@ -1,5 +1,3 @@
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
1
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
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); } }
5
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; }
@@ -14,8 +12,10 @@ function _possibleConstructorReturn(self, call) { if (call && (typeof call === "
14
12
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
15
13
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
16
14
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
15
+ import { autoPlacement, offset, shift } from '@floating-ui/dom';
17
16
  import { Controller } from '@hotwired/stimulus';
18
- import { computePosition, autoUpdate, shift, autoPlacement, offset } from '@floating-ui/dom';
17
+ import en from '@emoji-mart/data/i18n/en.json';
18
+ import es from '@emoji-mart/data/i18n/es.json';
19
19
  import { Picker } from 'emoji-mart';
20
20
  import { usePopover } from '../mixins/usePopover';
21
21
  var _default = /*#__PURE__*/function (_Controller) {
@@ -74,16 +74,7 @@ var _default = /*#__PURE__*/function (_Controller) {
74
74
  skinTonePosition: 'none',
75
75
  emojiSize: this.sizeValue,
76
76
  perLine: this.perLineValue,
77
- data: function () {
78
- var _data = _asyncToGenerator(function* () {
79
- var response = yield fetch('https://cdn.jsdelivr.net/npm/@emoji-mart/data');
80
- return response.json();
81
- });
82
- function data() {
83
- return _data.apply(this, arguments);
84
- }
85
- return data;
86
- }()
77
+ i18n: Hellotext.business.locale === 'es' ? es : en
87
78
  });
88
79
  }
89
80
  }, {
@@ -102,7 +93,7 @@ _default.targets = ['button', 'popover'];
102
93
  _default.values = {
103
94
  placement: {
104
95
  type: String,
105
- default: "bottom-end"
96
+ default: 'bottom-end'
106
97
  },
107
98
  open: {
108
99
  type: Boolean,
@@ -9,6 +9,7 @@ var _stimulus = require("@hotwired/stimulus");
9
9
  var _messages = _interopRequireDefault(require("../api/webchat/messages"));
10
10
  var _webchat_channel = _interopRequireDefault(require("../channels/webchat_channel"));
11
11
  var _hellotext = _interopRequireDefault(require("../hellotext"));
12
+ var _core = require("../core");
12
13
  var _webchat = require("../core/configuration/webchat");
13
14
  var _logo_builder = require("../builders/logo_builder");
14
15
  var _usePopover = require("./mixins/usePopover");
@@ -67,7 +68,7 @@ let _default = /*#__PURE__*/function (_Controller) {
67
68
  if (!_hellotext.default.business.features.white_label) {
68
69
  this.toolbarTarget.appendChild(_logo_builder.LogoBuilder.build());
69
70
  }
70
- if (localStorage.getItem(`hellotext--webchat--${this.idValue}`) === 'opened') {
71
+ if (this.shouldOpenOnMount) {
71
72
  this.openValue = true;
72
73
  }
73
74
  _hellotext.default.eventEmitter.dispatch('webchat:mounted');
@@ -164,14 +165,26 @@ let _default = /*#__PURE__*/function (_Controller) {
164
165
  this.openValue = false;
165
166
  }
166
167
  }
168
+ }, {
169
+ key: "closePopover",
170
+ value: function closePopover() {
171
+ this.popoverTarget.classList.add(...this.fadeOutClasses);
172
+ setTimeout(() => {
173
+ this.openValue = false;
174
+ }, 250);
175
+ }
167
176
  }, {
168
177
  key: "onPopoverOpened",
169
178
  value: function onPopoverOpened() {
170
- this.inputTarget.focus();
179
+ if (!this.onMobile) {
180
+ this.inputTarget.focus();
181
+ }
171
182
  if (!this.scrolled) {
172
- this.messagesContainerTarget.scroll({
173
- top: this.messagesContainerTarget.scrollHeight,
174
- behavior: 'instant'
183
+ requestAnimationFrame(() => {
184
+ this.messagesContainerTarget.scroll({
185
+ top: this.messagesContainerTarget.scrollHeight,
186
+ behavior: 'instant'
187
+ });
175
188
  });
176
189
  this.scrolled = true;
177
190
  }
@@ -186,9 +199,6 @@ let _default = /*#__PURE__*/function (_Controller) {
186
199
  key: "onPopoverClosed",
187
200
  value: function onPopoverClosed() {
188
201
  _hellotext.default.eventEmitter.dispatch('webchat:closed');
189
- setTimeout(() => {
190
- this.inputTarget.value = '';
191
- });
192
202
  localStorage.setItem(`hellotext--webchat--${this.idValue}`, 'closed');
193
203
  }
194
204
  }, {
@@ -219,6 +229,7 @@ let _default = /*#__PURE__*/function (_Controller) {
219
229
  key: "onMessageReceived",
220
230
  value: function onMessageReceived(message) {
221
231
  const {
232
+ id,
222
233
  body,
223
234
  attachments
224
235
  } = message;
@@ -245,7 +256,10 @@ let _default = /*#__PURE__*/function (_Controller) {
245
256
  behavior: 'smooth'
246
257
  });
247
258
  this.setOfflineTimeout();
248
- if (this.openValue) return;
259
+ if (this.openValue) {
260
+ this.messagesAPI.markAsSeen(id);
261
+ return;
262
+ }
249
263
  this.unreadCounterTarget.style.display = 'flex';
250
264
  const unreadCount = (parseInt(this.unreadCounterTarget.innerText) || 0) + 1;
251
265
  this.unreadCounterTarget.innerText = unreadCount > 99 ? '99+' : unreadCount;
@@ -277,17 +291,29 @@ let _default = /*#__PURE__*/function (_Controller) {
277
291
  body: this.inputTarget.value,
278
292
  attachments: this.files
279
293
  };
280
- formData.append('message[body]', this.inputTarget.value);
294
+ if (this.inputTarget.value.trim().length === 0 && this.files.length === 0) {
295
+ return;
296
+ }
297
+ if (this.inputTarget.value.trim().length > 0) {
298
+ formData.append('message[body]', this.inputTarget.value);
299
+ } else {
300
+ delete message.body;
301
+ }
281
302
  this.files.forEach(file => {
282
303
  formData.append('message[attachments][]', file);
283
304
  });
284
305
  formData.append('session', _hellotext.default.session);
306
+ formData.append('locale', _core.Locale.toString());
285
307
  const element = this.messageTemplateTarget.cloneNode(true);
286
308
  element.id = `hellotext--webchat--${this.idValue}--message--${Date.now()}`;
287
309
  element.classList.add('received');
288
310
  element.style.removeProperty('display');
289
311
  element.setAttribute('data-hellotext--webchat-target', 'message');
290
- element.querySelector('[data-body]').innerText = this.inputTarget.value;
312
+ if (this.inputTarget.value.trim().length > 0) {
313
+ element.querySelector('[data-body]').innerText = this.inputTarget.value;
314
+ } else {
315
+ element.querySelector('[data-message-bubble]').remove();
316
+ }
291
317
  const attachments = this.attachmentContainerTarget.querySelectorAll('img');
292
318
  if (attachments.length > 0) {
293
319
  attachments.forEach(attachment => {
@@ -304,6 +330,8 @@ let _default = /*#__PURE__*/function (_Controller) {
304
330
  });
305
331
  this.inputTarget.value = '';
306
332
  this.files = [];
333
+ this.attachmentInputTarget.value = '';
334
+ this.attachmentContainerTarget.innerHTML = '';
307
335
  this.attachmentContainerTarget.style.display = 'none';
308
336
  this.errorMessageContainerTarget.style.display = 'none';
309
337
  this.inputTarget.focus();
@@ -334,8 +362,9 @@ let _default = /*#__PURE__*/function (_Controller) {
334
362
  key: "onFileInputChange",
335
363
  value: function onFileInputChange() {
336
364
  this.errorMessageContainerTarget.style.display = 'none';
337
- this.files = Array.from(this.attachmentInputTarget.files);
338
- const fileMaxSizeTooMuch = this.files.find(file => {
365
+ const newFiles = Array.from(this.attachmentInputTarget.files);
366
+ this.attachmentInputTarget.value = '';
367
+ const fileMaxSizeTooMuch = newFiles.find(file => {
339
368
  const type = file.type.split('/')[0];
340
369
  if (['image', 'video', 'audio'].includes(type)) {
341
370
  return this.mediaValue[type].max_size < file.size;
@@ -347,10 +376,11 @@ let _default = /*#__PURE__*/function (_Controller) {
347
376
  const type = fileMaxSizeTooMuch.type.split('/')[0];
348
377
  const mediaType = ['image', 'audio', 'video'].includes(type) ? type : 'document';
349
378
  this.errorMessageContainerTarget.innerText = this.fileSizeErrorMessageValue.replace('%{limit}', this.byteToMegabyte(this.mediaValue[mediaType].max_size));
350
- return;
379
+ return this.errorMessageContainerTarget.style.display = 'block';
351
380
  }
381
+ this.files = [...this.files, ...newFiles];
352
382
  this.errorMessageContainerTarget.innerText = '';
353
- this.files.forEach(file => this.createAttachmentElement(file));
383
+ newFiles.forEach(file => this.createAttachmentElement(file));
354
384
  this.inputTarget.focus();
355
385
  }
356
386
  }, {
@@ -373,6 +403,8 @@ let _default = /*#__PURE__*/function (_Controller) {
373
403
  main.style.backgroundColor = '#e5e7eb';
374
404
  main.style.padding = '0.25rem';
375
405
  element.querySelector('p[data-attachment-name]').innerText = file.name;
406
+ this.attachmentContainerTarget.appendChild(element);
407
+ this.attachmentContainerTarget.style.display = 'flex';
376
408
  }
377
409
  }
378
410
  }, {
@@ -382,6 +414,7 @@ let _default = /*#__PURE__*/function (_Controller) {
382
414
  }) {
383
415
  const attachment = currentTarget.closest("[data-hellotext--webchat-target='attachment']");
384
416
  this.files = this.files.filter(file => file.name !== attachment.dataset.name);
417
+ this.attachmentInputTarget.value = '';
385
418
  attachment.remove();
386
419
  this.inputTarget.focus();
387
420
  }
@@ -439,6 +472,16 @@ let _default = /*#__PURE__*/function (_Controller) {
439
472
  padding: 24
440
473
  }), (0, _dom.flip)()];
441
474
  }
475
+ }, {
476
+ key: "shouldOpenOnMount",
477
+ get: function () {
478
+ return localStorage.getItem(`hellotext--webchat--${this.idValue}`) === 'opened' && !this.onMobile;
479
+ }
480
+ }, {
481
+ key: "onMobile",
482
+ get: function () {
483
+ return window.matchMedia(`(max-width: ${this.fullScreenThresholdValue}px)`).matches;
484
+ }
442
485
  }]);
443
486
  return _default;
444
487
  }(_stimulus.Controller);
@@ -467,6 +510,11 @@ _default.values = {
467
510
  nextPage: {
468
511
  type: Number,
469
512
  default: undefined
513
+ },
514
+ fullScreenThreshold: {
515
+ type: Number,
516
+ default: 1024
470
517
  }
471
518
  };
519
+ _default.classes = ['fadeOut'];
472
520
  _default.targets = ['trigger', 'popover', 'input', 'attachmentInput', 'attachmentButton', 'errorMessageContainer', 'attachmentTemplate', 'attachmentContainer', 'attachment', 'messageTemplate', 'messagesContainer', 'title', 'onlineStatus', 'attachmentImage', 'footer', 'toolbar', 'message', 'unreadCounter'];
@@ -22,6 +22,7 @@ import { Controller } from '@hotwired/stimulus';
22
22
  import WebchatMessagesAPI from '../api/webchat/messages';
23
23
  import WebchatChannel from '../channels/webchat_channel';
24
24
  import Hellotext from '../hellotext';
25
+ import { Locale } from '../core';
25
26
  import { Webchat as WebchatConfiguration, behaviors } from '../core/configuration/webchat';
26
27
  import { LogoBuilder } from '../builders/logo_builder';
27
28
  import { usePopover } from './mixins/usePopover';
@@ -65,7 +66,7 @@ var _default = /*#__PURE__*/function (_Controller) {
65
66
  if (!Hellotext.business.features.white_label) {
66
67
  this.toolbarTarget.appendChild(LogoBuilder.build());
67
68
  }
68
- if (localStorage.getItem("hellotext--webchat--".concat(this.idValue)) === 'opened') {
69
+ if (this.shouldOpenOnMount) {
69
70
  this.openValue = true;
70
71
  }
71
72
  Hellotext.eventEmitter.dispatch('webchat:mounted');
@@ -168,14 +169,26 @@ var _default = /*#__PURE__*/function (_Controller) {
168
169
  this.openValue = false;
169
170
  }
170
171
  }
172
+ }, {
173
+ key: "closePopover",
174
+ value: function closePopover() {
175
+ this.popoverTarget.classList.add(...this.fadeOutClasses);
176
+ setTimeout(() => {
177
+ this.openValue = false;
178
+ }, 250);
179
+ }
171
180
  }, {
172
181
  key: "onPopoverOpened",
173
182
  value: function onPopoverOpened() {
174
- this.inputTarget.focus();
183
+ if (!this.onMobile) {
184
+ this.inputTarget.focus();
185
+ }
175
186
  if (!this.scrolled) {
176
- this.messagesContainerTarget.scroll({
177
- top: this.messagesContainerTarget.scrollHeight,
178
- behavior: 'instant'
187
+ requestAnimationFrame(() => {
188
+ this.messagesContainerTarget.scroll({
189
+ top: this.messagesContainerTarget.scrollHeight,
190
+ behavior: 'instant'
191
+ });
179
192
  });
180
193
  this.scrolled = true;
181
194
  }
@@ -190,9 +203,6 @@ var _default = /*#__PURE__*/function (_Controller) {
190
203
  key: "onPopoverClosed",
191
204
  value: function onPopoverClosed() {
192
205
  Hellotext.eventEmitter.dispatch('webchat:closed');
193
- setTimeout(() => {
194
- this.inputTarget.value = '';
195
- });
196
206
  localStorage.setItem("hellotext--webchat--".concat(this.idValue), 'closed');
197
207
  }
198
208
  }, {
@@ -223,6 +233,7 @@ var _default = /*#__PURE__*/function (_Controller) {
223
233
  key: "onMessageReceived",
224
234
  value: function onMessageReceived(message) {
225
235
  var {
236
+ id,
226
237
  body,
227
238
  attachments
228
239
  } = message;
@@ -248,7 +259,10 @@ var _default = /*#__PURE__*/function (_Controller) {
248
259
  behavior: 'smooth'
249
260
  });
250
261
  this.setOfflineTimeout();
251
- if (this.openValue) return;
262
+ if (this.openValue) {
263
+ this.messagesAPI.markAsSeen(id);
264
+ return;
265
+ }
252
266
  this.unreadCounterTarget.style.display = 'flex';
253
267
  var unreadCount = (parseInt(this.unreadCounterTarget.innerText) || 0) + 1;
254
268
  this.unreadCounterTarget.innerText = unreadCount > 99 ? '99+' : unreadCount;
@@ -281,17 +295,29 @@ var _default = /*#__PURE__*/function (_Controller) {
281
295
  body: this.inputTarget.value,
282
296
  attachments: this.files
283
297
  };
284
- formData.append('message[body]', this.inputTarget.value);
298
+ if (this.inputTarget.value.trim().length === 0 && this.files.length === 0) {
299
+ return;
300
+ }
301
+ if (this.inputTarget.value.trim().length > 0) {
302
+ formData.append('message[body]', this.inputTarget.value);
303
+ } else {
304
+ delete message.body;
305
+ }
285
306
  this.files.forEach(file => {
286
307
  formData.append('message[attachments][]', file);
287
308
  });
288
309
  formData.append('session', Hellotext.session);
310
+ formData.append('locale', Locale.toString());
289
311
  var element = this.messageTemplateTarget.cloneNode(true);
290
312
  element.id = "hellotext--webchat--".concat(this.idValue, "--message--").concat(Date.now());
291
313
  element.classList.add('received');
292
314
  element.style.removeProperty('display');
293
315
  element.setAttribute('data-hellotext--webchat-target', 'message');
294
- element.querySelector('[data-body]').innerText = this.inputTarget.value;
316
+ if (this.inputTarget.value.trim().length > 0) {
317
+ element.querySelector('[data-body]').innerText = this.inputTarget.value;
318
+ } else {
319
+ element.querySelector('[data-message-bubble]').remove();
320
+ }
295
321
  var attachments = this.attachmentContainerTarget.querySelectorAll('img');
296
322
  if (attachments.length > 0) {
297
323
  attachments.forEach(attachment => {
@@ -308,6 +334,8 @@ var _default = /*#__PURE__*/function (_Controller) {
308
334
  });
309
335
  this.inputTarget.value = '';
310
336
  this.files = [];
337
+ this.attachmentInputTarget.value = '';
338
+ this.attachmentContainerTarget.innerHTML = '';
311
339
  this.attachmentContainerTarget.style.display = 'none';
312
340
  this.errorMessageContainerTarget.style.display = 'none';
313
341
  this.inputTarget.focus();
@@ -343,8 +371,9 @@ var _default = /*#__PURE__*/function (_Controller) {
343
371
  key: "onFileInputChange",
344
372
  value: function onFileInputChange() {
345
373
  this.errorMessageContainerTarget.style.display = 'none';
346
- this.files = Array.from(this.attachmentInputTarget.files);
347
- var fileMaxSizeTooMuch = this.files.find(file => {
374
+ var newFiles = Array.from(this.attachmentInputTarget.files);
375
+ this.attachmentInputTarget.value = '';
376
+ var fileMaxSizeTooMuch = newFiles.find(file => {
348
377
  var type = file.type.split('/')[0];
349
378
  if (['image', 'video', 'audio'].includes(type)) {
350
379
  return this.mediaValue[type].max_size < file.size;
@@ -356,10 +385,11 @@ var _default = /*#__PURE__*/function (_Controller) {
356
385
  var type = fileMaxSizeTooMuch.type.split('/')[0];
357
386
  var mediaType = ['image', 'audio', 'video'].includes(type) ? type : 'document';
358
387
  this.errorMessageContainerTarget.innerText = this.fileSizeErrorMessageValue.replace('%{limit}', this.byteToMegabyte(this.mediaValue[mediaType].max_size));
359
- return;
388
+ return this.errorMessageContainerTarget.style.display = 'block';
360
389
  }
390
+ this.files = [...this.files, ...newFiles];
361
391
  this.errorMessageContainerTarget.innerText = '';
362
- this.files.forEach(file => this.createAttachmentElement(file));
392
+ newFiles.forEach(file => this.createAttachmentElement(file));
363
393
  this.inputTarget.focus();
364
394
  }
365
395
  }, {
@@ -382,6 +412,8 @@ var _default = /*#__PURE__*/function (_Controller) {
382
412
  main.style.backgroundColor = '#e5e7eb';
383
413
  main.style.padding = '0.25rem';
384
414
  element.querySelector('p[data-attachment-name]').innerText = file.name;
415
+ this.attachmentContainerTarget.appendChild(element);
416
+ this.attachmentContainerTarget.style.display = 'flex';
385
417
  }
386
418
  }
387
419
  }, {
@@ -392,6 +424,7 @@ var _default = /*#__PURE__*/function (_Controller) {
392
424
  } = _ref;
393
425
  var attachment = currentTarget.closest("[data-hellotext--webchat-target='attachment']");
394
426
  this.files = this.files.filter(file => file.name !== attachment.dataset.name);
427
+ this.attachmentInputTarget.value = '';
395
428
  attachment.remove();
396
429
  this.inputTarget.focus();
397
430
  }
@@ -450,6 +483,16 @@ var _default = /*#__PURE__*/function (_Controller) {
450
483
  padding: 24
451
484
  }), flip()];
452
485
  }
486
+ }, {
487
+ key: "shouldOpenOnMount",
488
+ get: function get() {
489
+ return localStorage.getItem("hellotext--webchat--".concat(this.idValue)) === 'opened' && !this.onMobile;
490
+ }
491
+ }, {
492
+ key: "onMobile",
493
+ get: function get() {
494
+ return window.matchMedia("(max-width: ".concat(this.fullScreenThresholdValue, "px)")).matches;
495
+ }
453
496
  }]);
454
497
  return _default;
455
498
  }(Controller);
@@ -477,7 +520,12 @@ _default.values = {
477
520
  nextPage: {
478
521
  type: Number,
479
522
  default: undefined
523
+ },
524
+ fullScreenThreshold: {
525
+ type: Number,
526
+ default: 1024
480
527
  }
481
528
  };
529
+ _default.classes = ['fadeOut'];
482
530
  _default.targets = ['trigger', 'popover', 'input', 'attachmentInput', 'attachmentButton', 'errorMessageContainer', 'attachmentTemplate', 'attachmentContainer', 'attachment', 'messageTemplate', 'messagesContainer', 'title', 'onlineStatus', 'attachmentImage', 'footer', 'toolbar', 'message', 'unreadCounter'];
483
531
  export { _default as default };