@hellotext/hellotext 2.5.6 → 2.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -26
- package/dist/hellotext.js +1 -1
- package/dist/hellotext.js.LICENSE.txt +1 -1
- package/index.d.ts +15 -6
- package/lib/api/acks.cjs +17 -31
- package/lib/api/acks.js +17 -42
- package/lib/api/businesses.cjs +14 -28
- package/lib/api/businesses.js +13 -36
- package/lib/api/events.cjs +26 -40
- package/lib/api/events.js +28 -52
- package/lib/api/forms.cjs +24 -40
- package/lib/api/forms.js +24 -57
- package/lib/api/identifications.cjs +15 -29
- package/lib/api/identifications.js +15 -40
- package/lib/api/index.cjs +26 -46
- package/lib/api/index.js +28 -49
- package/lib/api/push/identities.cjs +43 -0
- package/lib/api/push/identities.js +35 -0
- package/lib/api/response.cjs +30 -52
- package/lib/api/response.js +31 -60
- package/lib/api/submissions.cjs +18 -34
- package/lib/api/submissions.js +18 -48
- package/lib/api/webchat/messages.cjs +44 -64
- package/lib/api/webchat/messages.js +44 -80
- package/lib/api/webchats.cjs +37 -56
- package/lib/api/webchats.js +37 -65
- package/lib/api/whatsapp_widgets.cjs +49 -72
- package/lib/api/whatsapp_widgets.js +48 -91
- package/lib/builders/input_builder.cjs +36 -48
- package/lib/builders/input_builder.js +36 -48
- package/lib/builders/logo_builder.cjs +10 -29
- package/lib/builders/logo_builder.js +20 -28
- package/lib/channels/application_channel.cjs +136 -178
- package/lib/channels/application_channel.js +137 -180
- package/lib/channels/webchat_channel.cjs +125 -170
- package/lib/channels/webchat_channel.js +125 -170
- package/lib/controllers/form_controller.cjs +82 -121
- package/lib/controllers/form_controller.js +82 -130
- package/lib/controllers/message_controller.cjs +211 -282
- package/lib/controllers/message_controller.js +209 -284
- package/lib/controllers/mixins/usePopover.cjs +3 -6
- package/lib/controllers/mixins/usePopover.js +17 -22
- package/lib/controllers/webchat/emoji_picker_controller.cjs +106 -150
- package/lib/controllers/webchat/emoji_picker_controller.js +105 -170
- package/lib/controllers/webchat/useBehaviour.js +5 -5
- package/lib/controllers/webchat/useOpeningSequence.js +6 -6
- package/lib/controllers/webchat/useTeaser.js +9 -9
- package/lib/controllers/webchat_controller.cjs +916 -1088
- package/lib/controllers/webchat_controller.js +926 -1152
- package/lib/core/configuration/forms.cjs +21 -35
- package/lib/core/configuration/forms.js +20 -35
- package/lib/core/configuration/locale.cjs +36 -71
- package/lib/core/configuration/locale.js +36 -70
- package/lib/core/configuration/push.cjs +16 -0
- package/lib/core/configuration/push.js +10 -0
- package/lib/core/configuration/webchat.cjs +142 -182
- package/lib/core/configuration/webchat.js +145 -189
- package/lib/core/configuration/whatsapp.cjs +76 -102
- package/lib/core/configuration/whatsapp.js +76 -105
- package/lib/core/configuration.cjs +62 -75
- package/lib/core/configuration.js +61 -75
- package/lib/core/event.cjs +36 -59
- package/lib/core/event.js +35 -61
- package/lib/core/sanitize_html.js +4 -4
- package/lib/errors/invalid_event.cjs +5 -26
- package/lib/errors/invalid_event.js +5 -26
- package/lib/errors/not_initialized_error.cjs +5 -26
- package/lib/errors/not_initialized_error.js +5 -26
- package/lib/hellotext.cjs +186 -211
- package/lib/hellotext.js +189 -236
- package/lib/index.js +1 -1
- package/lib/models/business.cjs +115 -152
- package/lib/models/business.js +118 -162
- package/lib/models/cookies.cjs +34 -51
- package/lib/models/cookies.js +34 -51
- package/lib/models/fingerprint.cjs +8 -23
- package/lib/models/fingerprint.js +25 -58
- package/lib/models/form.cjs +106 -142
- package/lib/models/form.js +105 -153
- package/lib/models/form_collection.cjs +63 -101
- package/lib/models/form_collection.js +61 -107
- package/lib/models/index.cjs +7 -0
- package/lib/models/index.js +1 -0
- package/lib/models/page.cjs +106 -129
- package/lib/models/page.js +106 -131
- package/lib/models/push.cjs +345 -0
- package/lib/models/push.js +339 -0
- package/lib/models/query.cjs +21 -41
- package/lib/models/query.js +21 -41
- package/lib/models/session.cjs +33 -65
- package/lib/models/session.js +30 -63
- package/lib/models/user.cjs +29 -51
- package/lib/models/user.js +29 -51
- package/lib/models/utm.cjs +15 -27
- package/lib/models/utm.js +17 -32
- package/lib/models/webchat.cjs +52 -76
- package/lib/models/webchat.js +52 -90
- package/lib/models/whatsapp_widget.cjs +41 -59
- package/lib/models/whatsapp_widget.js +41 -73
- package/lib/vanilla.cjs +4 -7
- package/lib/vanilla.js +2 -1
- package/package.json +2 -10
- package/src/api/index.js +5 -0
- package/src/api/push/identities.js +42 -0
- package/src/core/configuration/push.js +12 -0
- package/src/core/configuration.js +5 -0
- package/src/hellotext.js +15 -1
- package/src/index.bundle.js +0 -1
- package/src/models/business.js +1 -0
- package/src/models/index.js +1 -0
- package/src/models/push.js +397 -0
- package/src/vanilla.js +2 -1
- package/styles/index.css +0 -30
package/lib/hellotext.js
CHANGED
|
@@ -1,254 +1,207 @@
|
|
|
1
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
3
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
4
|
-
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); } }
|
|
5
|
-
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); }); }; }
|
|
6
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
7
|
-
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); } }
|
|
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
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
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
1
|
import { Configuration, Event } from './core';
|
|
12
2
|
import API, { Response, keepaliveFor } from './api';
|
|
13
|
-
import { Business, Fingerprint, FormCollection, Page, Query, Session, User, Webchat, WhatsAppWidget } from './models';
|
|
3
|
+
import { Business, Fingerprint, FormCollection, Page, Push, Query, Session, User, Webchat, WhatsAppWidget } from './models';
|
|
14
4
|
import { NotInitializedError } from './errors';
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (whatsappConfig && whatsappConfig.id) {
|
|
46
|
-
Configuration.whatsapp.assign(whatsappConfig);
|
|
47
|
-
this.whatsapp = yield WhatsAppWidget.load(whatsappConfig.id);
|
|
48
|
-
}
|
|
49
|
-
if (typeof MutationObserver !== 'undefined') {
|
|
50
|
-
this.forms.collectExistingFormsOnPage();
|
|
51
|
-
}
|
|
5
|
+
class Hellotext {
|
|
6
|
+
static eventEmitter = new Event();
|
|
7
|
+
static forms;
|
|
8
|
+
static business;
|
|
9
|
+
static webchat;
|
|
10
|
+
static whatsapp;
|
|
11
|
+
static push;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* initialize the module.
|
|
15
|
+
* @param business public business id
|
|
16
|
+
* @param { Configuration } config
|
|
17
|
+
*/
|
|
18
|
+
static async initialize(business, config = {}) {
|
|
19
|
+
this.push?.dispose();
|
|
20
|
+
this.push = null;
|
|
21
|
+
this.business = new Business(business);
|
|
22
|
+
this.page = new Page();
|
|
23
|
+
Configuration.assign({
|
|
24
|
+
push: {},
|
|
25
|
+
...config
|
|
26
|
+
});
|
|
27
|
+
Session.initialize(this.page);
|
|
28
|
+
this.forms = new FormCollection();
|
|
29
|
+
this.query = new Query();
|
|
30
|
+
const businessData = await this.business.hydrate();
|
|
31
|
+
if (config.push !== false && businessData?.push?.public_key && Push.supported) {
|
|
32
|
+
this.push = new Push(businessData.push);
|
|
33
|
+
this.push.initialize().catch(error => {
|
|
34
|
+
console.warn('Hellotext Push initialization failed:', error);
|
|
52
35
|
});
|
|
53
|
-
function initialize(_x) {
|
|
54
|
-
return _initialize.apply(this, arguments);
|
|
55
|
-
}
|
|
56
|
-
return initialize;
|
|
57
|
-
}()
|
|
58
|
-
}, {
|
|
59
|
-
key: "mergeWebchatConfig",
|
|
60
|
-
value: function mergeWebchatConfig(dashboardConfig, localConfig) {
|
|
61
|
-
return this.deepMergePlainObjects(dashboardConfig, localConfig);
|
|
62
36
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
37
|
+
const webchatConfig = config.webchat === false ? false : this.mergeWebchatConfig(businessData && businessData.webchat || {}, config.webchat || {});
|
|
38
|
+
const whatsappConfig = config.whatsappWidget === false ? false : this.mergeWhatsAppConfig(businessData && businessData.whatsapp || {}, config.whatsappWidget || {});
|
|
39
|
+
const hasExplicitBehaviourOverride = config.webchat && config.webchat !== false && Object.prototype.hasOwnProperty.call(config.webchat, 'behaviour');
|
|
40
|
+
Configuration.webchat.behaviourOverride = hasExplicitBehaviourOverride;
|
|
41
|
+
if (webchatConfig && webchatConfig.id) {
|
|
42
|
+
Configuration.webchat.assign(webchatConfig);
|
|
43
|
+
this.webchat = await Webchat.load(webchatConfig.id);
|
|
67
44
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
var result = _objectSpread({}, base);
|
|
72
|
-
Object.entries(override).forEach(_ref => {
|
|
73
|
-
var [key, value] = _ref;
|
|
74
|
-
if (this.isPlainObject(value) && this.isPlainObject(result[key])) {
|
|
75
|
-
result[key] = this.deepMergePlainObjects(result[key], value);
|
|
76
|
-
} else {
|
|
77
|
-
result[key] = value;
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
return result;
|
|
45
|
+
if (whatsappConfig && whatsappConfig.id) {
|
|
46
|
+
Configuration.whatsapp.assign(whatsappConfig);
|
|
47
|
+
this.whatsapp = await WhatsAppWidget.load(whatsappConfig.id);
|
|
81
48
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
value: function isPlainObject(value) {
|
|
85
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
49
|
+
if (typeof MutationObserver !== 'undefined') {
|
|
50
|
+
this.forms.collectExistingFormsOnPage();
|
|
86
51
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
var headers = _objectSpread(_objectSpread({}, params && params.headers || {}), this.headers);
|
|
104
|
-
var user_parameters = _objectSpread(_objectSpread({}, User.identificationData), params.user_parameters || {});
|
|
105
|
-
var pageInstance = params && params.url ? new Page(params.url) : this.page;
|
|
106
|
-
var body = _objectSpread(_objectSpread({
|
|
107
|
-
session: this.session,
|
|
108
|
-
user_parameters,
|
|
109
|
-
action
|
|
110
|
-
}, params), pageInstance.trackingData);
|
|
111
|
-
delete body.headers;
|
|
112
|
-
return yield API.events.create({
|
|
113
|
-
headers,
|
|
114
|
-
body,
|
|
115
|
-
// Track is the SDK's unload-sensitive analytics path. Keepalive belongs
|
|
116
|
-
// here rather than on identify/forms/webchat calls because event tracking
|
|
117
|
-
// is allowed to be fire-and-navigate, while those other calls have
|
|
118
|
-
// stronger request/response or interaction contracts.
|
|
119
|
-
keepalive: keepaliveFor(body)
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
function track(_x2) {
|
|
123
|
-
return _track.apply(this, arguments);
|
|
124
|
-
}
|
|
125
|
-
return track;
|
|
126
|
-
}()
|
|
127
|
-
/**
|
|
128
|
-
* @typedef { Object } IdentificationOptions
|
|
129
|
-
* @property { String } [email] - the email of the user
|
|
130
|
-
* @property { String } [phone] - the phone number of the user
|
|
131
|
-
* @property { String } [name] - the name of the user
|
|
132
|
-
* @property { String } [source] - the platform specific identifier where this pixel is running on.
|
|
133
|
-
*
|
|
134
|
-
* Identifies a user and attaches the hello_session to the user ID.
|
|
135
|
-
* Repeated calls are skipped only when the last successful identify payload
|
|
136
|
-
* for the current session remains unchanged.
|
|
137
|
-
* @param { String } externalId - the user ID
|
|
138
|
-
* @param { IdentificationOptions } options - the options for the identification
|
|
139
|
-
* @returns {Promise<Response>}
|
|
140
|
-
*/
|
|
141
|
-
}, {
|
|
142
|
-
key: "identify",
|
|
143
|
-
value: function () {
|
|
144
|
-
var _identify = _asyncToGenerator(function* (externalId) {
|
|
145
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
146
|
-
var fingerprint = yield Fingerprint.generate(this.session, externalId, options);
|
|
147
|
-
if (Fingerprint.matches(User.fingerprint, fingerprint)) {
|
|
148
|
-
return new Response(true, {
|
|
149
|
-
json: function () {
|
|
150
|
-
var _json = _asyncToGenerator(function* () {
|
|
151
|
-
return {
|
|
152
|
-
already_identified: true
|
|
153
|
-
};
|
|
154
|
-
});
|
|
155
|
-
function json() {
|
|
156
|
-
return _json.apply(this, arguments);
|
|
157
|
-
}
|
|
158
|
-
return json;
|
|
159
|
-
}()
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
var response = yield API.identifications.create(_objectSpread({
|
|
163
|
-
user_id: externalId
|
|
164
|
-
}, options));
|
|
165
|
-
if (response.succeeded) {
|
|
166
|
-
User.remember(externalId, options.source, fingerprint);
|
|
167
|
-
}
|
|
168
|
-
return response;
|
|
169
|
-
});
|
|
170
|
-
function identify(_x3) {
|
|
171
|
-
return _identify.apply(this, arguments);
|
|
52
|
+
}
|
|
53
|
+
static mergeWebchatConfig(dashboardConfig, localConfig) {
|
|
54
|
+
return this.deepMergePlainObjects(dashboardConfig, localConfig);
|
|
55
|
+
}
|
|
56
|
+
static mergeWhatsAppConfig(dashboardConfig, localConfig) {
|
|
57
|
+
return this.deepMergePlainObjects(dashboardConfig, localConfig);
|
|
58
|
+
}
|
|
59
|
+
static deepMergePlainObjects(base, override) {
|
|
60
|
+
const result = {
|
|
61
|
+
...base
|
|
62
|
+
};
|
|
63
|
+
Object.entries(override).forEach(([key, value]) => {
|
|
64
|
+
if (this.isPlainObject(value) && this.isPlainObject(result[key])) {
|
|
65
|
+
result[key] = this.deepMergePlainObjects(result[key], value);
|
|
66
|
+
} else {
|
|
67
|
+
result[key] = value;
|
|
172
68
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
*/
|
|
180
|
-
}, {
|
|
181
|
-
key: "forget",
|
|
182
|
-
value: function forget() {
|
|
183
|
-
User.forget();
|
|
184
|
-
}
|
|
69
|
+
});
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
static isPlainObject(value) {
|
|
73
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
74
|
+
}
|
|
185
75
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Tracks an action that has happened on the page
|
|
78
|
+
*
|
|
79
|
+
* @param { String } action a valid action name
|
|
80
|
+
* @param { Object } params
|
|
81
|
+
* @returns {Promise<Response>}
|
|
82
|
+
*/
|
|
83
|
+
static async track(action, params = {}) {
|
|
84
|
+
if (this.notInitialized) {
|
|
85
|
+
throw new NotInitializedError();
|
|
195
86
|
}
|
|
87
|
+
const headers = {
|
|
88
|
+
...(params && params.headers || {}),
|
|
89
|
+
...this.headers
|
|
90
|
+
};
|
|
91
|
+
const user_parameters = {
|
|
92
|
+
...User.identificationData,
|
|
93
|
+
...(params.user_parameters || {})
|
|
94
|
+
};
|
|
95
|
+
const pageInstance = params && params.url ? new Page(params.url) : this.page;
|
|
96
|
+
const body = {
|
|
97
|
+
session: this.session,
|
|
98
|
+
user_parameters,
|
|
99
|
+
action,
|
|
100
|
+
...params,
|
|
101
|
+
...pageInstance.trackingData
|
|
102
|
+
};
|
|
103
|
+
delete body.headers;
|
|
104
|
+
return await API.events.create({
|
|
105
|
+
headers,
|
|
106
|
+
body,
|
|
107
|
+
// Track is the SDK's unload-sensitive analytics path. Keepalive belongs
|
|
108
|
+
// here rather than on identify/forms/webchat calls because event tracking
|
|
109
|
+
// is allowed to be fire-and-navigate, while those other calls have
|
|
110
|
+
// stronger request/response or interaction contracts.
|
|
111
|
+
keepalive: keepaliveFor(body)
|
|
112
|
+
});
|
|
113
|
+
}
|
|
196
114
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
115
|
+
/**
|
|
116
|
+
* @typedef { Object } IdentificationOptions
|
|
117
|
+
* @property { String } [email] - the email of the user
|
|
118
|
+
* @property { String } [phone] - the phone number of the user
|
|
119
|
+
* @property { String } [name] - the name of the user
|
|
120
|
+
* @property { String } [source] - the platform specific identifier where this pixel is running on.
|
|
121
|
+
*
|
|
122
|
+
* Identifies a user and attaches the hello_session to the user ID.
|
|
123
|
+
* Repeated calls are skipped only when the last successful identify payload
|
|
124
|
+
* for the current session remains unchanged.
|
|
125
|
+
* @param { String } externalId - the user ID
|
|
126
|
+
* @param { IdentificationOptions } options - the options for the identification
|
|
127
|
+
* @returns {Promise<Response>}
|
|
128
|
+
*/
|
|
129
|
+
static async identify(externalId, options = {}) {
|
|
130
|
+
const fingerprint = await Fingerprint.generate(this.session, externalId, options);
|
|
131
|
+
if (Fingerprint.matches(User.fingerprint, fingerprint)) {
|
|
132
|
+
return new Response(true, {
|
|
133
|
+
json: async () => ({
|
|
134
|
+
already_identified: true
|
|
135
|
+
})
|
|
136
|
+
});
|
|
206
137
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
key: "session",
|
|
214
|
-
get: function get() {
|
|
215
|
-
return Session.session;
|
|
138
|
+
const response = await API.identifications.create({
|
|
139
|
+
user_id: externalId,
|
|
140
|
+
...options
|
|
141
|
+
});
|
|
142
|
+
if (response.succeeded) {
|
|
143
|
+
User.remember(externalId, options.source, fingerprint);
|
|
216
144
|
}
|
|
145
|
+
return response;
|
|
146
|
+
}
|
|
217
147
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
}
|
|
148
|
+
/**
|
|
149
|
+
* Clears the user session, use when the user logs out to clear the hello cookies
|
|
150
|
+
*
|
|
151
|
+
* @returns {void}
|
|
152
|
+
*/
|
|
153
|
+
static forget() {
|
|
154
|
+
User.forget();
|
|
155
|
+
}
|
|
227
156
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
157
|
+
/**
|
|
158
|
+
* Registers an event listener
|
|
159
|
+
* @param event the name of the event to listen to
|
|
160
|
+
* @param callback the callback. This method will be called with the payload
|
|
161
|
+
*/
|
|
162
|
+
static on(event, callback) {
|
|
163
|
+
this.eventEmitter.addSubscriber(event, callback);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Removes an event listener
|
|
168
|
+
* @param event the name of the event to remove
|
|
169
|
+
* @param callback the callback to remove
|
|
170
|
+
*/
|
|
171
|
+
static removeEventListener(event, callback) {
|
|
172
|
+
this.eventEmitter.removeSubscriber(event, callback);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
*
|
|
177
|
+
* @returns {String}
|
|
178
|
+
*/
|
|
179
|
+
static get session() {
|
|
180
|
+
return Session.session;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Determines if the session is set or not
|
|
185
|
+
* @returns {boolean}
|
|
186
|
+
*/
|
|
187
|
+
static get isInitialized() {
|
|
188
|
+
return Session.session !== undefined;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// private
|
|
192
|
+
|
|
193
|
+
static get notInitialized() {
|
|
194
|
+
return !this.business || this.business.id === undefined;
|
|
195
|
+
}
|
|
196
|
+
static get headers() {
|
|
197
|
+
if (this.notInitialized) {
|
|
198
|
+
throw new NotInitializedError();
|
|
245
199
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
Hellotext.whatsapp = void 0;
|
|
200
|
+
return {
|
|
201
|
+
Authorization: `Bearer ${this.business.id}`,
|
|
202
|
+
Accept: 'application/json',
|
|
203
|
+
'Content-Type': 'application/json'
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
}
|
|
254
207
|
export default Hellotext;
|
package/lib/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import FormController from './controllers/form_controller';
|
|
|
4
4
|
import MessageController from './controllers/message_controller';
|
|
5
5
|
import WebChatEmojiController from './controllers/webchat/emoji_picker_controller';
|
|
6
6
|
import WebchatController from './controllers/webchat_controller';
|
|
7
|
-
|
|
7
|
+
const application = Application.start();
|
|
8
8
|
application.register('hellotext--form', FormController);
|
|
9
9
|
application.register('hellotext--webchat', WebchatController);
|
|
10
10
|
application.register('hellotext--webchat--emoji', WebChatEmojiController);
|