@chat21/chat21-web-widget 5.1.34 → 5.2.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 (191) hide show
  1. package/.angular-mcp-cache/package.json +1 -0
  2. package/.cursor/angular18-accessibility-auditor-skill.md +442 -0
  3. package/.cursor/mcp.json +15 -0
  4. package/.github/workflows/playwright.yml +27 -0
  5. package/CHANGELOG.md +25 -0
  6. package/Dockerfile +4 -5
  7. package/README.md +1 -1
  8. package/angular.json +21 -3
  9. package/docs/ACCESSIBILITY-STATEMENT.md +388 -0
  10. package/docs/TILEDESK_WIDGET_ACCESSIBILITY_ALIGNMENT.md +60 -0
  11. package/docs/TILEDESK_WIDGET_ACCESSIBILITY_STATEMENT_COMPLETE.md +386 -0
  12. package/env.sample +3 -2
  13. package/mocks/voice-websocket-mock/server.cjs +245 -0
  14. package/package.json +10 -3
  15. package/playwright.config.ts +41 -0
  16. package/src/app/app.component.html +2 -2
  17. package/src/app/app.component.scss +25 -14
  18. package/src/app/app.component.spec.ts +21 -6
  19. package/src/app/app.module.ts +13 -0
  20. package/src/app/component/conversation-detail/conversation/conversation.component.html +25 -11
  21. package/src/app/component/conversation-detail/conversation/conversation.component.scss +38 -0
  22. package/src/app/component/conversation-detail/conversation/conversation.component.spec.ts +644 -75
  23. package/src/app/component/conversation-detail/conversation/conversation.component.ts +70 -2
  24. package/src/app/component/conversation-detail/conversation-audio-recorder/conversation-audio-recorder.component.html +25 -13
  25. package/src/app/component/conversation-detail/conversation-audio-recorder/conversation-audio-recorder.component.spec.ts +123 -5
  26. package/src/app/component/conversation-detail/conversation-audio-recorder/conversation-audio-recorder.component.ts +1 -0
  27. package/src/app/component/conversation-detail/conversation-content/conversation-content.component.html +23 -10
  28. package/src/app/component/conversation-detail/conversation-content/conversation-content.component.scss +18 -0
  29. package/src/app/component/conversation-detail/conversation-content/conversation-content.component.spec.ts +241 -149
  30. package/src/app/component/conversation-detail/conversation-content/conversation-content.component.ts +8 -5
  31. package/src/app/component/conversation-detail/conversation-emojii/conversation-emojii.component.spec.ts +53 -3
  32. package/src/app/component/conversation-detail/conversation-footer/conversation-footer.component.html +203 -110
  33. package/src/app/component/conversation-detail/conversation-footer/conversation-footer.component.scss +212 -1
  34. package/src/app/component/conversation-detail/conversation-footer/conversation-footer.component.spec.ts +458 -78
  35. package/src/app/component/conversation-detail/conversation-footer/conversation-footer.component.ts +288 -76
  36. package/src/app/component/conversation-detail/conversation-header/conversation-header.component.html +113 -53
  37. package/src/app/component/conversation-detail/conversation-header/conversation-header.component.scss +12 -4
  38. package/src/app/component/conversation-detail/conversation-header/conversation-header.component.spec.ts +274 -29
  39. package/src/app/component/conversation-detail/conversation-internal-frame/conversation-internal-frame.component.html +23 -9
  40. package/src/app/component/conversation-detail/conversation-internal-frame/conversation-internal-frame.component.spec.ts +80 -8
  41. package/src/app/component/conversation-detail/conversation-preview/conversation-preview.component.html +29 -23
  42. package/src/app/component/conversation-detail/conversation-preview/conversation-preview.component.spec.ts +185 -16
  43. package/src/app/component/conversation-detail/conversation-preview/conversation-preview.component.ts +34 -14
  44. package/src/app/component/conversation-detail/stream-audio-spectrum/stream-audio-spectrum.component.html +46 -0
  45. package/src/app/component/conversation-detail/stream-audio-spectrum/stream-audio-spectrum.component.scss +83 -0
  46. package/src/app/component/conversation-detail/stream-audio-spectrum/stream-audio-spectrum.component.ts +192 -0
  47. package/src/app/component/error-alert/error-alert.component.spec.ts +65 -5
  48. package/src/app/component/eyeeye-catcher-card/eyeeye-catcher-card.component.html +16 -7
  49. package/src/app/component/eyeeye-catcher-card/eyeeye-catcher-card.component.scss +21 -0
  50. package/src/app/component/eyeeye-catcher-card/eyeeye-catcher-card.component.spec.ts +89 -7
  51. package/src/app/component/form/form-builder/form-builder.component.html +1 -1
  52. package/src/app/component/form/form-builder/form-builder.component.spec.ts +163 -21
  53. package/src/app/component/form/inputs/form-checkbox/form-checkbox.component.html +8 -4
  54. package/src/app/component/form/inputs/form-checkbox/form-checkbox.component.scss +10 -5
  55. package/src/app/component/form/inputs/form-checkbox/form-checkbox.component.spec.ts +90 -16
  56. package/src/app/component/form/inputs/form-checkbox/form-checkbox.component.ts +26 -0
  57. package/src/app/component/form/inputs/form-label/form-label.component.spec.ts +45 -11
  58. package/src/app/component/form/inputs/form-radio-button/form-radio-button.component.spec.ts +24 -6
  59. package/src/app/component/form/inputs/form-select/form-select.component.spec.ts +14 -5
  60. package/src/app/component/form/inputs/form-text/form-text.component.html +14 -12
  61. package/src/app/component/form/inputs/form-text/form-text.component.scss +11 -1
  62. package/src/app/component/form/inputs/form-text/form-text.component.spec.ts +113 -17
  63. package/src/app/component/form/inputs/form-text/form-text.component.ts +35 -3
  64. package/src/app/component/form/inputs/form-textarea/form-textarea.component.html +13 -11
  65. package/src/app/component/form/inputs/form-textarea/form-textarea.component.scss +6 -5
  66. package/src/app/component/form/inputs/form-textarea/form-textarea.component.spec.ts +149 -13
  67. package/src/app/component/form/inputs/form-textarea/form-textarea.component.ts +26 -0
  68. package/src/app/component/form/prechat-form/prechat-form.component.html +14 -11
  69. package/src/app/component/form/prechat-form/prechat-form.component.spec.ts +102 -10
  70. package/src/app/component/form/prechat-form/prechat-form.component.ts +8 -1
  71. package/src/app/component/form/prechat-form-test-mock.ts +35 -0
  72. package/src/app/component/home/home.component.html +38 -31
  73. package/src/app/component/home/home.component.scss +4 -2
  74. package/src/app/component/home/home.component.spec.ts +226 -11
  75. package/src/app/component/home-conversations/home-conversations.component.html +30 -26
  76. package/src/app/component/home-conversations/home-conversations.component.scss +3 -0
  77. package/src/app/component/home-conversations/home-conversations.component.spec.ts +212 -36
  78. package/src/app/component/last-message/last-message.component.html +15 -9
  79. package/src/app/component/last-message/last-message.component.scss +16 -2
  80. package/src/app/component/last-message/last-message.component.spec.ts +204 -23
  81. package/src/app/component/launcher-button/launcher-button.component.html +8 -13
  82. package/src/app/component/launcher-button/launcher-button.component.spec.ts +104 -8
  83. package/src/app/component/list-all-conversations/list-all-conversations.component.html +12 -17
  84. package/src/app/component/list-all-conversations/list-all-conversations.component.scss +2 -0
  85. package/src/app/component/list-conversations/list-conversations.component.html +22 -22
  86. package/src/app/component/menu-options/menu-options.component.html +30 -20
  87. package/src/app/component/menu-options/menu-options.component.spec.ts +125 -9
  88. package/src/app/component/message/audio/audio.component.html +13 -15
  89. package/src/app/component/message/audio/audio.component.spec.ts +140 -5
  90. package/src/app/component/message/audio/audio.component.ts +1 -5
  91. package/src/app/component/message/audio-sync/audio-sync.component.html +18 -0
  92. package/src/app/component/message/audio-sync/audio-sync.component.scss +65 -0
  93. package/src/app/component/message/audio-sync/audio-sync.component.spec.ts +112 -0
  94. package/src/app/component/message/audio-sync/audio-sync.component.ts +714 -0
  95. package/src/app/component/message/avatar/avatar.component.html +2 -2
  96. package/src/app/component/message/avatar/avatar.component.spec.ts +99 -7
  97. package/src/app/component/message/bubble-message/bubble-message.component.html +41 -51
  98. package/src/app/component/message/bubble-message/bubble-message.component.scss +54 -1
  99. package/src/app/component/message/bubble-message/bubble-message.component.spec.ts +147 -57
  100. package/src/app/component/message/bubble-message/bubble-message.component.ts +95 -13
  101. package/src/app/component/message/buttons/action-button/action-button.component.html +3 -4
  102. package/src/app/component/message/buttons/action-button/action-button.component.spec.ts +49 -5
  103. package/src/app/component/message/buttons/link-button/link-button.component.scss +5 -8
  104. package/src/app/component/message/buttons/link-button/link-button.component.spec.ts +50 -5
  105. package/src/app/component/message/buttons/text-button/text-button.component.spec.ts +44 -5
  106. package/src/app/component/message/carousel/carousel.component.html +29 -16
  107. package/src/app/component/message/carousel/carousel.component.scss +20 -8
  108. package/src/app/component/message/carousel/carousel.component.spec.ts +80 -3
  109. package/src/app/component/message/carousel/carousel.component.ts +16 -0
  110. package/src/app/component/message/frame/frame.component.html +9 -4
  111. package/src/app/component/message/frame/frame.component.spec.ts +34 -15
  112. package/src/app/component/message/frame/frame.component.ts +7 -2
  113. package/src/app/component/message/html/html.component.html +1 -1
  114. package/src/app/component/message/html/html.component.scss +1 -1
  115. package/src/app/component/message/html/html.component.spec.ts +24 -7
  116. package/src/app/component/message/image/image.component.html +12 -10
  117. package/src/app/component/message/image/image.component.scss +16 -0
  118. package/src/app/component/message/image/image.component.spec.ts +101 -15
  119. package/src/app/component/message/image/image.component.ts +90 -51
  120. package/src/app/component/message/info-message/info-message.component.spec.ts +26 -14
  121. package/src/app/component/message/json-sources/json-sources.component.html +6 -5
  122. package/src/app/component/message/json-sources/json-sources.component.scss +26 -18
  123. package/src/app/component/message/json-sources/json-sources.component.ts +41 -0
  124. package/src/app/component/message/like-unlike/like-unlike.component.html +7 -9
  125. package/src/app/component/message/like-unlike/like-unlike.component.spec.ts +31 -3
  126. package/src/app/component/message/return-receipt/return-receipt.component.spec.ts +38 -17
  127. package/src/app/component/message/text/text.component.html +3 -3
  128. package/src/app/component/message/text/text.component.scss +80 -86
  129. package/src/app/component/message/text/text.component.spec.ts +106 -13
  130. package/src/app/component/message-attachment/message-attachment.component.spec.ts +134 -13
  131. package/src/app/component/selection-department/selection-department.component.html +21 -23
  132. package/src/app/component/selection-department/selection-department.component.spec.ts +159 -14
  133. package/src/app/component/selection-department/selection-department.component.ts +8 -1
  134. package/src/app/component/send-button/send-button.component.html +5 -13
  135. package/src/app/component/send-button/send-button.component.spec.ts +2 -2
  136. package/src/app/component/star-rating-widget/star-rating-widget.component.html +51 -81
  137. package/src/app/directives/tooltip.directive.spec.ts +8 -4
  138. package/src/app/modals/confirm-close/confirm-close.component.html +20 -8
  139. package/src/app/modals/confirm-close/confirm-close.component.scss +3 -0
  140. package/src/app/modals/confirm-close/confirm-close.component.spec.ts +13 -4
  141. package/src/app/modals/confirm-close/confirm-close.component.ts +8 -1
  142. package/src/app/pipe/html-entites-encode.pipe.spec.ts +35 -2
  143. package/src/app/pipe/marked.pipe.spec.ts +38 -2
  144. package/src/app/pipe/marked.pipe.ts +51 -41
  145. package/src/app/providers/app-config.service.ts +4 -2
  146. package/src/app/providers/brand.service.spec.ts +23 -2
  147. package/src/app/providers/brand.service.ts +1 -1
  148. package/src/app/providers/global-settings.service.spec.ts +1009 -14
  149. package/src/app/providers/global-settings.service.ts +40 -2
  150. package/src/app/providers/json-sources-parser.service.ts +13 -1
  151. package/src/app/providers/translator.service.ts +24 -7
  152. package/src/app/providers/tts-audio-playback-coordinator.service.spec.ts +116 -0
  153. package/src/app/providers/tts-audio-playback-coordinator.service.ts +122 -0
  154. package/src/app/providers/voice/STT&TTS/openai-voice.config.ts +12 -0
  155. package/src/app/providers/voice/STT&TTS/openai-voice.provider.ts +156 -0
  156. package/src/app/providers/voice/STT&TTS/speech-provider.abstract.ts +39 -0
  157. package/src/app/providers/voice/audio.types.ts +40 -0
  158. package/src/app/providers/voice/vad.service.spec.ts +28 -0
  159. package/src/app/providers/voice/vad.service.ts +70 -0
  160. package/src/app/providers/voice/voice-streaming.service.spec.ts +23 -0
  161. package/src/app/providers/voice/voice-streaming.service.ts +702 -0
  162. package/src/app/providers/voice/voice-streaming.types.ts +112 -0
  163. package/src/app/providers/voice/voice.service.spec.ts +227 -0
  164. package/src/app/providers/voice/voice.service.ts +969 -0
  165. package/src/app/sass/_variables.scss +2 -0
  166. package/src/app/sass/animations.scss +19 -1
  167. package/src/app/shims/onnxruntime-web-wasm.ts +4 -0
  168. package/src/app/utils/globals.ts +14 -0
  169. package/src/app/utils/utils-resources.ts +1 -1
  170. package/src/assets/i18n/en.json +128 -100
  171. package/src/assets/i18n/es.json +128 -100
  172. package/src/assets/i18n/fr.json +128 -100
  173. package/src/assets/i18n/it.json +128 -98
  174. package/src/assets/onnx/ort-wasm-simd-threaded.mjs +59 -0
  175. package/src/assets/onnx/ort-wasm-simd-threaded.wasm +0 -0
  176. package/src/assets/sounds/keyboard.mp3 +0 -0
  177. package/src/assets/vad/silero_vad_legacy.onnx +0 -0
  178. package/src/assets/vad/vad.worklet.bundle.min.js +1 -0
  179. package/src/chat21-core/models/message.ts +2 -1
  180. package/src/chat21-core/providers/chat-manager.spec.ts +72 -0
  181. package/src/chat21-core/providers/firebase/firebase-conversation-handler.ts +3 -2
  182. package/src/chat21-core/providers/firebase/firebase-init-service.ts +5 -5
  183. package/src/chat21-core/providers/mqtt/mqtt-conversation-handler.ts +12 -0
  184. package/src/chat21-core/providers/scripts/script.service.spec.ts +12 -2
  185. package/src/chat21-core/utils/utils-message.ts +7 -0
  186. package/src/widget-config-template.json +3 -1
  187. package/src/widget-config.json +28 -27
  188. package/tests/widget-form-rich.spec.ts +67 -0
  189. package/tests/widget-index-dev-settings.spec.ts +52 -0
  190. package/tests/widget-twp-iframe.spec.ts +39 -0
  191. package/tsconfig.json +5 -0
@@ -1,9 +1,9 @@
1
1
  <div class="c21-icon-avatar">
2
2
  <div class="c21-avatar-image profile_image">
3
3
  <!-- is a BOT -->
4
- <img *ngIf="senderID?.indexOf('bot_') !== -1 || senderFullname.toLowerCase().includes('bot')" [src]="url" (error)="onBotImgError($event)" (load)="onLoadedBot($event)"/>
4
+ <img *ngIf="senderID?.indexOf('bot_') !== -1 || senderFullname.toLowerCase().includes('bot')" [src]="url" [attr.alt]="senderFullname || 'Bot'" role="img" (error)="onBotImgError($event)" (load)="onLoadedBot($event)"/>
5
5
  <!-- is a HUMAN -->
6
- <img *ngIf="senderID?.indexOf('bot_') === -1 && !senderFullname.toLowerCase().includes('bot')" [src]="url" (error)="onHumanImgError($event)" (load)="onLoadedHuman($event)"/>
6
+ <img *ngIf="senderID?.indexOf('bot_') === -1 && !senderFullname.toLowerCase().includes('bot')" [src]="url" [attr.alt]="senderFullname || 'User'" role="img" (error)="onHumanImgError($event)" (load)="onLoadedHuman($event)"/>
7
7
  </div>
8
8
  </div>
9
9
 
@@ -1,27 +1,119 @@
1
- import { async, ComponentFixture, TestBed } from '@angular/core/testing';
1
+ import { Injectable } from '@angular/core';
2
+ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
2
3
  import { ImageRepoService } from '../../../../chat21-core/providers/abstract/image-repo.service';
3
4
 
4
5
  import { AvatarComponent } from './avatar.component';
5
6
 
7
+ @Injectable()
8
+ class ImageRepoStub extends ImageRepoService {
9
+ getImagePhotoUrl(uid: string): string {
10
+ return `https://cdn.test/photo/${uid}`;
11
+ }
12
+ checkImageExists(_uid: string, _cb: (exist: boolean) => void): void {}
13
+ }
14
+
6
15
  describe('AvatarComponent', () => {
7
16
  let component: AvatarComponent;
8
17
  let fixture: ComponentFixture<AvatarComponent>;
9
18
 
10
- beforeEach(async(() => {
19
+ beforeEach(waitForAsync(() => {
11
20
  TestBed.configureTestingModule({
12
- declarations: [ AvatarComponent ],
13
- providers: [ ImageRepoService ]
14
- })
15
- .compileComponents();
21
+ declarations: [AvatarComponent],
22
+ providers: [{ provide: ImageRepoService, useClass: ImageRepoStub }],
23
+ }).compileComponents();
16
24
  }));
17
25
 
18
26
  beforeEach(() => {
19
27
  fixture = TestBed.createComponent(AvatarComponent);
20
28
  component = fixture.componentInstance;
21
- fixture.detectChanges();
29
+ component.baseLocation = 'https://app.test';
22
30
  });
23
31
 
24
32
  it('should create', () => {
33
+ component.senderID = 'user_1';
34
+ component.senderFullname = 'Alice';
35
+ fixture.detectChanges();
25
36
  expect(component).toBeTruthy();
26
37
  });
38
+
39
+ it('ngOnInit should prefer remote photo when checkImageExists returns true', () => {
40
+ const remote = 'https://cdn.test/photo/bot_1';
41
+ spyOn(AvatarComponent.prototype as any, 'checkImageExists').and.callFake((_url: string, cb: (b: boolean) => void) => {
42
+ cb(true);
43
+ });
44
+ component.senderID = 'bot_1';
45
+ component.senderFullname = 'Support Bot';
46
+ component.ngOnInit();
47
+ expect(component.url).toBe(remote);
48
+ });
49
+
50
+ it('ngOnInit should keep default bot asset when remote image missing', () => {
51
+ spyOn(AvatarComponent.prototype as any, 'checkImageExists').and.callFake((_url: string, cb: (b: boolean) => void) => {
52
+ cb(false);
53
+ });
54
+ component.senderID = 'bot_1';
55
+ component.senderFullname = 'Bot';
56
+ component.ngOnInit();
57
+ expect(component.url).toBe(component.baseLocation + '/assets/images/tommy_bot_tiledesk.svg');
58
+ });
59
+
60
+ it('ngOnInit should use human default when not bot and photo missing', () => {
61
+ spyOn(AvatarComponent.prototype as any, 'checkImageExists').and.callFake((_url: string, cb: (b: boolean) => void) => {
62
+ cb(false);
63
+ });
64
+ component.senderID = 'user_99';
65
+ component.senderFullname = 'Bob';
66
+ component.ngOnInit();
67
+ expect(component.url).toBe(component.baseLocation + '/assets/images/chat_human_avatar.svg');
68
+ });
69
+
70
+ it('checkImageExists should invoke callback on image load', (done) => {
71
+ const imgCtor = window.Image;
72
+ (window as any).Image = function MockImage(this: any) {
73
+ setTimeout(() => this.onload && this.onload(), 0);
74
+ return this;
75
+ } as any;
76
+ component.checkImageExists('https://x', (ok) => {
77
+ (window as any).Image = imgCtor;
78
+ expect(ok).toBe(true);
79
+ done();
80
+ });
81
+ });
82
+
83
+ it('checkImageExists should invoke callback false on error', (done) => {
84
+ const imgCtor = window.Image;
85
+ (window as any).Image = function MockImage(this: any) {
86
+ setTimeout(() => this.onerror && this.onerror(), 0);
87
+ return this;
88
+ } as any;
89
+ component.checkImageExists('https://bad', (ok) => {
90
+ (window as any).Image = imgCtor;
91
+ expect(ok).toBe(false);
92
+ done();
93
+ });
94
+ });
95
+
96
+ it('onBotImgError should swap to local bot svg', () => {
97
+ const target = { src: 'bad' } as any;
98
+ component.baseLocation = 'https://host';
99
+ component.onBotImgError({ target });
100
+ expect(target.src).toContain('tommy_bot_tiledesk.svg');
101
+ });
102
+
103
+ it('onHumanImgError should swap to local human svg', () => {
104
+ const target = { src: 'bad' } as any;
105
+ component.baseLocation = 'https://host';
106
+ component.onHumanImgError({ target });
107
+ expect(target.src).toContain('chat_human_avatar.svg');
108
+ });
109
+
110
+ it('template should expose accessible name on avatar image (bot)', () => {
111
+ spyOn(AvatarComponent.prototype as any, 'checkImageExists').and.stub();
112
+ component.senderID = 'bot_x';
113
+ component.senderFullname = 'Helper Bot';
114
+ fixture.detectChanges();
115
+ const img = (fixture.nativeElement as HTMLElement).querySelector('img');
116
+ expect(img?.getAttribute('alt')).toBeTruthy();
117
+ expect(img?.getAttribute('role')).toBe('img');
118
+ });
27
119
  });
@@ -1,26 +1,4 @@
1
- <!-- [ngClass]="{'button-in-msg' : message.metadata && message.metadata.button}" -->
2
- <!-- ngStyle]="{'padding': (isImage(message) || isFrame(message))?'1px':'0 8px'}" -->
3
- <!-- 'width': (isImage(message) || isFrame(message))? sizeImage?.width + 'px': null -->
4
-
5
-
6
-
7
- <!-- <div id="bubble-message" *ngIf="isAudio(message)" [ngStyle]="{'padding': '0'}" class="messages primary-color">
8
- <div>
9
- <chat-audio-track *ngIf="isAudio(message)"
10
- [metadata]="message.metadata"
11
- ></chat-audio-track>
12
- </div>
13
- </div>
14
-
15
-
16
- [ngStyle]="{'padding': (isImage(message) || isFrame(message) || isAudio(message))?'0 0px':'0 8px'}"
17
- -->
18
-
19
-
20
-
21
-
22
-
23
- <div id="bubble-message" *ngIf="hasRenderableContent()" class="messages primary-color">
1
+ <div class="bubble-message messages primary-color" *ngIf="hasRenderableContent()">
24
2
  <div>
25
3
 
26
4
  <div *ngIf="messageType(MESSAGE_TYPE_OTHERS, message) && !isSameSender"
@@ -28,17 +6,7 @@
28
6
  [ngStyle]="{'margin': (isImage(message) || isFrame(message))? '12px 16px 8px 16px': '12px 16px 0px 16px'}" class="message_sender_fullname">
29
7
  {{message?.sender_fullname}}
30
8
  </div>
31
- <!-- message type:: image -->
32
- <!-- <div *ngIf="message.type == 'image' && message.metadata" [ngStyle] = "{ 'max-width': getSizeImg(message).width, 'max-height': getSizeImg(message).height }">
33
- <img class="message-contentX message-content-imageX" [src]="message.metadata.src" />
34
- </div> -->
35
-
36
- <!-- <img *ngIf="message.type == 'image' && message.metadata" class="message-contentX message-content-imageX"
37
- [src]="message.metadata.src" [width]="getSizeImg(message).width"
38
- [height]="getSizeImg(message).height" /> -->
39
-
40
- <!-- [width]="getMetadataSize(message.metadata).width"
41
- [height]="getMetadataSize(message.metadata).height" -->
9
+
42
10
  <chat-image *ngIf="isImage(message)"
43
11
  [metadata]="message.metadata"
44
12
  [width]="sizeImage?.width"
@@ -53,21 +21,44 @@
53
21
  (onElementRendered)="onElementRenderedFN($event)">
54
22
  </chat-frame>
55
23
 
56
- <!-- <chat-audio *ngIf="isAudio(message)"
57
- [metadata]="message.metadata"
58
- (onElementRendered)="onElementRenderedFN($event)">
59
- </chat-audio> -->
60
24
 
61
25
  <chat-audio *ngIf="isAudio(message)"
62
26
  [metadata]="message.metadata"
63
27
  [color]="fontColor"
64
- [stylesMap]="stylesMap">
28
+ [stylesMap]="stylesMap"
29
+ [translationMap]="translationMap">
65
30
  </chat-audio>
66
31
 
32
+ <!-- TTS player: only when voice proxy is NOT active (avoids double playback)
33
+ and the message was not already played by the proxy (avoids replay on session end) -->
34
+ <chat-audio-sync *ngIf="isAudioTTS(message) && !(voiceService.isWssVoiceActive$ | async) && !voiceService.wasProxyHandled(message?.uid)"
35
+ [message]="message"
36
+ [color]="fontColor">
37
+ </chat-audio-sync>
38
+
67
39
  <chat-json-sources *ngIf="jsonSources !== null && jsonSources.length > 0"
68
40
  [items]="jsonSources"
41
+ [displayFields]="jsonSourcesDisplayFields"
42
+ [backgroundColor]="jsonSourcesBackgroundColor"
69
43
  (onElementRendered)="onElementRenderedFN($event)">
70
- </chat-json-sources>
44
+ </chat-json-sources>
45
+
46
+ <!-- Karaoke display for TTS messages while a WSS voice session is active -->
47
+ <p *ngIf="isAudioTTS(message) && (voiceService.isWssVoiceActive$ | async) && _wssKaraokeWords$"
48
+ class="wss-karaoke"
49
+ [style.color]="fontColor">
50
+ <span *ngFor="let w of (_wssKaraokeWords$ | async); trackBy: trackKaraokeWord"
51
+ class="wss-word"
52
+ [class.future]="w.state === 'future'"
53
+ [class.active]="w.state === 'active'"
54
+ [class.past]="w.state === 'past'">{{ w.text }}&nbsp;</span>
55
+ </p>
56
+
57
+ <!-- Text fallback for TTS messages after the voice proxy session ended -->
58
+ <chat-text *ngIf="isAudioTTS(message) && !(voiceService.isWssVoiceActive$ | async) && voiceService.wasProxyHandled(message?.uid) && message?.text"
59
+ [text]="message?.text"
60
+ [color]="fontColor">
61
+ </chat-text>
71
62
 
72
63
 
73
64
  <!-- <chat-frame *ngIf="message.metadata && message.metadata.type && message.metadata.type.includes('video')"
@@ -80,10 +71,17 @@
80
71
  <!-- <div *ngIf="message.type == 'text'"> -->
81
72
 
82
73
  <!-- tooltip="{{message.timestamp | dateAgo}} ({{message.timestamp | date:'shortDate'}} {{message.timestamp | date:'HH:mm:ss'}})" placement="bottom" -->
83
- <div *ngIf="(message?.text && !isAudio(message)) && !isJsonSources(message)">
74
+ <div *ngIf="(message?.text && !isAudio(message) && !isAudioTTS(message)) && !isJsonSources(message)">
75
+
76
+ <!-- Word-by-word streaming reveal during an active voice session -->
77
+ <p *ngIf="_isStreaming" class="streaming-text" [style.color]="fontColor">
78
+ <span *ngFor="let w of _streamingWords; trackBy: trackWord"
79
+ class="stream-word"
80
+ [style.animation-delay]="(w.index * 80) + 'ms'">{{w.word}} </span>
81
+ </p>
84
82
 
85
83
  <!-- [htmlEnabled]="(message?.type==='html')? true : false" -->
86
- <chat-text *ngIf="jsonSources === null && message?.type !=='html'"
84
+ <chat-text *ngIf="jsonSources === null && message?.type !=='html' && !_isStreaming"
87
85
  [text]="message?.text"
88
86
  [color]="fontColor"
89
87
  (onBeforeMessageRender)="onBeforeMessageRenderFN($event)"
@@ -98,13 +96,5 @@
98
96
  </chat-html>
99
97
 
100
98
  </div>
101
-
102
99
  </div>
103
-
104
- </div>
105
-
106
-
107
-
108
-
109
-
110
-
100
+ </div>
@@ -37,4 +37,57 @@
37
37
  chat-audio {
38
38
  display: flex;
39
39
  }
40
- }
40
+ }
41
+ .streaming-text {
42
+ padding: 0;
43
+ margin: 0;
44
+ line-height: 1.5;
45
+
46
+ .stream-word {
47
+ display: inline;
48
+ opacity: 0;
49
+ animation: stream-word-in 200ms ease-out forwards;
50
+ }
51
+ }
52
+
53
+ @keyframes stream-word-in {
54
+ from {
55
+ opacity: 0;
56
+ transform: translateY(3px);
57
+ }
58
+ to {
59
+ opacity: 1;
60
+ transform: translateY(0);
61
+ }
62
+ }
63
+
64
+ // -- WSS TTS Karaoke ----------------------------------------------------------
65
+ .wss-karaoke {
66
+ // Match chat-text (ShadowDom) visual layout so there's no jump when voice opens.
67
+ // font-size must be set explicitly: the parent has font-size:10px but chat-text
68
+ // overrides it via :host { font-size: var(--font-size-bubble-message, 14px) }.
69
+ display: block;
70
+ margin: 0;
71
+ padding: 12px 16px;
72
+ font-size: var(--font-size-bubble-message, 14px);
73
+ line-height: 1.4em;
74
+ font-weight: 300;
75
+ overflow: hidden;
76
+ }
77
+
78
+ .wss-word {
79
+ display: inline;
80
+ transition: opacity 120ms ease;
81
+
82
+ &.future {
83
+ opacity: 0.35;
84
+ }
85
+
86
+ &.active {
87
+ opacity: 1;
88
+ }
89
+
90
+ &.past {
91
+ opacity: 1;
92
+ }
93
+ }
@@ -1,26 +1,67 @@
1
- import { async, ComponentFixture, TestBed } from '@angular/core/testing';
1
+ import { NO_ERRORS_SCHEMA } from '@angular/core';
2
+ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
2
3
  import { By } from '@angular/platform-browser';
4
+ import { MAX_WIDTH_IMAGES, MIN_WIDTH_IMAGES } from 'src/chat21-core/utils/constants';
5
+ import { calcImageSize } from 'src/chat21-core/utils/utils-message';
6
+ import { JsonSourcesParserService } from 'src/app/providers/json-sources-parser.service';
7
+ import { VoiceService } from 'src/app/providers/voice/voice.service';
3
8
 
4
9
  import { BubbleMessageComponent } from './bubble-message.component';
5
- import { NO_ERRORS_SCHEMA } from '@angular/core';
6
10
 
7
11
  describe('BubbleMessageComponent', () => {
8
12
  let component: BubbleMessageComponent;
9
13
  let fixture: ComponentFixture<BubbleMessageComponent>;
10
14
 
11
- beforeEach(async(() => {
15
+ const jsonSourcesParserMock = {
16
+ getUrlPreviewPayload: () => null,
17
+ parseBaseFromMessage: () => null,
18
+ enrichSources: jasmine.createSpy('enrichSources').and.resolveTo([]),
19
+ };
20
+
21
+ const voiceServiceMock = {
22
+ isWssVoiceActive: false,
23
+ markProxyHandled: jasmine.createSpy('markProxyHandled'),
24
+ voiceTtsKaraoke$: {
25
+ pipe: () => ({
26
+ subscribe: () => ({ unsubscribe: () => undefined }),
27
+ }),
28
+ },
29
+ };
30
+
31
+ const textMessage: any = {
32
+ attributes: { projectId: 'p1' },
33
+ channel_type: 'group',
34
+ recipient: 'support-group-x',
35
+ recipient_fullname: 'Guest ',
36
+ sender: 'bot_1',
37
+ sender_fullname: 'BOT2',
38
+ status: 150,
39
+ text: 'Hello',
40
+ timestamp: 1629273999970,
41
+ type: 'text',
42
+ uid: 'm1',
43
+ isSender: false,
44
+ };
45
+
46
+ beforeEach(waitForAsync(() => {
12
47
  TestBed.configureTestingModule({
13
- declarations: [ BubbleMessageComponent ],
48
+ declarations: [BubbleMessageComponent],
14
49
  schemas: [NO_ERRORS_SCHEMA],
15
- imports: [
50
+ providers: [
51
+ { provide: JsonSourcesParserService, useValue: jsonSourcesParserMock },
52
+ { provide: VoiceService, useValue: voiceServiceMock },
16
53
  ],
17
- })
18
- .compileComponents();
54
+ }).compileComponents();
19
55
  }));
20
56
 
21
57
  beforeEach(() => {
22
58
  fixture = TestBed.createComponent(BubbleMessageComponent);
23
59
  component = fixture.componentInstance;
60
+ component.stylesMap = new Map([
61
+ ['buttonFontSize', '14px'],
62
+ ['themeColor', '#000'],
63
+ ['foregroundColor', '#fff'],
64
+ ]);
24
65
  fixture.detectChanges();
25
66
  });
26
67
 
@@ -28,54 +69,103 @@ describe('BubbleMessageComponent', () => {
28
69
  expect(component).toBeTruthy();
29
70
  });
30
71
 
31
- it('should have a "chat-text" child element', () => {
32
- const messages: any = {
33
- attributes: {
34
- projectId: "6013ec749b32000045be650e",
35
- tiledesk_message_id: "611cbf8ffb379b00346660e7"
36
- },
37
- channel_type: "group",
38
- recipient: "support-group-6013ec749b32000045be650e-4904aee91f8b487aad117bcda860549d",
39
- recipient_fullname: "Guest ",
40
- sender: "bot_602256f6c001b800342cb76f",
41
- sender_fullname: "BOT2",
42
- status: 150,
43
- text: "Hello 👋. I'm a bot 🤖.\n\nChoose one of the options below or write a message to reach our staff.",
44
- timestamp: 1629273999970,
45
- type: "text",
46
- uid: "-MhNI3eaIoLTOLoX3TAu",
47
- isSender: false
48
- }
49
- component.message = messages
50
- // component.textColor = 'black'
51
- fixture.detectChanges()
52
- const textChild = fixture.debugElement.query(By.css('chat-text'))
53
- textChild.properties.text
54
- expect(textChild).toBeTruthy();
55
- })
56
-
57
- it('should have a text inside "chat-text" child element', () => {
58
- const messages: any = {
59
- attributes: {
60
- projectId: "6013ec749b32000045be650e",
61
- tiledesk_message_id: "611cbf8ffb379b00346660e7"
62
- },
63
- channel_type: "group",
64
- recipient: "support-group-6013ec749b32000045be650e-4904aee91f8b487aad117bcda860549d",
65
- recipient_fullname: "Guest ",
66
- sender: "bot_602256f6c001b800342cb76f",
67
- sender_fullname: "BOT2",
68
- status: 150,
69
- text: "Hello 👋. I'm a bot 🤖.\n\nChoose one of the options below or write a message to reach our staff.",
70
- timestamp: 1629273999970,
71
- type: "text",
72
- uid: "-MhNI3eaIoLTOLoX3TAu",
73
- isSender: false
74
- }
75
- component.message = messages
76
- // component.textColor = 'black'
77
- fixture.detectChanges()
78
- const textChild = fixture.debugElement.query(By.css('chat-text'))
79
- expect(textChild.properties.text).toEqual(messages.text)
80
- })
72
+ it('should have a chat-text child for plain text messages', () => {
73
+ component.message = textMessage;
74
+ fixture.detectChanges();
75
+ expect(fixture.debugElement.query(By.css('chat-text'))).toBeTruthy();
76
+ });
77
+
78
+ it('should bind chat-text inputs from message', () => {
79
+ component.message = textMessage;
80
+ fixture.detectChanges();
81
+ const textChild = fixture.debugElement.query(By.css('chat-text'));
82
+ expect(textChild.properties.text).toEqual(textMessage.text);
83
+ });
84
+
85
+ describe('calcImageSize', () => {
86
+ it('should scale down when width exceeds MAX_WIDTH_IMAGES', () => {
87
+ const meta = { width: MAX_WIDTH_IMAGES * 2, height: 100 };
88
+ const s = calcImageSize(meta);
89
+ expect(s.width).toBe(MAX_WIDTH_IMAGES);
90
+ });
91
+
92
+ it('should apply MIN_WIDTH when thumbnail width is small', () => {
93
+ const meta = { width: 40, height: 80 };
94
+ const s = calcImageSize(meta);
95
+ expect(s.width).toBe(MIN_WIDTH_IMAGES);
96
+ });
97
+
98
+ it('should keep metadata dimensions for mid-sized images', () => {
99
+ const meta = { width: 120, height: 60 };
100
+ const s = calcImageSize(meta);
101
+ expect(s.width).toBe(120);
102
+ expect(s.height).toBe(60);
103
+ });
104
+
105
+ it('should return raw metadata when width branch not matched', () => {
106
+ const s = calcImageSize({ width: undefined, height: 10 });
107
+ expect(s.width).toBeUndefined();
108
+ expect(s.height).toBe(10);
109
+ });
110
+ });
111
+
112
+ describe('ngOnChanges', () => {
113
+ it('should compute sizeImage from message metadata object', () => {
114
+ component.message = {
115
+ ...textMessage,
116
+ metadata: { width: 100, height: 50 },
117
+ };
118
+ component.ngOnChanges();
119
+ expect(component.sizeImage.width).toBe(100);
120
+ });
121
+
122
+ it('should ignore non-object metadata', () => {
123
+ component.message = { ...textMessage, metadata: 'x' as any };
124
+ component.ngOnChanges();
125
+ expect(component.sizeImage).toBeUndefined();
126
+ });
127
+
128
+ it('should derive fullnameColor from fontColor', () => {
129
+ component.message = textMessage;
130
+ component.fontColor = '#ff0000';
131
+ component.ngOnChanges();
132
+ expect(component.fullnameColor).toBeTruthy();
133
+ });
134
+
135
+ it('should prefer sender fullname color when name present', () => {
136
+ component.message = { ...textMessage, sender_fullname: 'Anna' };
137
+ component.fontColor = '#00ff00';
138
+ component.ngOnChanges();
139
+ expect(component.fullnameColor).toBeTruthy();
140
+ });
141
+ });
142
+
143
+ describe('emitters', () => {
144
+ beforeEach(() => {
145
+ component.message = textMessage;
146
+ });
147
+
148
+ it('onBeforeMessageRenderFN should emit with sanitizer and message', () => {
149
+ spyOn(component.onBeforeMessageRender, 'emit');
150
+ const ev = { messageEl: {}, component: {} };
151
+ component.onBeforeMessageRenderFN(ev);
152
+ expect(component.onBeforeMessageRender.emit).toHaveBeenCalled();
153
+ const arg = (component.onBeforeMessageRender.emit as jasmine.Spy).calls.mostRecent().args[0];
154
+ expect(arg.message).toBe(component.message);
155
+ expect(arg.sanitizer).toBe(component.sanitizer);
156
+ });
157
+
158
+ it('onAfterMessageRenderFN should emit', () => {
159
+ spyOn(component.onAfterMessageRender, 'emit');
160
+ const ev = { messageEl: {}, component: {} };
161
+ component.onAfterMessageRenderFN(ev);
162
+ expect(component.onAfterMessageRender.emit).toHaveBeenCalled();
163
+ });
164
+
165
+ it('onElementRenderedFN should forward element and status', () => {
166
+ spyOn(component.onElementRendered, 'emit');
167
+ component.onElementRenderedFN({ element: 'image', status: true });
168
+ expect(component.onElementRendered.emit).toHaveBeenCalledWith({ element: 'image', status: true });
169
+ });
170
+ });
81
171
  });