@blotoutio/providers-shop-gpt-sdk 1.8.0 → 1.9.1

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 (4) hide show
  1. package/index.cjs.js +279 -77
  2. package/index.js +279 -77
  3. package/index.mjs +279 -77
  4. package/package.json +1 -1
package/index.js CHANGED
@@ -473,7 +473,6 @@ var ProvidersShopGptSdk = (function () {
473
473
  return url;
474
474
  };
475
475
  const processQuery = async (query, threadId, productHandle) => {
476
- var _a;
477
476
  const response = await fetchImpl(getURL('/query'), {
478
477
  method: 'POST',
479
478
  headers: getHeaders(),
@@ -488,14 +487,7 @@ var ProvidersShopGptSdk = (function () {
488
487
  if (!response.ok) {
489
488
  throw new Error(`Failed to process the query - ${response.status}: ${await response.text()}`);
490
489
  }
491
- const data = (await response.json());
492
- return {
493
- messageId: data.messageId,
494
- message: data.message,
495
- products: (_a = data.products) === null || _a === void 0 ? void 0 : _a.filter((item) => !!item).map((item) => ({ ...item, quantity: 1 })),
496
- chatTitle: data.chatTitle,
497
- welcomePrompts: data.welcomePrompts,
498
- };
490
+ return response;
499
491
  };
500
492
  const fetchChatHistory = async (threadId) => {
501
493
  if (!threadId) {
@@ -629,7 +621,7 @@ var ProvidersShopGptSdk = (function () {
629
621
  // exit if not in top window
630
622
  return;
631
623
  }
632
- const { enabled, mode, devMode, merchantUrl, profiles, productHandles, targetPath, view, brandName, quickPrompts, merchantImage, latestThreadLoad, } = (_c = params.manifest.variables) !== null && _c !== void 0 ? _c : {};
624
+ const { enabled, mode, devMode, merchantUrl, profiles, productHandles, targetPath, view, brandName, quickPrompts, merchantImage, latestThreadLoad, botIconUrl, css, } = (_c = params.manifest.variables) !== null && _c !== void 0 ? _c : {};
633
625
  const experiment = createExperiment({
634
626
  name: getExperimentName(mode),
635
627
  userId: params.userId,
@@ -663,6 +655,8 @@ var ProvidersShopGptSdk = (function () {
663
655
  quickPrompts,
664
656
  merchantImage,
665
657
  latestThreadLoad: latestThreadLoad !== null && latestThreadLoad !== void 0 ? latestThreadLoad : DEFAULT_MAX_THREAD_AGE,
658
+ botIconUrl,
659
+ css,
666
660
  });
667
661
  }
668
662
  };
@@ -789,6 +783,14 @@ var ProvidersShopGptSdk = (function () {
789
783
  const shopGPTStyles = i$4 `
790
784
  ${scrollBarStyles}
791
785
 
786
+ :host {
787
+ --shopgpt-primary: #001531;
788
+ --shopgpt-secondary: #172a41;
789
+ --shopgpt-white: #ffffff;
790
+ --shopgpt-border: #dbe2eb;
791
+ --shopgpt-warning: #ffcc81;
792
+ }
793
+
792
794
  * {
793
795
  box-sizing: border-box;
794
796
  }
@@ -821,6 +823,7 @@ var ProvidersShopGptSdk = (function () {
821
823
  0px 20px 20px 0px rgba(0, 0, 0, 0.08);
822
824
  position: fixed;
823
825
  z-index: 2000;
826
+ background: var(--shopgpt-white);
824
827
 
825
828
  @media screen and (max-width: 768px) {
826
829
  min-height: unset;
@@ -839,21 +842,21 @@ var ProvidersShopGptSdk = (function () {
839
842
  z-index: 1000;
840
843
 
841
844
  button {
842
- color: #ffffff;
845
+ color: var(--shopgpt-white);
843
846
  border: none;
844
847
  cursor: pointer;
845
848
  width: 56px;
846
849
  height: 56px;
847
- background-color: #001531;
850
+ background-color: var(--shopgpt-primary);
848
851
  border-radius: 50%;
849
852
  justify-content: center;
850
853
  align-items: center;
851
- box-shadow: 0 0 4px 1px #ffffff;
854
+ box-shadow: 0 0 4px 1px var(--shopgpt-white);
852
855
  }
853
856
 
854
857
  .chatbot-hover-text {
855
858
  position: absolute;
856
- color: #172a41;
859
+ color: var(--shopgpt-secondary);
857
860
  padding: 8px;
858
861
  white-space: nowrap;
859
862
  font-size: 16px;
@@ -866,7 +869,7 @@ var ProvidersShopGptSdk = (function () {
866
869
  right: calc(100% + 5px);
867
870
 
868
871
  border-radius: 5px 5px 0px;
869
- background: #ffcc81;
872
+ background: var(--shopgpt-warning);
870
873
  box-shadow: 0px 4px 6px -1px rgba(0, 0, 0, 0.1),
871
874
  0px 2px 4px -1px rgba(0, 0, 0, 0.06);
872
875
 
@@ -888,7 +891,7 @@ var ProvidersShopGptSdk = (function () {
888
891
  display: flex;
889
892
  overflow: hidden;
890
893
  height: 100%;
891
- background: #ffffff;
894
+ background: var(--shopgpt-white);
892
895
  justify-content: center;
893
896
  align-items: center;
894
897
  padding: 25px;
@@ -899,7 +902,7 @@ var ProvidersShopGptSdk = (function () {
899
902
  .shopgpt-container {
900
903
  display: flex;
901
904
  gap: 1px;
902
- background: #dbe2eb;
905
+ background: var(--shopgpt-border);
903
906
  height: 100%;
904
907
  width: 100%;
905
908
 
@@ -1226,6 +1229,16 @@ var ProvidersShopGptSdk = (function () {
1226
1229
  constructor() {
1227
1230
  super(...arguments);
1228
1231
  this.deleteAllThreads = false;
1232
+ this.isStylesheetInjected = false;
1233
+ }
1234
+ connectedCallback() {
1235
+ super.connectedCallback();
1236
+ if (!this.isStylesheetInjected && this.css) {
1237
+ const sheet = new CSSStyleSheet();
1238
+ sheet.replaceSync(this.css);
1239
+ this.shadowRoot.adoptedStyleSheets.push(sheet);
1240
+ this.isStylesheetInjected = true;
1241
+ }
1229
1242
  }
1230
1243
  getDomain() {
1231
1244
  var _a;
@@ -1394,6 +1407,10 @@ var ProvidersShopGptSdk = (function () {
1394
1407
  r(),
1395
1408
  __metadata("design:type", Object)
1396
1409
  ], ChatThreads.prototype, "deleteAllThreads", void 0);
1410
+ __decorate([
1411
+ n({ type: String }),
1412
+ __metadata("design:type", String)
1413
+ ], ChatThreads.prototype, "css", void 0);
1397
1414
  if (!customElements.get('chat-threads')) {
1398
1415
  customElements.define('chat-threads', ChatThreads);
1399
1416
  }
@@ -1832,8 +1849,18 @@ var ProvidersShopGptSdk = (function () {
1832
1849
  }
1833
1850
 
1834
1851
  class ProductsSection extends r$2 {
1852
+ constructor() {
1853
+ super(...arguments);
1854
+ this.isStylesheetInjected = false;
1855
+ }
1835
1856
  connectedCallback() {
1836
1857
  super.connectedCallback();
1858
+ if (!this.isStylesheetInjected && this.css) {
1859
+ const sheet = new CSSStyleSheet();
1860
+ sheet.replaceSync(this.css);
1861
+ this.shadowRoot.adoptedStyleSheets.push(sheet);
1862
+ this.isStylesheetInjected = true;
1863
+ }
1837
1864
  }
1838
1865
  renderMerchantImage() {
1839
1866
  if (this.merchantImage) {
@@ -1910,6 +1937,10 @@ var ProvidersShopGptSdk = (function () {
1910
1937
  e$3('.products'),
1911
1938
  __metadata("design:type", Object)
1912
1939
  ], ProductsSection.prototype, "productsEle", void 0);
1940
+ __decorate([
1941
+ n({ type: String }),
1942
+ __metadata("design:type", String)
1943
+ ], ProductsSection.prototype, "css", void 0);
1913
1944
  if (!customElements.get('products-section')) {
1914
1945
  customElements.define('products-section', ProductsSection);
1915
1946
  }
@@ -2026,8 +2057,8 @@ var ProvidersShopGptSdk = (function () {
2026
2057
  }
2027
2058
 
2028
2059
  .chatbot-section.modal-view {
2029
- height: calc(100% - 121px);
2030
- padding: 0px 16px 44px;
2060
+ height: calc(100% - 93px);
2061
+ padding: 0px 16px 16px;
2031
2062
  gap: 16px;
2032
2063
  }
2033
2064
 
@@ -2176,6 +2207,9 @@ var ProvidersShopGptSdk = (function () {
2176
2207
  border-radius: 5px;
2177
2208
  border: 1px solid #dbe2eb;
2178
2209
  background: #fff;
2210
+ width: 36px;
2211
+ height: 36px;
2212
+ box-sizing: border-box;
2179
2213
  }
2180
2214
 
2181
2215
  .line {
@@ -2412,6 +2446,17 @@ var ProvidersShopGptSdk = (function () {
2412
2446
  }
2413
2447
  }
2414
2448
 
2449
+ footer {
2450
+ text-align: center;
2451
+ font-size: 10px;
2452
+ color: #4e647f;
2453
+ font-weight: 500;
2454
+
2455
+ a {
2456
+ text-decoration: none;
2457
+ }
2458
+ }
2459
+
2415
2460
  ${scrollBarStyles}
2416
2461
  `;
2417
2462
 
@@ -3081,12 +3126,12 @@ var ProvidersShopGptSdk = (function () {
3081
3126
  };
3082
3127
 
3083
3128
  class MarkdownRenderer extends r$2 {
3129
+ constructor() {
3130
+ super(...arguments);
3131
+ this.content = '';
3132
+ }
3084
3133
  render() {
3085
- // Remove lit markers from slot content
3086
- const slotContent = this.innerHTML
3087
- .trim()
3088
- .replace(/<!--\?lit\$[\d$]+-->/g, '');
3089
- return o(markdown(slotContent));
3134
+ return o(markdown(this.content));
3090
3135
  }
3091
3136
  }
3092
3137
  MarkdownRenderer.styles = i$4 `
@@ -3100,6 +3145,10 @@ var ProvidersShopGptSdk = (function () {
3100
3145
  }
3101
3146
  }
3102
3147
  `;
3148
+ __decorate([
3149
+ n({ type: String }),
3150
+ __metadata("design:type", Object)
3151
+ ], MarkdownRenderer.prototype, "content", void 0);
3103
3152
  if (!customElements.get('markdown-renderer')) {
3104
3153
  customElements.define('markdown-renderer', MarkdownRenderer);
3105
3154
  }
@@ -3555,6 +3604,16 @@ ${this.comment ? this.comment : E}</textarea
3555
3604
  this.showChatThreads = false;
3556
3605
  this.deleteAllThreads = false;
3557
3606
  this.userQuery = '';
3607
+ this.isStylesheetInjected = false;
3608
+ }
3609
+ connectedCallback() {
3610
+ super.connectedCallback();
3611
+ if (!this.isStylesheetInjected && this.css) {
3612
+ const sheet = new CSSStyleSheet();
3613
+ sheet.replaceSync(this.css);
3614
+ this.shadowRoot.adoptedStyleSheets.push(sheet);
3615
+ this.isStylesheetInjected = true;
3616
+ }
3558
3617
  }
3559
3618
  scrollToBottom() {
3560
3619
  var _a;
@@ -3625,12 +3684,12 @@ ${this.comment ? this.comment : E}</textarea
3625
3684
  return x `
3626
3685
  <div class="message-wrapper">
3627
3686
  <div class="message bot">
3628
- <div>
3629
- <div class="bot-icon">${botIcon}</div>
3630
- </div>
3687
+ <div>${this.renderBotIcon()}</div>
3631
3688
  <div>
3632
3689
  ${message.message
3633
- ? x ` <markdown-renderer>${message.message}</markdown-renderer>`
3690
+ ? x ` <markdown-renderer
3691
+ .content=${message.message}
3692
+ ></markdown-renderer>`
3634
3693
  : E}
3635
3694
  ${this.viewType !== 'modal' && ((_a = message.products) === null || _a === void 0 ? void 0 : _a[0])
3636
3695
  ? x `
@@ -3675,6 +3734,14 @@ ${this.comment ? this.comment : E}</textarea
3675
3734
  </div>
3676
3735
  `;
3677
3736
  }
3737
+ renderBotIcon() {
3738
+ if (this.botIconUrl) {
3739
+ return x `<div class="bot-icon">
3740
+ <img src=${this.botIconUrl} width="30" height="30" />
3741
+ </div>`;
3742
+ }
3743
+ return x ` <div class="bot-icon">${botIcon}</div> `;
3744
+ }
3678
3745
  chatWindow() {
3679
3746
  if (this.isLoadingHistory || this.isLoadingThreads) {
3680
3747
  return x `<div class="messages loading">
@@ -3685,17 +3752,13 @@ ${this.comment ? this.comment : E}</textarea
3685
3752
  <div class="messages">
3686
3753
  ${this.isTyping
3687
3754
  ? x ` <div class="message bot">
3688
- <div>
3689
- <div class="bot-icon">${botIcon}</div>
3690
- </div>
3755
+ <div>${this.renderBotIcon()}</div>
3691
3756
  ${this.typingIndicator()}
3692
3757
  </div>`
3693
3758
  : ''}
3694
3759
  ${this.isFailed
3695
3760
  ? x `<div class="message bot">
3696
- <div>
3697
- <div class="bot-icon">${botIcon}</div>
3698
- </div>
3761
+ <div>${this.renderBotIcon()}</div>
3699
3762
  <div>
3700
3763
  <p>
3701
3764
  Uh-oh! Looks like I tripped over some alpha-stage wires.
@@ -3713,9 +3776,7 @@ ${this.comment ? this.comment : E}</textarea
3713
3776
  return x ` <div class="message user">${message.message}</div> `;
3714
3777
  })}
3715
3778
  <div class="message bot">
3716
- <div>
3717
- <div class="bot-icon">${botIcon}</div>
3718
- </div>
3779
+ <div>${this.renderBotIcon()}</div>
3719
3780
  <div>
3720
3781
  <p>
3721
3782
  Hi,
@@ -3840,7 +3901,11 @@ ${this.comment ? this.comment : E}</textarea
3840
3901
  modalViewHeader() {
3841
3902
  var _a;
3842
3903
  return x `
3843
- <div>${botIcon}</div>
3904
+ <div>
3905
+ ${this.botIconUrl
3906
+ ? x `<img src=${this.botIconUrl} width="30" height="30" />`
3907
+ : botIcon}
3908
+ </div>
3844
3909
  <h2>${((_a = this.thread) === null || _a === void 0 ? void 0 : _a.title) || 'New Search'}</h2>
3845
3910
  <div class="btns-wrapper">
3846
3911
  <tooltip-component .position=${'bottom-right'} .text=${'New Chat'}>
@@ -4026,6 +4091,11 @@ ${this.comment ? this.comment : E}</textarea
4026
4091
  ${sendFilledIcon}
4027
4092
  </button>
4028
4093
  </form>
4094
+ ${this.viewType === 'modal'
4095
+ ? x ` <footer>
4096
+ Powered by <a href="https://blotout.io">Blotout</a>
4097
+ </footer>`
4098
+ : E}
4029
4099
  </div>
4030
4100
  <personalize-dialog
4031
4101
  .createChatThread=${this.createChatThread.bind(this)}
@@ -4082,6 +4152,10 @@ ${this.comment ? this.comment : E}</textarea
4082
4152
  n({ type: String }),
4083
4153
  __metadata("design:type", Object)
4084
4154
  ], ChatSection.prototype, "merchantImage", void 0);
4155
+ __decorate([
4156
+ n({ type: String }),
4157
+ __metadata("design:type", Object)
4158
+ ], ChatSection.prototype, "botIconUrl", void 0);
4085
4159
  __decorate([
4086
4160
  n({ type: String }),
4087
4161
  __metadata("design:type", Object)
@@ -4170,15 +4244,78 @@ ${this.comment ? this.comment : E}</textarea
4170
4244
  n({ type: String }),
4171
4245
  __metadata("design:type", Object)
4172
4246
  ], ChatSection.prototype, "userQuery", void 0);
4247
+ __decorate([
4248
+ n({ type: String }),
4249
+ __metadata("design:type", String)
4250
+ ], ChatSection.prototype, "css", void 0);
4173
4251
  if (!customElements.get('chat-section')) {
4174
4252
  customElements.define('chat-section', ChatSection);
4175
4253
  }
4176
4254
 
4255
+ async function* streamToIterable(stream) {
4256
+ const reader = stream.getReader();
4257
+ while (true) {
4258
+ const { done, value } = await reader.read();
4259
+ if (done)
4260
+ return;
4261
+ yield value;
4262
+ }
4263
+ }
4264
+ const handleEventSource = async (response, onEvent) => {
4265
+ var _a, _b;
4266
+ if (!response.body) {
4267
+ throw new Error('No body found in response');
4268
+ }
4269
+ let buffer = '';
4270
+ for await (const chunk of streamToIterable(response.body.pipeThrough(new TextDecoderStream()))) {
4271
+ buffer += chunk;
4272
+ const sections = buffer.split('\n\n');
4273
+ buffer = sections.pop() || '';
4274
+ for (const section of sections) {
4275
+ const event = parseMessage(section, true);
4276
+ onEvent((_a = event.event) !== null && _a !== void 0 ? _a : '', event.data);
4277
+ }
4278
+ }
4279
+ if (buffer) {
4280
+ const event = parseMessage(buffer, true);
4281
+ onEvent((_b = event.event) !== null && _b !== void 0 ? _b : '', event.data);
4282
+ }
4283
+ };
4284
+ const parseMessage = (message, parseDataAsJSON) => {
4285
+ const fields = message.split('\n');
4286
+ const result = {};
4287
+ for (const field of fields) {
4288
+ if (field.startsWith(':')) {
4289
+ continue;
4290
+ }
4291
+ if (field.startsWith('event: ')) {
4292
+ result.event = field.slice(7);
4293
+ }
4294
+ else if (field.startsWith('data: ')) {
4295
+ if (result.data) {
4296
+ result.data += '\n';
4297
+ }
4298
+ else {
4299
+ result.data = '';
4300
+ }
4301
+ result.data += field.slice(6);
4302
+ }
4303
+ else if (field.startsWith('retry: ')) {
4304
+ result.retry = field.slice(7);
4305
+ }
4306
+ }
4307
+ if (result.data && parseDataAsJSON) {
4308
+ result.data = JSON.parse(result.data);
4309
+ }
4310
+ return result;
4311
+ };
4312
+
4177
4313
  const DIALOG_DELAY = 1000;
4178
4314
  const normalizePath = (path) => path.replace(/\/$/, '');
4179
4315
  class ShopGPT extends r$2 {
4180
4316
  constructor() {
4181
4317
  super(...arguments);
4318
+ this.isStylesheetInjected = false;
4182
4319
  this.latestThreadLoad = DEFAULT_MAX_THREAD_AGE;
4183
4320
  this.modalState = 'close';
4184
4321
  this.isLoadingHistory = false;
@@ -4212,6 +4349,12 @@ ${this.comment ? this.comment : E}</textarea
4212
4349
  }
4213
4350
  connectedCallback() {
4214
4351
  super.connectedCallback();
4352
+ if (!this.isStylesheetInjected && this.css) {
4353
+ const sheet = new CSSStyleSheet();
4354
+ sheet.replaceSync(this.css);
4355
+ this.shadowRoot.adoptedStyleSheets.push(sheet);
4356
+ this.isStylesheetInjected = true;
4357
+ }
4215
4358
  if (!this.view || this.view === 'overlay') {
4216
4359
  if (!this.path) {
4217
4360
  return;
@@ -4281,27 +4424,12 @@ ${this.comment ? this.comment : E}</textarea
4281
4424
  : undefined;
4282
4425
  try {
4283
4426
  this.isTyping = true;
4284
- const reply = await this.shopGPTAPI.processQuery('', thread.threadId, productHandle);
4285
- if (reply.chatTitle) {
4286
- this.setChatTitle(this.selectedThreadId, reply.chatTitle);
4287
- }
4288
- this.messages = [
4289
- {
4290
- messageId: reply.messageId,
4291
- sender: 'bot',
4292
- message: reply.message,
4293
- products: reply.products,
4294
- welcomePrompts: reply.welcomePrompts,
4295
- },
4296
- ...this.messages,
4297
- ];
4298
- this.products = reply.products || [];
4427
+ const response = await this.shopGPTAPI.processQuery('', thread.threadId, productHandle);
4428
+ this.processMessageResponse(response);
4299
4429
  }
4300
4430
  catch (error) {
4301
4431
  logger.error(error);
4302
4432
  this.isFailed = true;
4303
- }
4304
- finally {
4305
4433
  this.isTyping = false;
4306
4434
  }
4307
4435
  }
@@ -4439,6 +4567,92 @@ ${this.comment ? this.comment : E}</textarea
4439
4567
  .catch(logger.error)
4440
4568
  .finally(() => (this.isLoadingThreads = false));
4441
4569
  }
4570
+ handleMessageChunks(messageData) {
4571
+ if (!messageData.message) {
4572
+ return;
4573
+ }
4574
+ const latestMessage = this.messages[0];
4575
+ this.isTyping = false;
4576
+ if (latestMessage === null || latestMessage === void 0 ? void 0 : latestMessage.isChunk) {
4577
+ this.messages = [
4578
+ {
4579
+ ...latestMessage,
4580
+ message: latestMessage.message + messageData.message,
4581
+ isChunk: messageData.isChunk,
4582
+ sender: 'bot',
4583
+ },
4584
+ ...this.messages.slice(1),
4585
+ ];
4586
+ }
4587
+ else {
4588
+ this.messages = [
4589
+ {
4590
+ sender: 'bot',
4591
+ message: messageData.message || '',
4592
+ isChunk: messageData.isChunk,
4593
+ },
4594
+ ...this.messages,
4595
+ ];
4596
+ }
4597
+ }
4598
+ handleCompleteMessage(messageData) {
4599
+ const latestMessage = this.messages[0];
4600
+ this.messages = [
4601
+ {
4602
+ ...latestMessage,
4603
+ message: messageData.message || '',
4604
+ messageId: messageData.messageId,
4605
+ welcomePrompts: messageData.welcomePrompts,
4606
+ sender: 'bot',
4607
+ isChunk: false,
4608
+ },
4609
+ ...this.messages.slice(1),
4610
+ ];
4611
+ }
4612
+ handleProductsComplete(products, isMessageCompleted) {
4613
+ if (!products || !isMessageCompleted) {
4614
+ return;
4615
+ }
4616
+ const latestMessage = this.messages[0];
4617
+ this.messages = [
4618
+ {
4619
+ ...latestMessage,
4620
+ products,
4621
+ },
4622
+ ...this.messages.slice(1),
4623
+ ];
4624
+ if (products.length) {
4625
+ this.products = products;
4626
+ }
4627
+ }
4628
+ processMessageResponse(response) {
4629
+ let isMessageCompleted = false;
4630
+ let products;
4631
+ handleEventSource(response, (eventName, data) => {
4632
+ if (eventName === 'ChatTitle') {
4633
+ this.setChatTitle(this.selectedThreadId, data.chatTitle || '');
4634
+ }
4635
+ else if (eventName === 'Message') {
4636
+ this.handleMessageChunks(data);
4637
+ }
4638
+ else if (eventName === 'MessageComplete') {
4639
+ isMessageCompleted = true;
4640
+ this.handleProductsComplete(products, isMessageCompleted);
4641
+ this.handleCompleteMessage(data);
4642
+ }
4643
+ else if (eventName === 'ProductsComplete') {
4644
+ this.handleProductsComplete(data.products, isMessageCompleted);
4645
+ products = data.products;
4646
+ }
4647
+ else if (eventName === 'error') {
4648
+ if (this.messages[0].isChunk) {
4649
+ this.messages = this.messages.slice(1);
4650
+ }
4651
+ this.isFailed = true;
4652
+ throw new Error(data);
4653
+ }
4654
+ });
4655
+ }
4442
4656
  async sendMessageToServer(e, message) {
4443
4657
  e.preventDefault();
4444
4658
  e.stopPropagation();
@@ -4449,32 +4663,12 @@ ${this.comment ? this.comment : E}</textarea
4449
4663
  try {
4450
4664
  this.messages = [{ sender: 'user', message }, ...this.messages];
4451
4665
  this.isTyping = true;
4452
- const reply = await this.submitQuery(message);
4453
- if (!reply) {
4454
- return;
4455
- }
4456
- if (reply.chatTitle) {
4457
- this.setChatTitle(this.selectedThreadId, reply.chatTitle);
4458
- }
4459
- this.messages = [
4460
- {
4461
- messageId: reply.messageId,
4462
- sender: 'bot',
4463
- message: reply.message,
4464
- products: reply.products,
4465
- welcomePrompts: reply.welcomePrompts,
4466
- },
4467
- ...this.messages,
4468
- ];
4469
- if (reply.products && reply.products.length > 0) {
4470
- this.products = reply.products;
4471
- }
4666
+ const response = await this.submitQuery(message);
4667
+ this.processMessageResponse(response);
4472
4668
  }
4473
4669
  catch (err) {
4474
4670
  logger.error(err);
4475
4671
  this.isFailed = true;
4476
- }
4477
- finally {
4478
4672
  this.isTyping = false;
4479
4673
  }
4480
4674
  }
@@ -4521,6 +4715,7 @@ ${this.comment ? this.comment : E}</textarea
4521
4715
  .isLoading=${this.isLoadingThreads}
4522
4716
  .isTyping=${this.isTyping}
4523
4717
  .merchantUrl=${this.merchantUrl}
4718
+ .css=${this.css}
4524
4719
  ></chat-threads>
4525
4720
  <products-section
4526
4721
  .merchantImage=${this.merchantImage}
@@ -4528,6 +4723,7 @@ ${this.comment ? this.comment : E}</textarea
4528
4723
  .isLoadingHistory=${this.isLoadingHistory}
4529
4724
  .siteCurrency=${this.getSiteCurrency()}
4530
4725
  .isLoadingThreads=${this.isLoadingThreads}
4726
+ .css=${this.css}
4531
4727
  ></products-section>
4532
4728
  <chat-section
4533
4729
  .prompts=${this.quickPrompts}
@@ -4546,6 +4742,8 @@ ${this.comment ? this.comment : E}</textarea
4546
4742
  .viewType=${'overlay'}
4547
4743
  .isLoadingThreads=${this.isLoadingThreads}
4548
4744
  .customPrompts=${this.customPrompts}
4745
+ .botIconUrl=${this.botIconUrl}
4746
+ .css=${this.css}
4549
4747
  ></chat-section>
4550
4748
  </div>
4551
4749
  </dialog>
@@ -4597,6 +4795,8 @@ ${this.comment ? this.comment : E}</textarea
4597
4795
  .isLoadingThreads=${this.isLoadingThreads}
4598
4796
  .merchantImage=${this.merchantImage}
4599
4797
  .customPrompts=${this.customPrompts}
4798
+ .botIconUrl=${this.botIconUrl}
4799
+ .css=${this.css}
4600
4800
  ></chat-section>
4601
4801
  </div>
4602
4802
  `;
@@ -4678,6 +4878,8 @@ ${this.comment ? this.comment : E}</textarea
4678
4878
  shopGPT.quickPrompts = params.quickPrompts;
4679
4879
  shopGPT.merchantImage = params.merchantImage;
4680
4880
  shopGPT.latestThreadLoad = params.latestThreadLoad;
4881
+ shopGPT.botIconUrl = params.botIconUrl;
4882
+ shopGPT.css = params.css;
4681
4883
  document.body.append(shopGPT);
4682
4884
  },
4683
4885
  destroy() {