@subiz/widget-v4 4.1.197 → 4.1.198

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 (29) hide show
  1. package/compiled_src/lib.js +55 -26
  2. package/compiled_src/store/api.js +6 -10
  3. package/dist/{19b9941db90.app.js → 19bbfd5aa77.app.js} +1 -1
  4. package/dist/{19b9941db90.chat.html → 19bbfd5aa77.chat.html} +1 -1
  5. package/dist/{19b9941db90.chat.js → 19bbfd5aa77.chat.js} +1 -1
  6. package/dist/{19b9941db90.form.html → 19bbfd5aa77.form.html} +1 -1
  7. package/dist/19bbfd5aa77.form.js +1 -0
  8. package/dist/{19b9941db90.index.html → 19bbfd5aa77.index.html} +1 -1
  9. package/dist/{19b9941db90.library.html → 19bbfd5aa77.library.html} +1 -1
  10. package/dist/{19b9941db90.library.js → 19bbfd5aa77.library.js} +1 -1
  11. package/dist/{19b9941db90.preview.html → 19bbfd5aa77.preview.html} +1 -1
  12. package/dist/{19b9941db90.preview.js → 19bbfd5aa77.preview.js} +1 -1
  13. package/dist/{19b9941db90.webview.js → 19bbfd5aa77.webview.js} +1 -1
  14. package/dist/HASH +1 -1
  15. package/dist/screenshoot.js +67 -40
  16. package/package.json +1 -1
  17. package/src/lib.js +44 -19
  18. package/src/store/api.js +6 -6
  19. package/dist/19b9941db90.form.js +0 -1
  20. /package/dist/{19b9941db90.127.js → 19bbfd5aa77.127.js} +0 -0
  21. /package/dist/{19b9941db90.132.js → 19bbfd5aa77.132.js} +0 -0
  22. /package/dist/{19b9941db90.185.js → 19bbfd5aa77.185.js} +0 -0
  23. /package/dist/{19b9941db90.27.js → 19bbfd5aa77.27.js} +0 -0
  24. /package/dist/{19b9941db90.278.js → 19bbfd5aa77.278.js} +0 -0
  25. /package/dist/{19b9941db90.339.js → 19bbfd5aa77.339.js} +0 -0
  26. /package/dist/{19b9941db90.459.js → 19bbfd5aa77.459.js} +0 -0
  27. /package/dist/{19b9941db90.490.js → 19bbfd5aa77.490.js} +0 -0
  28. /package/dist/{19b9941db90.74.js → 19bbfd5aa77.74.js} +0 -0
  29. /package/dist/{19b9941db90.997.js → 19bbfd5aa77.997.js} +0 -0
@@ -198,35 +198,64 @@ class Widget {
198
198
  return impressiontoken;
199
199
  }
200
200
  async submitForm(formid, values) {
201
- if (!formid || !_index.default.startsWith(formid, 'cp')) return;
202
- let storeuser = _index.default.cloneDeep(this.store.matchUser());
203
- let user = {
204
- id: storeuser.id,
205
- account_id: storeuser.account_id
206
- };
207
- let is_lead = false;
208
- values = _index.default.map(values, val => {
209
- let key = val.key;
210
- if (key === 'email') key = 'emails';
211
- if (key === 'phone') key = 'phones';
212
- is_lead = is_lead || key == 'emails' || key == 'phones';
213
- _index.default.setUserAttr(user, {
214
- key: key,
215
- [val.type || 'text']: val.value
216
- });
217
- return {
218
- key: key,
219
- type: val.type || 'text',
220
- value: _index.default.stringify(val.value)
201
+ if (!formid || !values) return;
202
+ if (_index.default.startsWith(formid, 'cp')) {
203
+ let storeuser = _index.default.cloneDeep(this.store.matchUser());
204
+ let user = {
205
+ id: storeuser.id,
206
+ account_id: storeuser.account_id
221
207
  };
208
+ let is_lead = false;
209
+ values = _index.default.map(values, val => {
210
+ let key = val.key;
211
+ if (key === 'email') key = 'emails';
212
+ if (key === 'phone') key = 'phones';
213
+ is_lead = is_lead || key == 'emails' || key == 'phones';
214
+ _index.default.setUserAttr(user, {
215
+ key: key,
216
+ [val.type || 'text']: val.value
217
+ });
218
+ return {
219
+ key: key,
220
+ type: val.type || 'text',
221
+ value: _index.default.stringify(val.value)
222
+ };
223
+ });
224
+ if (is_lead) _index.default.setUserAttr(user, {
225
+ key: 'lead_source',
226
+ text: 'plugin.' + formid
227
+ });
228
+ let impressiontoken = await this.viewForm(formid);
229
+ this.store.setUserDiff(user);
230
+ return this.store.sendConversion(formid, values, impressiontoken);
231
+ }
232
+ values = _index.default.filter(values, field => {
233
+ return field.key && field.value;
222
234
  });
223
- if (is_lead) _index.default.setUserAttr(user, {
224
- key: 'lead_source',
225
- text: 'plugin.' + formid
235
+ let text = 'Khách điền form\n';
236
+ _index.default.map(values, field => {
237
+ text += '+ ' + field.key + ': ' + field.value + '\n';
238
+ });
239
+ return this.store.startConvo({
240
+ subject: 'Khách điền form',
241
+ touchpoint: {
242
+ channel: 'form',
243
+ source: window.location.hostname,
244
+ id: Date.now() + '_' + _index.default.randomString()
245
+ },
246
+ form_submission: {
247
+ id: formid,
248
+ values: values
249
+ },
250
+ message_sent: {
251
+ data: {
252
+ message: {
253
+ format: 'plaintext',
254
+ text: text
255
+ }
256
+ }
257
+ }
226
258
  });
227
- let impressiontoken = await this.viewForm(formid);
228
- this.store.setUserDiff(user);
229
- return this.store.sendConversion(formid, values, impressiontoken);
230
259
  }
231
260
  startConvo(req) {
232
261
  req = _index.default.cloneDeep(req) || {};
@@ -49,16 +49,12 @@ class _default {
49
49
  _defineProperty(this, "listConversations", _ => this.apireq.addQuery('user_id', this.uid).addQuery('integration_id', `${this.accid}.subizv4.subikon`).get(`/accounts/${this.accid}/conversations`));
50
50
  _defineProperty(this, "listMessages", (cid, limit, start_id) => this.apireq.addQuery('limit', limit).addQuery('start_id', start_id).get(`/accounts/${this.accid}/conversations/${cid}/messages`));
51
51
  _defineProperty(this, "ajax", ajax);
52
- _defineProperty(this, "start", extraData => {
53
- let data = {
54
- touchpoint: {
55
- channel: 'subiz',
56
- source: 'web'
57
- }
58
- };
59
- _index.default.each(extraData, (v, k) => {
60
- data[k] = v;
61
- });
52
+ _defineProperty(this, "start", (extraData, tpchannel, tpsource, tpid) => {
53
+ let data = Object.assign({}, extraData);
54
+ if (!data.touchpoint) data.touchpoint = {};
55
+ if (!data.touchpoint.channel) data.touchpoint.channel = 'subiz';
56
+ if (!data.touchpoint.source) data.touchpoint.source = 'web';
57
+ data.source = _index.default.get(document, 'location.href');
62
58
  return this.apireq.post(`/accounts/${this.accid}/conversations`, data);
63
59
  });
64
60
  _defineProperty(this, "sendConvoEvent", (cid, ev) => this.apireq.addQuery('x-referer', _index.default.get(location, 'origin', '')).post(`/accounts/${this.accid}/conversations/${cid}/events`, ev));