botframework-webchat 4.13.0 → 4.15.0

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 (260) hide show
  1. package/.eslintrc.yml +5 -104
  2. package/.prettierrc.yml +1 -1
  3. package/README.md +33 -36
  4. package/babel.config.json +2 -2
  5. package/babel.sanitize-html.config.json +10 -0
  6. package/lib/AddFullBundle.d.ts +30 -0
  7. package/lib/AddFullBundle.d.ts.map +1 -0
  8. package/lib/AddFullBundle.js +76 -0
  9. package/lib/FullComposer.d.ts +8 -0
  10. package/lib/FullComposer.d.ts.map +1 -0
  11. package/lib/FullComposer.js +6 -16
  12. package/lib/FullReactWebChat.d.ts +8 -0
  13. package/lib/FullReactWebChat.d.ts.map +1 -0
  14. package/lib/FullReactWebChat.js +8 -23
  15. package/lib/adaptiveCards/AdaptiveCardsComposer.d.ts +10 -0
  16. package/lib/adaptiveCards/AdaptiveCardsComposer.d.ts.map +1 -0
  17. package/lib/adaptiveCards/AdaptiveCardsComposer.js +6 -2
  18. package/lib/adaptiveCards/AdaptiveCardsContext.d.ts +8 -0
  19. package/lib/adaptiveCards/AdaptiveCardsContext.d.ts.map +1 -0
  20. package/lib/adaptiveCards/AdaptiveCardsContext.js +3 -3
  21. package/lib/adaptiveCards/AdaptiveCardsStyleOptions.d.ts +5 -3
  22. package/lib/adaptiveCards/AdaptiveCardsStyleOptions.d.ts.map +1 -1
  23. package/lib/adaptiveCards/AdaptiveCardsStyleSet.d.ts +7 -0
  24. package/lib/adaptiveCards/AdaptiveCardsStyleSet.d.ts.map +1 -0
  25. package/lib/{FullBundleStyleOptions.js → adaptiveCards/AdaptiveCardsStyleSet.js} +0 -0
  26. package/lib/adaptiveCards/Attachment/AdaptiveCardAttachment.d.ts +9 -0
  27. package/lib/adaptiveCards/Attachment/AdaptiveCardAttachment.d.ts.map +1 -0
  28. package/lib/adaptiveCards/Attachment/AdaptiveCardAttachment.js +1 -1
  29. package/lib/adaptiveCards/Attachment/AdaptiveCardBuilder.d.ts +28 -0
  30. package/lib/adaptiveCards/Attachment/AdaptiveCardBuilder.d.ts.map +1 -0
  31. package/lib/adaptiveCards/Attachment/AdaptiveCardBuilder.js +13 -6
  32. package/lib/adaptiveCards/Attachment/AdaptiveCardContent.d.ts +9 -0
  33. package/lib/adaptiveCards/Attachment/AdaptiveCardContent.d.ts.map +1 -0
  34. package/lib/adaptiveCards/Attachment/AdaptiveCardContent.js +8 -4
  35. package/lib/adaptiveCards/Attachment/AdaptiveCardRenderer.d.ts +12 -0
  36. package/lib/adaptiveCards/Attachment/AdaptiveCardRenderer.d.ts.map +1 -0
  37. package/lib/adaptiveCards/Attachment/AdaptiveCardRenderer.js +310 -85
  38. package/lib/adaptiveCards/Attachment/AnimationCardContent.d.ts +10 -0
  39. package/lib/adaptiveCards/Attachment/AnimationCardContent.d.ts.map +1 -0
  40. package/lib/adaptiveCards/Attachment/AnimationCardContent.js +1 -1
  41. package/lib/adaptiveCards/Attachment/AudioCardContent.d.ts +10 -0
  42. package/lib/adaptiveCards/Attachment/AudioCardContent.d.ts.map +1 -0
  43. package/lib/adaptiveCards/Attachment/AudioCardContent.js +1 -1
  44. package/lib/adaptiveCards/Attachment/CommonCard.js +11 -6
  45. package/lib/adaptiveCards/Attachment/HeroCardContent.d.ts +10 -0
  46. package/lib/adaptiveCards/Attachment/HeroCardContent.d.ts.map +1 -0
  47. package/lib/adaptiveCards/Attachment/HeroCardContent.js +11 -6
  48. package/lib/adaptiveCards/Attachment/OAuthCardContent.d.ts +10 -0
  49. package/lib/adaptiveCards/Attachment/OAuthCardContent.d.ts.map +1 -0
  50. package/lib/adaptiveCards/Attachment/OAuthCardContent.js +11 -6
  51. package/lib/adaptiveCards/Attachment/ReceiptCardContent.d.ts +10 -0
  52. package/lib/adaptiveCards/Attachment/ReceiptCardContent.d.ts.map +1 -0
  53. package/lib/adaptiveCards/Attachment/ReceiptCardContent.js +11 -6
  54. package/lib/adaptiveCards/Attachment/SignInCardContent.d.ts +10 -0
  55. package/lib/adaptiveCards/Attachment/SignInCardContent.d.ts.map +1 -0
  56. package/lib/adaptiveCards/Attachment/SignInCardContent.js +1 -1
  57. package/lib/adaptiveCards/Attachment/ThumbnailCardContent.d.ts +10 -0
  58. package/lib/adaptiveCards/Attachment/ThumbnailCardContent.d.ts.map +1 -0
  59. package/lib/adaptiveCards/Attachment/ThumbnailCardContent.js +11 -6
  60. package/lib/adaptiveCards/Attachment/VideoCardContent.d.ts +20 -0
  61. package/lib/adaptiveCards/Attachment/VideoCardContent.d.ts.map +1 -0
  62. package/lib/adaptiveCards/Attachment/VideoCardContent.js +7 -5
  63. package/lib/adaptiveCards/AttachmentForScreenReader/AdaptiveCardAttachment.js +7 -3
  64. package/lib/adaptiveCards/AttachmentForScreenReader/RichCardAttachment.js +1 -1
  65. package/lib/adaptiveCards/Styles/StyleSet/AdaptiveCardRenderer.d.ts +59 -0
  66. package/lib/adaptiveCards/Styles/StyleSet/AdaptiveCardRenderer.d.ts.map +1 -0
  67. package/lib/adaptiveCards/Styles/StyleSet/AdaptiveCardRenderer.js +8 -1
  68. package/lib/adaptiveCards/Styles/adaptiveCardHostConfig.d.ts +126 -0
  69. package/lib/adaptiveCards/Styles/adaptiveCardHostConfig.d.ts.map +1 -0
  70. package/lib/adaptiveCards/Styles/adaptiveCardHostConfig.js +29 -9
  71. package/lib/adaptiveCards/Styles/createAdaptiveCardsStyleSet.d.ts +5 -0
  72. package/lib/adaptiveCards/Styles/createAdaptiveCardsStyleSet.d.ts.map +1 -0
  73. package/lib/adaptiveCards/Styles/createAdaptiveCardsStyleSet.js +2 -2
  74. package/lib/adaptiveCards/createAdaptiveCardsAttachmentForScreenReaderMiddleware.d.ts +3 -0
  75. package/lib/adaptiveCards/createAdaptiveCardsAttachmentForScreenReaderMiddleware.d.ts.map +1 -0
  76. package/lib/adaptiveCards/createAdaptiveCardsAttachmentForScreenReaderMiddleware.js +5 -11
  77. package/lib/adaptiveCards/createAdaptiveCardsAttachmentMiddleware.d.ts +3 -0
  78. package/lib/adaptiveCards/createAdaptiveCardsAttachmentMiddleware.d.ts.map +1 -0
  79. package/lib/adaptiveCards/createAdaptiveCardsAttachmentMiddleware.js +2 -15
  80. package/lib/adaptiveCards/defaultStyleOptions.d.ts +4 -0
  81. package/lib/adaptiveCards/defaultStyleOptions.d.ts.map +1 -0
  82. package/lib/adaptiveCards/defaultStyleOptions.js +3 -2
  83. package/lib/adaptiveCards/hooks/internal/useAdaptiveCardsContext.d.ts +3 -0
  84. package/lib/adaptiveCards/hooks/internal/useAdaptiveCardsContext.d.ts.map +1 -0
  85. package/lib/adaptiveCards/hooks/internal/useAdaptiveCardsContext.js +1 -1
  86. package/lib/adaptiveCards/hooks/internal/useParseAdaptiveCardJSON.d.ts +2 -0
  87. package/lib/adaptiveCards/hooks/internal/useParseAdaptiveCardJSON.d.ts.map +1 -0
  88. package/lib/adaptiveCards/hooks/internal/useParseAdaptiveCardJSON.js +7 -5
  89. package/lib/adaptiveCards/hooks/internal/useUniqueId.js +1 -1
  90. package/lib/adaptiveCards/hooks/useAdaptiveCardsHostConfig.d.ts +2 -0
  91. package/lib/adaptiveCards/hooks/useAdaptiveCardsHostConfig.d.ts.map +1 -0
  92. package/lib/adaptiveCards/hooks/useAdaptiveCardsHostConfig.js +3 -5
  93. package/lib/adaptiveCards/hooks/useAdaptiveCardsPackage.d.ts +3 -0
  94. package/lib/adaptiveCards/hooks/useAdaptiveCardsPackage.d.ts.map +1 -0
  95. package/lib/adaptiveCards/hooks/useAdaptiveCardsPackage.js +1 -1
  96. package/lib/adaptiveCards/normalizeStyleOptions.d.ts +3 -0
  97. package/lib/adaptiveCards/normalizeStyleOptions.d.ts.map +1 -0
  98. package/lib/adaptiveCards/normalizeStyleOptions.js +1 -1
  99. package/lib/addVersion.js +2 -2
  100. package/lib/createBrowserWebSpeechPonyfillFactory.d.ts +3 -0
  101. package/lib/createBrowserWebSpeechPonyfillFactory.d.ts.map +1 -0
  102. package/lib/createBrowserWebSpeechPonyfillFactory.js +7 -4
  103. package/lib/createCognitiveServicesSpeechServicesPonyfillFactory.d.ts +17 -0
  104. package/lib/createCognitiveServicesSpeechServicesPonyfillFactory.d.ts.map +1 -0
  105. package/lib/createCognitiveServicesSpeechServicesPonyfillFactory.js +17 -11
  106. package/lib/createDirectLine.d.ts +17 -0
  107. package/lib/createDirectLine.d.ts.map +1 -0
  108. package/lib/createDirectLine.js +3 -2
  109. package/lib/createDirectLineAppServiceExtension.d.ts +7 -0
  110. package/lib/createDirectLineAppServiceExtension.d.ts.map +1 -0
  111. package/lib/createDirectLineAppServiceExtension.js +1 -1
  112. package/lib/createDirectLineSpeechAdapters.d.ts +25 -0
  113. package/lib/createDirectLineSpeechAdapters.d.ts.map +1 -0
  114. package/lib/createDirectLineSpeechAdapters.js +57 -3
  115. package/lib/createFullStyleSet.d.ts +1375 -0
  116. package/lib/createFullStyleSet.d.ts.map +1 -0
  117. package/lib/createFullStyleSet.js +2 -2
  118. package/lib/fullBundleDefaultStyleOptions.js +4 -4
  119. package/lib/hooks/useStyleOptions.d.ts +3 -0
  120. package/lib/hooks/useStyleOptions.d.ts.map +1 -0
  121. package/lib/hooks/useStyleOptions.js +21 -0
  122. package/lib/index-es5.d.ts +4 -20
  123. package/lib/index-es5.d.ts.map +1 -1
  124. package/lib/index-es5.js +3 -43
  125. package/lib/index-minimal.d.ts +9 -6
  126. package/lib/index-minimal.d.ts.map +1 -1
  127. package/lib/index-minimal.js +27 -21
  128. package/lib/index.d.ts +164 -18
  129. package/lib/index.d.ts.map +1 -1
  130. package/lib/index.js +19 -12
  131. package/lib/polyfill.d.ts +23 -0
  132. package/lib/polyfill.d.ts.map +1 -0
  133. package/lib/polyfill.js +46 -0
  134. package/lib/renderMarkdown.d.ts +6 -0
  135. package/lib/renderMarkdown.d.ts.map +1 -0
  136. package/lib/renderMarkdown.js +36 -5
  137. package/lib/renderWebChat.d.ts +3 -0
  138. package/lib/renderWebChat.d.ts.map +1 -0
  139. package/lib/renderWebChat.js +1 -1
  140. package/lib/speech/CustomAudioInputStream.d.ts +94 -0
  141. package/lib/speech/CustomAudioInputStream.d.ts.map +1 -0
  142. package/lib/speech/CustomAudioInputStream.js +441 -0
  143. package/lib/speech/bytesPerSample.d.ts +2 -0
  144. package/lib/speech/bytesPerSample.d.ts.map +1 -0
  145. package/lib/speech/bytesPerSample.js +12 -0
  146. package/lib/speech/createAudioConfig.d.ts +23 -0
  147. package/lib/speech/createAudioConfig.d.ts.map +1 -0
  148. package/lib/speech/createAudioConfig.js +90 -0
  149. package/lib/speech/createAudioContext.d.ts +3 -0
  150. package/lib/speech/createAudioContext.d.ts.map +1 -0
  151. package/lib/speech/createAudioContext.js +22 -0
  152. package/lib/speech/createMicrophoneAudioConfigAndAudioContext.d.ts +9 -0
  153. package/lib/speech/createMicrophoneAudioConfigAndAudioContext.d.ts.map +1 -0
  154. package/lib/speech/createMicrophoneAudioConfigAndAudioContext.js +161 -0
  155. package/lib/speech/getUserMedia.d.ts +2 -0
  156. package/lib/speech/getUserMedia.d.ts.map +1 -0
  157. package/lib/speech/getUserMedia.js +25 -0
  158. package/lib/types/AdaptiveCardsPackage.d.ts +13 -0
  159. package/lib/types/AdaptiveCardsPackage.d.ts.map +1 -0
  160. package/lib/types/AdaptiveCardsPackage.js +2 -0
  161. package/lib/types/CognitiveServicesAudioOutputFormat.d.ts +3 -0
  162. package/lib/types/CognitiveServicesAudioOutputFormat.d.ts.map +1 -0
  163. package/lib/types/CognitiveServicesAudioOutputFormat.js +2 -0
  164. package/lib/types/CognitiveServicesCredentials.d.ts +18 -0
  165. package/lib/types/CognitiveServicesCredentials.d.ts.map +1 -0
  166. package/lib/types/CognitiveServicesCredentials.js +2 -0
  167. package/lib/types/CognitiveServicesTextNormalization.d.ts +3 -0
  168. package/lib/types/CognitiveServicesTextNormalization.d.ts.map +1 -0
  169. package/lib/types/CognitiveServicesTextNormalization.js +2 -0
  170. package/lib/{FullBundleStyleOptions.d.ts → types/FullBundleStyleOptions.d.ts} +1 -1
  171. package/lib/types/FullBundleStyleOptions.d.ts.map +1 -0
  172. package/lib/types/FullBundleStyleOptions.js +2 -0
  173. package/lib/useComposerProps.d.ts +22 -0
  174. package/lib/useComposerProps.d.ts.map +1 -0
  175. package/lib/useComposerProps.js +6 -8
  176. package/package.json +46 -48
  177. package/src/AddFullBundle.tsx +93 -0
  178. package/src/FullComposer.tsx +38 -0
  179. package/src/FullReactWebChat.tsx +32 -0
  180. package/src/__tests__/createDirectLine.spec.js +2 -0
  181. package/src/__tests__/renderMarkdown.spec.js +1 -1
  182. package/src/__tests__/versionTag.es5.spec.js +3 -0
  183. package/src/__tests__/versionTag.full.spec.js +3 -0
  184. package/src/__tests__/versionTag.minimal.spec.js +3 -0
  185. package/src/adaptiveCards/{AdaptiveCardsComposer.js → AdaptiveCardsComposer.tsx} +17 -5
  186. package/src/adaptiveCards/AdaptiveCardsContext.ts +12 -0
  187. package/src/adaptiveCards/AdaptiveCardsStyleOptions.ts +5 -3
  188. package/src/adaptiveCards/AdaptiveCardsStyleSet.ts +7 -0
  189. package/src/adaptiveCards/Attachment/{AdaptiveCardAttachment.js → AdaptiveCardAttachment.tsx} +8 -2
  190. package/src/adaptiveCards/Attachment/AdaptiveCardBuilder.ts +27 -17
  191. package/src/adaptiveCards/Attachment/{AdaptiveCardContent.js → AdaptiveCardContent.tsx} +8 -2
  192. package/src/adaptiveCards/Attachment/AdaptiveCardRenderer.tsx +768 -0
  193. package/src/adaptiveCards/Attachment/{AnimationCardContent.js → AnimationCardContent.tsx} +9 -2
  194. package/src/adaptiveCards/Attachment/{AudioCardContent.js → AudioCardContent.tsx} +9 -2
  195. package/src/adaptiveCards/Attachment/CommonCard.js +2 -1
  196. package/src/adaptiveCards/Attachment/{HeroCardContent.js → HeroCardContent.tsx} +12 -3
  197. package/src/adaptiveCards/Attachment/{OAuthCardContent.js → OAuthCardContent.tsx} +11 -3
  198. package/src/adaptiveCards/Attachment/{ReceiptCardContent.js → ReceiptCardContent.tsx} +58 -28
  199. package/src/adaptiveCards/Attachment/{SignInCardContent.js → SignInCardContent.tsx} +9 -2
  200. package/src/adaptiveCards/Attachment/{ThumbnailCardContent.js → ThumbnailCardContent.tsx} +12 -3
  201. package/src/adaptiveCards/Attachment/{VideoCardContent.js → VideoCardContent.tsx} +15 -3
  202. package/src/adaptiveCards/Styles/StyleSet/AdaptiveCardRenderer.ts +9 -1
  203. package/src/adaptiveCards/Styles/adaptiveCardHostConfig.ts +28 -8
  204. package/src/adaptiveCards/Styles/createAdaptiveCardsStyleSet.spec.js +2 -0
  205. package/src/adaptiveCards/Styles/createAdaptiveCardsStyleSet.ts +7 -4
  206. package/src/adaptiveCards/{createAdaptiveCardsAttachmentForScreenReaderMiddleware.js → createAdaptiveCardsAttachmentForScreenReaderMiddleware.tsx} +16 -15
  207. package/src/adaptiveCards/createAdaptiveCardsAttachmentMiddleware.tsx +44 -0
  208. package/src/adaptiveCards/defaultStyleOptions.ts +2 -1
  209. package/src/adaptiveCards/hooks/internal/{useAdaptiveCardsContext.js → useAdaptiveCardsContext.ts} +1 -1
  210. package/src/adaptiveCards/hooks/internal/{useParseAdaptiveCardJSON.js → useParseAdaptiveCardJSON.ts} +5 -2
  211. package/src/adaptiveCards/hooks/internal/{useUniqueId.js → useUniqueId.ts} +1 -1
  212. package/src/adaptiveCards/hooks/{useAdaptiveCardsHostConfig.js → useAdaptiveCardsHostConfig.ts} +6 -8
  213. package/src/adaptiveCards/hooks/{useAdaptiveCardsPackage.js → useAdaptiveCardsPackage.ts} +2 -1
  214. package/src/createBrowserWebSpeechPonyfillFactory.ts +21 -0
  215. package/src/createCognitiveServicesSpeechServicesPonyfillFactory.spec.js +36 -6
  216. package/src/createCognitiveServicesSpeechServicesPonyfillFactory.ts +78 -0
  217. package/src/createDirectLine.ts +65 -0
  218. package/src/createDirectLineAppServiceExtension.ts +22 -0
  219. package/src/createDirectLineSpeechAdapters.ts +84 -0
  220. package/src/createFullStyleSet.ts +2 -2
  221. package/src/fullBundleDefaultStyleOptions.ts +3 -3
  222. package/src/hooks/useStyleOptions.ts +9 -0
  223. package/src/index-es5.ts +3 -28
  224. package/src/index-minimal.ts +3 -2
  225. package/src/index.ts +22 -10
  226. package/src/polyfill.ts +29 -0
  227. package/src/renderMarkdown.ts +140 -0
  228. package/src/renderWebChat.tsx +6 -0
  229. package/src/speech/CustomAudioInputStream.ts +356 -0
  230. package/src/speech/bytesPerSample.ts +4 -0
  231. package/src/speech/createAudioConfig.spec.js +23 -0
  232. package/src/speech/createAudioConfig.ts +77 -0
  233. package/src/speech/createAudioContext.ts +16 -0
  234. package/src/speech/createMicrophoneAudioConfigAndAudioContext.ts +146 -0
  235. package/src/speech/getUserMedia.ts +14 -0
  236. package/src/tsconfig.json +1 -1
  237. package/src/types/AdaptiveCardsPackage.ts +23 -0
  238. package/src/types/CognitiveServicesAudioOutputFormat.ts +28 -0
  239. package/src/types/CognitiveServicesCredentials.ts +28 -0
  240. package/src/types/CognitiveServicesTextNormalization.ts +3 -0
  241. package/src/{FullBundleStyleOptions.ts → types/FullBundleStyleOptions.ts} +1 -1
  242. package/src/{useComposerProps.js → useComposerProps.ts} +21 -11
  243. package/webpack.config.js +46 -6
  244. package/.eslintignore +0 -9
  245. package/lib/FullBundleStyleOptions.d.ts.map +0 -1
  246. package/src/FullComposer.js +0 -40
  247. package/src/FullReactWebChat.js +0 -47
  248. package/src/adaptiveCards/AdaptiveCardsContext.js +0 -5
  249. package/src/adaptiveCards/Attachment/AdaptiveCardRenderer.js +0 -492
  250. package/src/adaptiveCards/createAdaptiveCardsAttachmentMiddleware.js +0 -41
  251. package/src/createBrowserWebSpeechPonyfillFactory.js +0 -16
  252. package/src/createCognitiveServicesSpeechServicesPonyfillFactory.js +0 -58
  253. package/src/createDirectLine.js +0 -38
  254. package/src/createDirectLineAppServiceExtension.js +0 -12
  255. package/src/createDirectLineSpeechAdapters.js +0 -5
  256. package/src/index-es5.tsx +0 -49
  257. package/src/index-minimal.tsx +0 -9
  258. package/src/index.tsx +0 -45
  259. package/src/renderMarkdown.js +0 -97
  260. package/src/renderWebChat.js +0 -6
@@ -0,0 +1,21 @@
1
+ import { WebSpeechPonyfill } from 'botframework-webchat-api';
2
+
3
+ export default function createBrowserWebSpeechPonyfillFactory(): () => WebSpeechPonyfill {
4
+ // eslint-disable-next-line dot-notation
5
+ if (!window.SpeechRecognition && !window['webkitSpeechRecognition']) {
6
+ console.warn('Web Chat: This browser does not support Web Speech API Speech Recognition.');
7
+ }
8
+
9
+ if (!window.speechSynthesis) {
10
+ console.warn('Web Chat: This browser does not support Web Speech API Speech Synthesis.');
11
+ }
12
+
13
+ return () => ({
14
+ // eslint-disable-next-line dot-notation
15
+ SpeechGrammarList: window.SpeechGrammarList || window['webkitSpeechGrammarList'],
16
+ // eslint-disable-next-line dot-notation
17
+ SpeechRecognition: window.SpeechRecognition || window['webkitSpeechRecognition'],
18
+ speechSynthesis: window.speechSynthesis,
19
+ SpeechSynthesisUtterance: window.SpeechSynthesisUtterance
20
+ });
21
+ }
@@ -1,3 +1,4 @@
1
+ /** @jest-environment jsdom */
1
2
  /* eslint-disable prefer-destructuring */
2
3
  /* eslint-disable no-global-assign */
3
4
  let consoleWarns;
@@ -17,11 +18,28 @@ beforeEach(() => {
17
18
  };
18
19
 
19
20
  createPonyfill = require('web-speech-cognitive-services/lib/SpeechServices');
20
- // eslint-disable-next-line @typescript-eslint/no-var-requires
21
- createCognitiveServicesSpeechServicesPonyfillFactory = require('./createCognitiveServicesSpeechServicesPonyfillFactory')
22
- .default;
21
+ createCognitiveServicesSpeechServicesPonyfillFactory =
22
+ require('./createCognitiveServicesSpeechServicesPonyfillFactory').default;
23
+
24
+ window.AudioContext = class MockAudioContext {
25
+ // eslint-disable-next-line class-methods-use-this
26
+ createMediaStreamSource() {
27
+ // eslint-disable-next-line no-empty-function
28
+ return { connect: () => {} };
29
+ }
30
+
31
+ // eslint-disable-next-line class-methods-use-this
32
+ createScriptProcessor() {
33
+ // eslint-disable-next-line no-empty-function
34
+ return { connect: () => {} };
35
+ }
36
+ };
23
37
 
24
- window.navigator.mediaDevices = {};
38
+ window.navigator.mediaDevices = {
39
+ getUserMedia: jest.fn(() => ({
40
+ getAudioTracks: () => ['mock-media-stream-track']
41
+ }))
42
+ };
25
43
  });
26
44
 
27
45
  afterEach(() => {
@@ -60,7 +78,8 @@ test('not providing reference grammar ID', () => {
60
78
  expect(referenceGrammars).toEqual([]);
61
79
  });
62
80
 
63
- test('supplying audioInputDeviceId', () => {
81
+ test('supplying audioInputDeviceId', async () => {
82
+ // GIVEN: Set up Web Speech with "audioInputDeviceId" of "audio-input-device-1".
64
83
  const ponyfillFactory = createCognitiveServicesSpeechServicesPonyfillFactory({
65
84
  audioInputDeviceId: 'audio-input-device-1',
66
85
  credentials: {
@@ -69,9 +88,20 @@ test('supplying audioInputDeviceId', () => {
69
88
  }
70
89
  });
71
90
 
91
+ // WHEN: Polyfill is created.
72
92
  ponyfillFactory({});
73
93
 
74
- expect(createPonyfill.mock.calls[0][0]).toHaveProperty('audioConfig.privSource.deviceId', 'audio-input-device-1');
94
+ // WHEN: Audio source is attached and audio device is opened.
95
+ await createPonyfill.mock.calls[0][0].audioConfig.privSource.attach();
96
+
97
+ // THEN: It should call getUserMedia() with "audio" constraints of { deviceId: 'audio-input-device-1' }.
98
+ expect(window.navigator.mediaDevices.getUserMedia.mock.calls[0][0]).toHaveProperty(
99
+ 'audio.deviceId',
100
+ 'audio-input-device-1'
101
+ );
102
+
103
+ // THEN: It should call getUserMedia() with "video" constraint of false.
104
+ expect(window.navigator.mediaDevices.getUserMedia.mock.calls[0][0]).toHaveProperty('video', false);
75
105
  });
76
106
 
77
107
  test('supplying both audioConfig and audioInputDeviceId', () => {
@@ -0,0 +1,78 @@
1
+ import { AudioConfig } from 'microsoft-cognitiveservices-speech-sdk';
2
+ import { WebSpeechPonyfillFactory } from 'botframework-webchat-api';
3
+ import createPonyfill from 'web-speech-cognitive-services/lib/SpeechServices';
4
+
5
+ import CognitiveServicesAudioOutputFormat from './types/CognitiveServicesAudioOutputFormat';
6
+ import CognitiveServicesCredentials from './types/CognitiveServicesCredentials';
7
+ import CognitiveServicesTextNormalization from './types/CognitiveServicesTextNormalization';
8
+ import createMicrophoneAudioConfigAndAudioContext from './speech/createMicrophoneAudioConfigAndAudioContext';
9
+
10
+ export default function createCognitiveServicesSpeechServicesPonyfillFactory({
11
+ audioConfig,
12
+ audioContext,
13
+ audioInputDeviceId,
14
+ credentials,
15
+ enableTelemetry,
16
+ speechRecognitionEndpointId,
17
+ speechSynthesisDeploymentId,
18
+ speechSynthesisOutputFormat,
19
+ textNormalization
20
+ }: {
21
+ audioConfig?: AudioConfig;
22
+ audioContext?: AudioContext;
23
+ audioInputDeviceId?: string;
24
+ credentials: CognitiveServicesCredentials;
25
+ enableTelemetry?: true;
26
+ speechRecognitionEndpointId?: string;
27
+ speechSynthesisDeploymentId?: string;
28
+ speechSynthesisOutputFormat?: CognitiveServicesAudioOutputFormat;
29
+ textNormalization?: CognitiveServicesTextNormalization;
30
+ }): WebSpeechPonyfillFactory {
31
+ if (!window.navigator.mediaDevices && !audioConfig) {
32
+ console.warn(
33
+ 'botframework-webchat: Your browser does not support Web Audio or the page is not loaded via HTTPS or localhost. Cognitive Services Speech Services is disabled. However, you may pass a custom AudioConfig to enable speech in this environment.'
34
+ );
35
+
36
+ return () => ({});
37
+ }
38
+
39
+ if (audioConfig) {
40
+ audioInputDeviceId &&
41
+ console.warn(
42
+ 'botframework-webchat: "audioConfig" and "audioInputDeviceId" cannot be set at the same time; ignoring "audioInputDeviceId".'
43
+ );
44
+
45
+ audioContext &&
46
+ console.warn(
47
+ 'botframework-webchat: "audioConfig" and "audioContext" cannot be set at the same time; ignoring "audioContext" for speech recognition.'
48
+ );
49
+ } else {
50
+ ({ audioConfig, audioContext } = createMicrophoneAudioConfigAndAudioContext({
51
+ audioContext,
52
+ audioInputDeviceId,
53
+ enableTelemetry
54
+ }));
55
+ }
56
+
57
+ return ({ referenceGrammarID } = {}) => {
58
+ const { SpeechGrammarList, SpeechRecognition, speechSynthesis, SpeechSynthesisUtterance } = createPonyfill({
59
+ audioConfig,
60
+ audioContext,
61
+ credentials,
62
+ enableTelemetry,
63
+ referenceGrammars: referenceGrammarID ? [`luis/${referenceGrammarID}-PRODUCTION`] : [],
64
+ speechRecognitionEndpointId,
65
+ speechSynthesisDeploymentId,
66
+ speechSynthesisOutputFormat,
67
+ textNormalization
68
+ });
69
+
70
+ return {
71
+ resumeAudioContext: () => audioContext && audioContext.state === 'suspended' && audioContext.resume(),
72
+ SpeechGrammarList,
73
+ SpeechRecognition,
74
+ speechSynthesis,
75
+ SpeechSynthesisUtterance
76
+ };
77
+ };
78
+ }
@@ -0,0 +1,65 @@
1
+ import { DirectLine } from 'botframework-directlinejs';
2
+
3
+ type CreateDirectLineOptions = {
4
+ botAgent?: string;
5
+ conversationId?: string;
6
+ conversationStartProperties?: any;
7
+ domain?: string;
8
+ fetch?: typeof window.fetch;
9
+ pollingInterval?: number;
10
+ secret?: string;
11
+ streamUrl?: string;
12
+ token?: string;
13
+ watermark?: string;
14
+ webSocket?: typeof WebSocket;
15
+ };
16
+
17
+ export default function createDirectLine({
18
+ botAgent,
19
+ conversationId,
20
+ conversationStartProperties,
21
+ domain,
22
+ fetch,
23
+ pollingInterval,
24
+ secret,
25
+ streamUrl,
26
+ token,
27
+ watermark,
28
+ webSocket
29
+ }: CreateDirectLineOptions) {
30
+ // TODO: [P3] Checks if DLJS supports ponyfilling fetch.
31
+ return new DirectLine({
32
+ botAgent,
33
+ conversationId,
34
+ conversationStartProperties,
35
+ domain,
36
+ fetch,
37
+ pollingInterval,
38
+ secret,
39
+ streamUrl,
40
+ token,
41
+ watermark,
42
+ webSocket,
43
+ createFormData: attachments => {
44
+ const formData = new FormData();
45
+
46
+ attachments.forEach(
47
+ ({
48
+ contentType,
49
+ data,
50
+ filename,
51
+ name
52
+ }: {
53
+ contentType?: string;
54
+ data: BlobPart[];
55
+ filename?: string;
56
+ name?: string;
57
+ }) => {
58
+ formData.append(name, new Blob(data, { type: contentType }), filename);
59
+ }
60
+ );
61
+
62
+ return formData;
63
+ }
64
+ } as any);
65
+ }
@@ -0,0 +1,22 @@
1
+ import { DirectLineStreaming } from 'botframework-directlinejs';
2
+
3
+ export default function createDirectLineAppServiceExtension({
4
+ botAgent,
5
+ conversationId,
6
+ domain,
7
+ token
8
+ }: {
9
+ botAgent?: string;
10
+ conversationId?: string;
11
+ domain?: string;
12
+ token: string;
13
+ }): Promise<any> {
14
+ return Promise.resolve(
15
+ new DirectLineStreaming({
16
+ botAgent,
17
+ conversationId,
18
+ domain,
19
+ token
20
+ })
21
+ );
22
+ }
@@ -0,0 +1,84 @@
1
+ import { AudioConfig } from 'microsoft-cognitiveservices-speech-sdk';
2
+ import { createAdapters } from 'botframework-directlinespeech-sdk';
3
+ import { DirectLineJSBotConnection } from 'botframework-webchat-core';
4
+ import { WebSpeechPonyfill } from 'botframework-webchat-api';
5
+
6
+ import CognitiveServicesAudioOutputFormat from './types/CognitiveServicesAudioOutputFormat';
7
+ import CognitiveServicesCredentials from './types/CognitiveServicesCredentials';
8
+ import CognitiveServicesTextNormalization from './types/CognitiveServicesTextNormalization';
9
+ import createMicrophoneAudioConfigAndAudioContext from './speech/createMicrophoneAudioConfigAndAudioContext';
10
+
11
+ const DEFAULT_LANGUAGE = 'en-US';
12
+
13
+ // TODO: When using DLSpeech via bundle, we will add our own MicrophoneAudioConfig.
14
+ export default function createDirectLineSpeechAdapters({
15
+ audioConfig,
16
+ audioContext,
17
+ audioInputDeviceId,
18
+ enableInternalHTTPSupport,
19
+ enableTelemetry,
20
+ fetchCredentials,
21
+ speechRecognitionEndpointId,
22
+ speechRecognitionLanguage = window?.navigator?.language || DEFAULT_LANGUAGE,
23
+ speechSynthesisDeploymentId,
24
+ speechSynthesisOutputFormat,
25
+ textNormalization,
26
+ userID,
27
+ username
28
+ }: {
29
+ audioConfig?: AudioConfig;
30
+ audioContext?: AudioContext;
31
+ audioInputDeviceId?: string;
32
+ enableInternalHTTPSupport?: true;
33
+ enableTelemetry?: true;
34
+ fetchCredentials: CognitiveServicesCredentials;
35
+ speechRecognitionEndpointId?: string;
36
+ speechRecognitionLanguage?: string;
37
+ speechSynthesisDeploymentId?: string;
38
+ speechSynthesisOutputFormat?: CognitiveServicesAudioOutputFormat;
39
+ textNormalization?: CognitiveServicesTextNormalization;
40
+ userID?: string;
41
+ username?: string;
42
+ }): {
43
+ directLine: DirectLineJSBotConnection;
44
+ webSpeechPonyfill: WebSpeechPonyfill;
45
+ } {
46
+ if (audioConfig) {
47
+ audioInputDeviceId &&
48
+ console.warn(
49
+ 'botframework-webchat: "audioConfig" and "audioInputDeviceId" cannot be set at the same time; ignoring "audioInputDeviceId".'
50
+ );
51
+
52
+ audioContext &&
53
+ console.warn(
54
+ 'botframework-webchat: "audioConfig" and "audioContext" cannot be set at the same time; ignoring "audioContext" for speech recognition.'
55
+ );
56
+ } else if (!window.navigator.mediaDevices) {
57
+ // If the browser does not support or allow microphone access, we will continue to create Direct Line Speech adapter without custom "audioConfig" and "audioContext".
58
+ // In Direct Line Speech SDK, it will disable speech functionality, only leaving text chat available via the protocol.
59
+ console.warn(
60
+ 'botframework-webchat: Your browser does not support or allow microphone access or the page is not loaded via HTTPS or localhost. Speech is disabled for Direct Line Speech. However, you may pass a custom "audioConfig" to enable speech in this environment.'
61
+ );
62
+ } else {
63
+ ({ audioConfig, audioContext } = createMicrophoneAudioConfigAndAudioContext({
64
+ audioContext,
65
+ audioInputDeviceId,
66
+ enableTelemetry
67
+ }));
68
+ }
69
+
70
+ return createAdapters({
71
+ audioConfig,
72
+ audioContext,
73
+ enableInternalHTTPSupport,
74
+ enableTelemetry,
75
+ fetchCredentials,
76
+ speechRecognitionEndpointId,
77
+ speechRecognitionLanguage,
78
+ speechSynthesisDeploymentId,
79
+ speechSynthesisOutputFormat,
80
+ textNormalization,
81
+ userID,
82
+ username
83
+ });
84
+ }
@@ -1,13 +1,13 @@
1
1
  import { createStyleSet } from 'botframework-webchat-component';
2
- import { StyleOptions } from 'botframework-webchat-api';
3
2
 
4
3
  import createAdaptiveCardsStyleSet from './adaptiveCards/Styles/createAdaptiveCardsStyleSet';
4
+ import FullBundleStyleOptions from './types/FullBundleStyleOptions';
5
5
 
6
6
  // TODO: [P4] We should add a notice for people who want to use "styleSet" instead of "styleOptions".
7
7
  // "styleSet" is actually CSS stylesheet and it is based on the DOM tree.
8
8
  // DOM tree may change from time to time, thus, maintaining "styleSet" becomes a constant effort.
9
9
 
10
- export default function createFullStyleSet(options: StyleOptions) {
10
+ export default function createFullStyleSet(options: FullBundleStyleOptions) {
11
11
  return {
12
12
  ...createStyleSet(options),
13
13
  ...createAdaptiveCardsStyleSet(options)
@@ -1,11 +1,11 @@
1
1
  import { defaultStyleOptions } from 'botframework-webchat-api';
2
2
  import adaptiveCardsDefaultStyleOptions from './adaptiveCards/defaultStyleOptions';
3
3
 
4
- import FullBundleStyleOptions from './FullBundleStyleOptions';
4
+ import FullBundleStyleOptions from './types/FullBundleStyleOptions';
5
5
 
6
- const FULL_BUNDLE_DEFAULT_STYLE_OPTIONS: Required<FullBundleStyleOptions> = {
6
+ const fullBundleDefaultStyleOptions: Required<FullBundleStyleOptions> = {
7
7
  ...defaultStyleOptions,
8
8
  ...adaptiveCardsDefaultStyleOptions
9
9
  };
10
10
 
11
- export default FULL_BUNDLE_DEFAULT_STYLE_OPTIONS;
11
+ export default fullBundleDefaultStyleOptions;
@@ -0,0 +1,9 @@
1
+ import { hooks } from 'botframework-webchat-component';
2
+
3
+ import { StrictFullBundleStyleOptions } from '../types/FullBundleStyleOptions';
4
+
5
+ export default function useStyleOptions(): [StrictFullBundleStyleOptions] {
6
+ const [styleOptions] = hooks.useStyleOptions();
7
+
8
+ return [styleOptions as StrictFullBundleStyleOptions];
9
+ }
package/src/index-es5.ts CHANGED
@@ -1,34 +1,9 @@
1
- // IMPORTANT: To export anything from this file, add it to index-es5.tsx, which is the .d.ts for this file.
2
-
3
1
  /* eslint dot-notation: ["error", { "allowPattern": "^WebChat$" }] */
4
2
  // window['WebChat'] is required for TypeScript
5
3
 
6
- // Polyfills for IE11 and other ES5 browsers
7
- // To maintain quality, we prefer polyfills without additives
8
- // For example, we prefer Promise implementation from "core-js" than "bluebird"
9
-
10
- import 'core-js/features/array/find-index';
11
- import 'core-js/features/array/find';
12
- import 'core-js/features/array/from';
13
- import 'core-js/features/array/includes';
14
- import 'core-js/features/array/iterator';
15
- import 'core-js/features/dom-collections';
16
- import 'core-js/features/math/sign';
17
- import 'core-js/features/number/is-finite';
18
- import 'core-js/features/object/assign';
19
- import 'core-js/features/object/entries';
20
- import 'core-js/features/object/from-entries';
21
- import 'core-js/features/object/is';
22
- import 'core-js/features/object/values';
23
- import 'core-js/features/promise';
24
- import 'core-js/features/promise/finally';
25
- import 'core-js/features/set';
26
- import 'core-js/features/string/ends-with';
27
- import 'core-js/features/string/starts-with';
28
- import 'core-js/features/symbol';
29
-
30
- import 'url-search-params-polyfill';
31
- import 'whatwg-fetch';
4
+ // Importing polyfills required for IE11/ES5.
5
+ import './polyfill';
6
+
32
7
  import { version } from './index-minimal';
33
8
  import addVersion from './addVersion';
34
9
  import defaultCreateDirectLine from './createDirectLine';
@@ -1,9 +1,8 @@
1
- // IMPORTANT: To export anything from this file, add it to index-minimal.tsx, which is the .d.ts for this file.
2
-
3
1
  /* eslint dot-notation: ["error", { "allowPattern": "^WebChat$" }] */
4
2
  // window['WebChat'] is required for TypeScript
5
3
 
6
4
  import { Constants, createStore, createStoreWithDevTools, version } from 'botframework-webchat-core';
5
+ import { StrictStyleOptions, StyleOptions } from 'botframework-webchat-api';
7
6
 
8
7
  import ReactWebChat, {
9
8
  Components,
@@ -55,6 +54,8 @@ export {
55
54
  version
56
55
  };
57
56
 
57
+ export type { StyleOptions, StrictStyleOptions };
58
+
58
59
  // Until we have a development-specific bundle, we are not shipping createStoreWithDevTools in bundle.
59
60
  window['WebChat'] = {
60
61
  ...window['WebChat'],
package/src/index.ts CHANGED
@@ -1,5 +1,3 @@
1
- // IMPORTANT: To export anything from this file, add it to index.tsx, which is the .d.ts for this file.
2
-
3
1
  /* eslint dot-notation: ["error", { "allowPattern": "^WebChat$" }] */
4
2
  // window['WebChat'] is required for TypeScript
5
3
 
@@ -18,6 +16,7 @@ import createDirectLineSpeechAdapters from './createDirectLineSpeechAdapters';
18
16
  import createStyleSet from './createFullStyleSet';
19
17
  import defaultCreateDirectLine from './createDirectLine';
20
18
  import defaultCreateDirectLineAppServiceExtension from './createDirectLineAppServiceExtension';
19
+ import FullBundleStyleOptions, { StrictFullBundleStyleOptions } from './types/FullBundleStyleOptions';
21
20
  import FullComposer from './FullComposer';
22
21
  import HeroCardContent from './adaptiveCards/Attachment/HeroCardContent';
23
22
  import OAuthCardContent from './adaptiveCards/Attachment/OAuthCardContent';
@@ -28,12 +27,13 @@ import SignInCardContent from './adaptiveCards/Attachment/SignInCardContent';
28
27
  import ThumbnailCardContent from './adaptiveCards/Attachment/ThumbnailCardContent';
29
28
  import useAdaptiveCardsHostConfig from './adaptiveCards/hooks/useAdaptiveCardsHostConfig';
30
29
  import useAdaptiveCardsPackage from './adaptiveCards/hooks/useAdaptiveCardsPackage';
30
+ import useStyleOptions from './hooks/useStyleOptions';
31
31
  import VideoCardContent from './adaptiveCards/Attachment/VideoCardContent';
32
32
 
33
33
  const renderWebChat = coreRenderWebChat.bind(null, ReactWebChat);
34
34
 
35
- export const createDirectLine = options => {
36
- options.botAgent &&
35
+ export const createDirectLine = (options: Omit<Parameters<typeof defaultCreateDirectLine>[0], 'botAgent'>) => {
36
+ (options as any).botAgent &&
37
37
  console.warn(
38
38
  'Web Chat: Developers are not currently allowed to set botAgent. See https://github.com/microsoft/BotFramework-WebChat/issues/2119 for more details.'
39
39
  );
@@ -41,8 +41,10 @@ export const createDirectLine = options => {
41
41
  return defaultCreateDirectLine({ ...options, botAgent: `WebChat/${version} (Full)` });
42
42
  };
43
43
 
44
- export const createDirectLineAppServiceExtension = options => {
45
- options.botAgent &&
44
+ export const createDirectLineAppServiceExtension = (
45
+ options: Omit<Parameters<typeof defaultCreateDirectLineAppServiceExtension>[0], 'botAgent'>
46
+ ) => {
47
+ (options as any).botAgent &&
46
48
  console.warn(
47
49
  'Web Chat: Developers are not currently allowed to set botAgent. See https://github.com/microsoft/BotFramework-WebChat/issues/2119 for more details.'
48
50
  );
@@ -53,14 +55,14 @@ export const createDirectLineAppServiceExtension = options => {
53
55
  const patchedHooks = {
54
56
  ...hooks,
55
57
  useAdaptiveCardsHostConfig,
56
- useAdaptiveCardsPackage
58
+ useAdaptiveCardsPackage,
59
+ useStyleOptions
57
60
  };
58
61
 
59
- const Components = {
60
- ...MinimalComponents,
62
+ const AdditionalComponents = {
61
63
  AdaptiveCardContent,
62
- AudioCardContent,
63
64
  AnimationCardContent,
65
+ AudioCardContent,
64
66
  Composer: FullComposer,
65
67
  HeroCardContent,
66
68
  OAuthCardContent,
@@ -70,6 +72,14 @@ const Components = {
70
72
  VideoCardContent
71
73
  };
72
74
 
75
+ const Components: typeof MinimalComponents & typeof AdditionalComponents = {
76
+ ...MinimalComponents,
77
+ ...AdditionalComponents
78
+ };
79
+
80
+ type StyleOptions = FullBundleStyleOptions;
81
+ type StrictStyleOptions = StrictFullBundleStyleOptions;
82
+
73
83
  export default ReactWebChat;
74
84
 
75
85
  export {
@@ -84,6 +94,8 @@ export {
84
94
  renderWebChat
85
95
  };
86
96
 
97
+ export type { StyleOptions, StrictStyleOptions };
98
+
87
99
  window['WebChat'] = {
88
100
  ...window['WebChat'],
89
101
  Components,
@@ -0,0 +1,29 @@
1
+ // Polyfills for IE11 and other ES5 browsers
2
+ // To maintain quality, we prefer polyfills without additives
3
+ // For example, we prefer Promise implementation from "core-js" than "bluebird"
4
+
5
+ // To reduce conflicts with hosting app, we should consider using
6
+ // @babel/plugin-transform-runtime to polyfill in transpiled code directly.
7
+
8
+ import 'core-js/features/array/find-index';
9
+ import 'core-js/features/array/find';
10
+ import 'core-js/features/array/from';
11
+ import 'core-js/features/array/includes';
12
+ import 'core-js/features/array/iterator';
13
+ import 'core-js/features/dom-collections';
14
+ import 'core-js/features/map';
15
+ import 'core-js/features/math/sign';
16
+ import 'core-js/features/number/is-finite';
17
+ import 'core-js/features/object/assign';
18
+ import 'core-js/features/object/entries';
19
+ import 'core-js/features/object/from-entries';
20
+ import 'core-js/features/object/is';
21
+ import 'core-js/features/object/values';
22
+ import 'core-js/features/promise';
23
+ import 'core-js/features/promise/finally';
24
+ import 'core-js/features/set';
25
+ import 'core-js/features/string/ends-with';
26
+ import 'core-js/features/string/starts-with';
27
+ import 'core-js/features/symbol';
28
+ import 'url-search-params-polyfill';
29
+ import 'whatwg-fetch';