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.
- package/.eslintrc.yml +5 -104
- package/.prettierrc.yml +1 -1
- package/README.md +33 -36
- package/babel.config.json +2 -2
- package/babel.sanitize-html.config.json +10 -0
- package/lib/AddFullBundle.d.ts +30 -0
- package/lib/AddFullBundle.d.ts.map +1 -0
- package/lib/AddFullBundle.js +76 -0
- package/lib/FullComposer.d.ts +8 -0
- package/lib/FullComposer.d.ts.map +1 -0
- package/lib/FullComposer.js +6 -16
- package/lib/FullReactWebChat.d.ts +8 -0
- package/lib/FullReactWebChat.d.ts.map +1 -0
- package/lib/FullReactWebChat.js +8 -23
- package/lib/adaptiveCards/AdaptiveCardsComposer.d.ts +10 -0
- package/lib/adaptiveCards/AdaptiveCardsComposer.d.ts.map +1 -0
- package/lib/adaptiveCards/AdaptiveCardsComposer.js +6 -2
- package/lib/adaptiveCards/AdaptiveCardsContext.d.ts +8 -0
- package/lib/adaptiveCards/AdaptiveCardsContext.d.ts.map +1 -0
- package/lib/adaptiveCards/AdaptiveCardsContext.js +3 -3
- package/lib/adaptiveCards/AdaptiveCardsStyleOptions.d.ts +5 -3
- package/lib/adaptiveCards/AdaptiveCardsStyleOptions.d.ts.map +1 -1
- package/lib/adaptiveCards/AdaptiveCardsStyleSet.d.ts +7 -0
- package/lib/adaptiveCards/AdaptiveCardsStyleSet.d.ts.map +1 -0
- package/lib/{FullBundleStyleOptions.js → adaptiveCards/AdaptiveCardsStyleSet.js} +0 -0
- package/lib/adaptiveCards/Attachment/AdaptiveCardAttachment.d.ts +9 -0
- package/lib/adaptiveCards/Attachment/AdaptiveCardAttachment.d.ts.map +1 -0
- package/lib/adaptiveCards/Attachment/AdaptiveCardAttachment.js +1 -1
- package/lib/adaptiveCards/Attachment/AdaptiveCardBuilder.d.ts +28 -0
- package/lib/adaptiveCards/Attachment/AdaptiveCardBuilder.d.ts.map +1 -0
- package/lib/adaptiveCards/Attachment/AdaptiveCardBuilder.js +13 -6
- package/lib/adaptiveCards/Attachment/AdaptiveCardContent.d.ts +9 -0
- package/lib/adaptiveCards/Attachment/AdaptiveCardContent.d.ts.map +1 -0
- package/lib/adaptiveCards/Attachment/AdaptiveCardContent.js +8 -4
- package/lib/adaptiveCards/Attachment/AdaptiveCardRenderer.d.ts +12 -0
- package/lib/adaptiveCards/Attachment/AdaptiveCardRenderer.d.ts.map +1 -0
- package/lib/adaptiveCards/Attachment/AdaptiveCardRenderer.js +310 -85
- package/lib/adaptiveCards/Attachment/AnimationCardContent.d.ts +10 -0
- package/lib/adaptiveCards/Attachment/AnimationCardContent.d.ts.map +1 -0
- package/lib/adaptiveCards/Attachment/AnimationCardContent.js +1 -1
- package/lib/adaptiveCards/Attachment/AudioCardContent.d.ts +10 -0
- package/lib/adaptiveCards/Attachment/AudioCardContent.d.ts.map +1 -0
- package/lib/adaptiveCards/Attachment/AudioCardContent.js +1 -1
- package/lib/adaptiveCards/Attachment/CommonCard.js +11 -6
- package/lib/adaptiveCards/Attachment/HeroCardContent.d.ts +10 -0
- package/lib/adaptiveCards/Attachment/HeroCardContent.d.ts.map +1 -0
- package/lib/adaptiveCards/Attachment/HeroCardContent.js +11 -6
- package/lib/adaptiveCards/Attachment/OAuthCardContent.d.ts +10 -0
- package/lib/adaptiveCards/Attachment/OAuthCardContent.d.ts.map +1 -0
- package/lib/adaptiveCards/Attachment/OAuthCardContent.js +11 -6
- package/lib/adaptiveCards/Attachment/ReceiptCardContent.d.ts +10 -0
- package/lib/adaptiveCards/Attachment/ReceiptCardContent.d.ts.map +1 -0
- package/lib/adaptiveCards/Attachment/ReceiptCardContent.js +11 -6
- package/lib/adaptiveCards/Attachment/SignInCardContent.d.ts +10 -0
- package/lib/adaptiveCards/Attachment/SignInCardContent.d.ts.map +1 -0
- package/lib/adaptiveCards/Attachment/SignInCardContent.js +1 -1
- package/lib/adaptiveCards/Attachment/ThumbnailCardContent.d.ts +10 -0
- package/lib/adaptiveCards/Attachment/ThumbnailCardContent.d.ts.map +1 -0
- package/lib/adaptiveCards/Attachment/ThumbnailCardContent.js +11 -6
- package/lib/adaptiveCards/Attachment/VideoCardContent.d.ts +20 -0
- package/lib/adaptiveCards/Attachment/VideoCardContent.d.ts.map +1 -0
- package/lib/adaptiveCards/Attachment/VideoCardContent.js +7 -5
- package/lib/adaptiveCards/AttachmentForScreenReader/AdaptiveCardAttachment.js +7 -3
- package/lib/adaptiveCards/AttachmentForScreenReader/RichCardAttachment.js +1 -1
- package/lib/adaptiveCards/Styles/StyleSet/AdaptiveCardRenderer.d.ts +59 -0
- package/lib/adaptiveCards/Styles/StyleSet/AdaptiveCardRenderer.d.ts.map +1 -0
- package/lib/adaptiveCards/Styles/StyleSet/AdaptiveCardRenderer.js +8 -1
- package/lib/adaptiveCards/Styles/adaptiveCardHostConfig.d.ts +126 -0
- package/lib/adaptiveCards/Styles/adaptiveCardHostConfig.d.ts.map +1 -0
- package/lib/adaptiveCards/Styles/adaptiveCardHostConfig.js +29 -9
- package/lib/adaptiveCards/Styles/createAdaptiveCardsStyleSet.d.ts +5 -0
- package/lib/adaptiveCards/Styles/createAdaptiveCardsStyleSet.d.ts.map +1 -0
- package/lib/adaptiveCards/Styles/createAdaptiveCardsStyleSet.js +2 -2
- package/lib/adaptiveCards/createAdaptiveCardsAttachmentForScreenReaderMiddleware.d.ts +3 -0
- package/lib/adaptiveCards/createAdaptiveCardsAttachmentForScreenReaderMiddleware.d.ts.map +1 -0
- package/lib/adaptiveCards/createAdaptiveCardsAttachmentForScreenReaderMiddleware.js +5 -11
- package/lib/adaptiveCards/createAdaptiveCardsAttachmentMiddleware.d.ts +3 -0
- package/lib/adaptiveCards/createAdaptiveCardsAttachmentMiddleware.d.ts.map +1 -0
- package/lib/adaptiveCards/createAdaptiveCardsAttachmentMiddleware.js +2 -15
- package/lib/adaptiveCards/defaultStyleOptions.d.ts +4 -0
- package/lib/adaptiveCards/defaultStyleOptions.d.ts.map +1 -0
- package/lib/adaptiveCards/defaultStyleOptions.js +3 -2
- package/lib/adaptiveCards/hooks/internal/useAdaptiveCardsContext.d.ts +3 -0
- package/lib/adaptiveCards/hooks/internal/useAdaptiveCardsContext.d.ts.map +1 -0
- package/lib/adaptiveCards/hooks/internal/useAdaptiveCardsContext.js +1 -1
- package/lib/adaptiveCards/hooks/internal/useParseAdaptiveCardJSON.d.ts +2 -0
- package/lib/adaptiveCards/hooks/internal/useParseAdaptiveCardJSON.d.ts.map +1 -0
- package/lib/adaptiveCards/hooks/internal/useParseAdaptiveCardJSON.js +7 -5
- package/lib/adaptiveCards/hooks/internal/useUniqueId.js +1 -1
- package/lib/adaptiveCards/hooks/useAdaptiveCardsHostConfig.d.ts +2 -0
- package/lib/adaptiveCards/hooks/useAdaptiveCardsHostConfig.d.ts.map +1 -0
- package/lib/adaptiveCards/hooks/useAdaptiveCardsHostConfig.js +3 -5
- package/lib/adaptiveCards/hooks/useAdaptiveCardsPackage.d.ts +3 -0
- package/lib/adaptiveCards/hooks/useAdaptiveCardsPackage.d.ts.map +1 -0
- package/lib/adaptiveCards/hooks/useAdaptiveCardsPackage.js +1 -1
- package/lib/adaptiveCards/normalizeStyleOptions.d.ts +3 -0
- package/lib/adaptiveCards/normalizeStyleOptions.d.ts.map +1 -0
- package/lib/adaptiveCards/normalizeStyleOptions.js +1 -1
- package/lib/addVersion.js +2 -2
- package/lib/createBrowserWebSpeechPonyfillFactory.d.ts +3 -0
- package/lib/createBrowserWebSpeechPonyfillFactory.d.ts.map +1 -0
- package/lib/createBrowserWebSpeechPonyfillFactory.js +7 -4
- package/lib/createCognitiveServicesSpeechServicesPonyfillFactory.d.ts +17 -0
- package/lib/createCognitiveServicesSpeechServicesPonyfillFactory.d.ts.map +1 -0
- package/lib/createCognitiveServicesSpeechServicesPonyfillFactory.js +17 -11
- package/lib/createDirectLine.d.ts +17 -0
- package/lib/createDirectLine.d.ts.map +1 -0
- package/lib/createDirectLine.js +3 -2
- package/lib/createDirectLineAppServiceExtension.d.ts +7 -0
- package/lib/createDirectLineAppServiceExtension.d.ts.map +1 -0
- package/lib/createDirectLineAppServiceExtension.js +1 -1
- package/lib/createDirectLineSpeechAdapters.d.ts +25 -0
- package/lib/createDirectLineSpeechAdapters.d.ts.map +1 -0
- package/lib/createDirectLineSpeechAdapters.js +57 -3
- package/lib/createFullStyleSet.d.ts +1375 -0
- package/lib/createFullStyleSet.d.ts.map +1 -0
- package/lib/createFullStyleSet.js +2 -2
- package/lib/fullBundleDefaultStyleOptions.js +4 -4
- package/lib/hooks/useStyleOptions.d.ts +3 -0
- package/lib/hooks/useStyleOptions.d.ts.map +1 -0
- package/lib/hooks/useStyleOptions.js +21 -0
- package/lib/index-es5.d.ts +4 -20
- package/lib/index-es5.d.ts.map +1 -1
- package/lib/index-es5.js +3 -43
- package/lib/index-minimal.d.ts +9 -6
- package/lib/index-minimal.d.ts.map +1 -1
- package/lib/index-minimal.js +27 -21
- package/lib/index.d.ts +164 -18
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +19 -12
- package/lib/polyfill.d.ts +23 -0
- package/lib/polyfill.d.ts.map +1 -0
- package/lib/polyfill.js +46 -0
- package/lib/renderMarkdown.d.ts +6 -0
- package/lib/renderMarkdown.d.ts.map +1 -0
- package/lib/renderMarkdown.js +36 -5
- package/lib/renderWebChat.d.ts +3 -0
- package/lib/renderWebChat.d.ts.map +1 -0
- package/lib/renderWebChat.js +1 -1
- package/lib/speech/CustomAudioInputStream.d.ts +94 -0
- package/lib/speech/CustomAudioInputStream.d.ts.map +1 -0
- package/lib/speech/CustomAudioInputStream.js +441 -0
- package/lib/speech/bytesPerSample.d.ts +2 -0
- package/lib/speech/bytesPerSample.d.ts.map +1 -0
- package/lib/speech/bytesPerSample.js +12 -0
- package/lib/speech/createAudioConfig.d.ts +23 -0
- package/lib/speech/createAudioConfig.d.ts.map +1 -0
- package/lib/speech/createAudioConfig.js +90 -0
- package/lib/speech/createAudioContext.d.ts +3 -0
- package/lib/speech/createAudioContext.d.ts.map +1 -0
- package/lib/speech/createAudioContext.js +22 -0
- package/lib/speech/createMicrophoneAudioConfigAndAudioContext.d.ts +9 -0
- package/lib/speech/createMicrophoneAudioConfigAndAudioContext.d.ts.map +1 -0
- package/lib/speech/createMicrophoneAudioConfigAndAudioContext.js +161 -0
- package/lib/speech/getUserMedia.d.ts +2 -0
- package/lib/speech/getUserMedia.d.ts.map +1 -0
- package/lib/speech/getUserMedia.js +25 -0
- package/lib/types/AdaptiveCardsPackage.d.ts +13 -0
- package/lib/types/AdaptiveCardsPackage.d.ts.map +1 -0
- package/lib/types/AdaptiveCardsPackage.js +2 -0
- package/lib/types/CognitiveServicesAudioOutputFormat.d.ts +3 -0
- package/lib/types/CognitiveServicesAudioOutputFormat.d.ts.map +1 -0
- package/lib/types/CognitiveServicesAudioOutputFormat.js +2 -0
- package/lib/types/CognitiveServicesCredentials.d.ts +18 -0
- package/lib/types/CognitiveServicesCredentials.d.ts.map +1 -0
- package/lib/types/CognitiveServicesCredentials.js +2 -0
- package/lib/types/CognitiveServicesTextNormalization.d.ts +3 -0
- package/lib/types/CognitiveServicesTextNormalization.d.ts.map +1 -0
- package/lib/types/CognitiveServicesTextNormalization.js +2 -0
- package/lib/{FullBundleStyleOptions.d.ts → types/FullBundleStyleOptions.d.ts} +1 -1
- package/lib/types/FullBundleStyleOptions.d.ts.map +1 -0
- package/lib/types/FullBundleStyleOptions.js +2 -0
- package/lib/useComposerProps.d.ts +22 -0
- package/lib/useComposerProps.d.ts.map +1 -0
- package/lib/useComposerProps.js +6 -8
- package/package.json +46 -48
- package/src/AddFullBundle.tsx +93 -0
- package/src/FullComposer.tsx +38 -0
- package/src/FullReactWebChat.tsx +32 -0
- package/src/__tests__/createDirectLine.spec.js +2 -0
- package/src/__tests__/renderMarkdown.spec.js +1 -1
- package/src/__tests__/versionTag.es5.spec.js +3 -0
- package/src/__tests__/versionTag.full.spec.js +3 -0
- package/src/__tests__/versionTag.minimal.spec.js +3 -0
- package/src/adaptiveCards/{AdaptiveCardsComposer.js → AdaptiveCardsComposer.tsx} +17 -5
- package/src/adaptiveCards/AdaptiveCardsContext.ts +12 -0
- package/src/adaptiveCards/AdaptiveCardsStyleOptions.ts +5 -3
- package/src/adaptiveCards/AdaptiveCardsStyleSet.ts +7 -0
- package/src/adaptiveCards/Attachment/{AdaptiveCardAttachment.js → AdaptiveCardAttachment.tsx} +8 -2
- package/src/adaptiveCards/Attachment/AdaptiveCardBuilder.ts +27 -17
- package/src/adaptiveCards/Attachment/{AdaptiveCardContent.js → AdaptiveCardContent.tsx} +8 -2
- package/src/adaptiveCards/Attachment/AdaptiveCardRenderer.tsx +768 -0
- package/src/adaptiveCards/Attachment/{AnimationCardContent.js → AnimationCardContent.tsx} +9 -2
- package/src/adaptiveCards/Attachment/{AudioCardContent.js → AudioCardContent.tsx} +9 -2
- package/src/adaptiveCards/Attachment/CommonCard.js +2 -1
- package/src/adaptiveCards/Attachment/{HeroCardContent.js → HeroCardContent.tsx} +12 -3
- package/src/adaptiveCards/Attachment/{OAuthCardContent.js → OAuthCardContent.tsx} +11 -3
- package/src/adaptiveCards/Attachment/{ReceiptCardContent.js → ReceiptCardContent.tsx} +58 -28
- package/src/adaptiveCards/Attachment/{SignInCardContent.js → SignInCardContent.tsx} +9 -2
- package/src/adaptiveCards/Attachment/{ThumbnailCardContent.js → ThumbnailCardContent.tsx} +12 -3
- package/src/adaptiveCards/Attachment/{VideoCardContent.js → VideoCardContent.tsx} +15 -3
- package/src/adaptiveCards/Styles/StyleSet/AdaptiveCardRenderer.ts +9 -1
- package/src/adaptiveCards/Styles/adaptiveCardHostConfig.ts +28 -8
- package/src/adaptiveCards/Styles/createAdaptiveCardsStyleSet.spec.js +2 -0
- package/src/adaptiveCards/Styles/createAdaptiveCardsStyleSet.ts +7 -4
- package/src/adaptiveCards/{createAdaptiveCardsAttachmentForScreenReaderMiddleware.js → createAdaptiveCardsAttachmentForScreenReaderMiddleware.tsx} +16 -15
- package/src/adaptiveCards/createAdaptiveCardsAttachmentMiddleware.tsx +44 -0
- package/src/adaptiveCards/defaultStyleOptions.ts +2 -1
- package/src/adaptiveCards/hooks/internal/{useAdaptiveCardsContext.js → useAdaptiveCardsContext.ts} +1 -1
- package/src/adaptiveCards/hooks/internal/{useParseAdaptiveCardJSON.js → useParseAdaptiveCardJSON.ts} +5 -2
- package/src/adaptiveCards/hooks/internal/{useUniqueId.js → useUniqueId.ts} +1 -1
- package/src/adaptiveCards/hooks/{useAdaptiveCardsHostConfig.js → useAdaptiveCardsHostConfig.ts} +6 -8
- package/src/adaptiveCards/hooks/{useAdaptiveCardsPackage.js → useAdaptiveCardsPackage.ts} +2 -1
- package/src/createBrowserWebSpeechPonyfillFactory.ts +21 -0
- package/src/createCognitiveServicesSpeechServicesPonyfillFactory.spec.js +36 -6
- package/src/createCognitiveServicesSpeechServicesPonyfillFactory.ts +78 -0
- package/src/createDirectLine.ts +65 -0
- package/src/createDirectLineAppServiceExtension.ts +22 -0
- package/src/createDirectLineSpeechAdapters.ts +84 -0
- package/src/createFullStyleSet.ts +2 -2
- package/src/fullBundleDefaultStyleOptions.ts +3 -3
- package/src/hooks/useStyleOptions.ts +9 -0
- package/src/index-es5.ts +3 -28
- package/src/index-minimal.ts +3 -2
- package/src/index.ts +22 -10
- package/src/polyfill.ts +29 -0
- package/src/renderMarkdown.ts +140 -0
- package/src/renderWebChat.tsx +6 -0
- package/src/speech/CustomAudioInputStream.ts +356 -0
- package/src/speech/bytesPerSample.ts +4 -0
- package/src/speech/createAudioConfig.spec.js +23 -0
- package/src/speech/createAudioConfig.ts +77 -0
- package/src/speech/createAudioContext.ts +16 -0
- package/src/speech/createMicrophoneAudioConfigAndAudioContext.ts +146 -0
- package/src/speech/getUserMedia.ts +14 -0
- package/src/tsconfig.json +1 -1
- package/src/types/AdaptiveCardsPackage.ts +23 -0
- package/src/types/CognitiveServicesAudioOutputFormat.ts +28 -0
- package/src/types/CognitiveServicesCredentials.ts +28 -0
- package/src/types/CognitiveServicesTextNormalization.ts +3 -0
- package/src/{FullBundleStyleOptions.ts → types/FullBundleStyleOptions.ts} +1 -1
- package/src/{useComposerProps.js → useComposerProps.ts} +21 -11
- package/webpack.config.js +46 -6
- package/.eslintignore +0 -9
- package/lib/FullBundleStyleOptions.d.ts.map +0 -1
- package/src/FullComposer.js +0 -40
- package/src/FullReactWebChat.js +0 -47
- package/src/adaptiveCards/AdaptiveCardsContext.js +0 -5
- package/src/adaptiveCards/Attachment/AdaptiveCardRenderer.js +0 -492
- package/src/adaptiveCards/createAdaptiveCardsAttachmentMiddleware.js +0 -41
- package/src/createBrowserWebSpeechPonyfillFactory.js +0 -16
- package/src/createCognitiveServicesSpeechServicesPonyfillFactory.js +0 -58
- package/src/createDirectLine.js +0 -38
- package/src/createDirectLineAppServiceExtension.js +0 -12
- package/src/createDirectLineSpeechAdapters.js +0 -5
- package/src/index-es5.tsx +0 -49
- package/src/index-minimal.tsx +0 -9
- package/src/index.tsx +0 -45
- package/src/renderMarkdown.js +0 -97
- package/src/renderWebChat.js +0 -6
|
@@ -1,492 +0,0 @@
|
|
|
1
|
-
/* eslint no-magic-numbers: ["error", { "ignore": [-1, 0, 2] }] */
|
|
2
|
-
|
|
3
|
-
import { Components, getTabIndex, hooks } from 'botframework-webchat-component';
|
|
4
|
-
import classNames from 'classnames';
|
|
5
|
-
import PropTypes from 'prop-types';
|
|
6
|
-
import React, { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
7
|
-
|
|
8
|
-
import useAdaptiveCardsHostConfig from '../hooks/useAdaptiveCardsHostConfig';
|
|
9
|
-
import useAdaptiveCardsPackage from '../hooks/useAdaptiveCardsPackage';
|
|
10
|
-
|
|
11
|
-
const { ErrorBox } = Components;
|
|
12
|
-
const { useDisabled, useLocalizer, usePerformCardAction, useRenderMarkdownAsHTML, useScrollToEnd, useStyleSet } = hooks;
|
|
13
|
-
|
|
14
|
-
// eslint-disable-next-line no-undef
|
|
15
|
-
const node_env = process.env.node_env || process.env.NODE_ENV;
|
|
16
|
-
|
|
17
|
-
function addClass(element, className) {
|
|
18
|
-
const classNames = new Set(element.className.split(' '));
|
|
19
|
-
|
|
20
|
-
if (!classNames.has(className)) {
|
|
21
|
-
classNames.add(className);
|
|
22
|
-
|
|
23
|
-
element.className = Array.from(classNames).join(' ');
|
|
24
|
-
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function addPersistentClassWithUndo(element, className) {
|
|
32
|
-
if (addClass(element, className)) {
|
|
33
|
-
// After we add the class, keep observing the element to make sure the class is not removed.
|
|
34
|
-
const observer = new MutationObserver(() => addClass(element, className));
|
|
35
|
-
|
|
36
|
-
observer.observe(element, { attributes: true, attributeFilter: ['class'] });
|
|
37
|
-
|
|
38
|
-
return () => {
|
|
39
|
-
const classNames = new Set(element.className.split(' '));
|
|
40
|
-
|
|
41
|
-
classNames.delete(className);
|
|
42
|
-
|
|
43
|
-
element.className = Array.from(classNames).join(' ');
|
|
44
|
-
observer.disconnect();
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function isPlainObject(obj) {
|
|
50
|
-
return Object.getPrototypeOf(obj) === Object.prototype;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function setAttributeWithUndo(element, qualifiedName, nextValue) {
|
|
54
|
-
const value = element.getAttribute(qualifiedName);
|
|
55
|
-
|
|
56
|
-
if (value !== nextValue) {
|
|
57
|
-
element.setAttribute(qualifiedName, nextValue);
|
|
58
|
-
|
|
59
|
-
return () => (value ? element.setAttribute(qualifiedName, value) : element.removeAttribute(qualifiedName));
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const disabledHandler = event => {
|
|
64
|
-
event.preventDefault();
|
|
65
|
-
event.stopImmediatePropagation();
|
|
66
|
-
event.stopPropagation();
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
function addEventListenerOnceWithUndo(element, name, handler) {
|
|
70
|
-
/* eslint-disable-next-line prefer-const */
|
|
71
|
-
let detach;
|
|
72
|
-
const detachingHandler = event => {
|
|
73
|
-
try {
|
|
74
|
-
handler(event);
|
|
75
|
-
} finally {
|
|
76
|
-
// IE11 does not support { once: true }, so we need to detach manually.
|
|
77
|
-
detach();
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
detach = () => element.removeEventListener(name, detachingHandler);
|
|
82
|
-
|
|
83
|
-
element.addEventListener(name, detachingHandler, { once: true });
|
|
84
|
-
|
|
85
|
-
return detach;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function addEventListenerWithUndo(element, name, handler) {
|
|
89
|
-
element.addEventListener(name, handler);
|
|
90
|
-
|
|
91
|
-
return () => element.removeEventListener(name, handler);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function disableElementWithUndo(element) {
|
|
95
|
-
const undoStack = [];
|
|
96
|
-
const isActive = element === document.activeElement;
|
|
97
|
-
const tag = element.nodeName.toLowerCase();
|
|
98
|
-
|
|
99
|
-
/* eslint-disable-next-line default-case */
|
|
100
|
-
switch (tag) {
|
|
101
|
-
case 'button':
|
|
102
|
-
case 'input':
|
|
103
|
-
case 'select':
|
|
104
|
-
case 'textarea':
|
|
105
|
-
undoStack.push(setAttributeWithUndo(element, 'aria-disabled', 'true'));
|
|
106
|
-
|
|
107
|
-
if (isActive) {
|
|
108
|
-
undoStack.push(
|
|
109
|
-
addEventListenerOnceWithUndo(element, 'blur', () =>
|
|
110
|
-
undoStack.push(setAttributeWithUndo(element, 'disabled', 'disabled'))
|
|
111
|
-
)
|
|
112
|
-
);
|
|
113
|
-
} else {
|
|
114
|
-
undoStack.push(setAttributeWithUndo(element, 'disabled', 'disabled'));
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (tag === 'input' || tag === 'textarea') {
|
|
118
|
-
undoStack.push(addEventListenerWithUndo(element, 'click', disabledHandler));
|
|
119
|
-
undoStack.push(setAttributeWithUndo(element, 'readonly', 'readonly'));
|
|
120
|
-
} else if (tag === 'select') {
|
|
121
|
-
undoStack.push(
|
|
122
|
-
...[].map.call(element.querySelectorAll('option'), option =>
|
|
123
|
-
setAttributeWithUndo(option, 'disabled', 'disabled')
|
|
124
|
-
)
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return () => undoStack.forEach(undo => undo && undo());
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function disableInputElementsWithUndo(element, observeSubtree = true) {
|
|
135
|
-
const undoStack = [].map.call(element.querySelectorAll('button, input, select, textarea'), element =>
|
|
136
|
-
disableElementWithUndo(element)
|
|
137
|
-
);
|
|
138
|
-
|
|
139
|
-
const tag = element.nodeName.toLowerCase();
|
|
140
|
-
|
|
141
|
-
// Only set tabindex="-1" on focusable element. Otherwise, we will make <div> focusable by mouse.
|
|
142
|
-
(tag === 'a' || tag === 'button' || tag === 'input' || tag === 'select' || tag === 'textarea') &&
|
|
143
|
-
undoStack.push(setAttributeWithUndo(element, 'tabindex', '-1'));
|
|
144
|
-
|
|
145
|
-
if (observeSubtree) {
|
|
146
|
-
const observer = new MutationObserver(mutations =>
|
|
147
|
-
mutations.forEach(({ addedNodes }) =>
|
|
148
|
-
undoStack.push(...addedNodes.map(addedNode => disableInputElementsWithUndo(addedNode, false)))
|
|
149
|
-
)
|
|
150
|
-
);
|
|
151
|
-
|
|
152
|
-
observer.observe(element, { childList: true, subtree: true });
|
|
153
|
-
|
|
154
|
-
undoStack.push(() => observer.disconnect());
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
return () => undoStack.forEach(undo => undo && undo());
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function getFocusableElements(element) {
|
|
161
|
-
return [].filter.call(
|
|
162
|
-
element.querySelectorAll(
|
|
163
|
-
[
|
|
164
|
-
'a',
|
|
165
|
-
'body',
|
|
166
|
-
'button',
|
|
167
|
-
'frame',
|
|
168
|
-
'iframe',
|
|
169
|
-
'img',
|
|
170
|
-
'input',
|
|
171
|
-
'isindex',
|
|
172
|
-
'object',
|
|
173
|
-
'select',
|
|
174
|
-
'textarea',
|
|
175
|
-
'[tabindex]'
|
|
176
|
-
].join(', ')
|
|
177
|
-
),
|
|
178
|
-
element => {
|
|
179
|
-
const tabIndex = getTabIndex(element);
|
|
180
|
-
|
|
181
|
-
return typeof tabIndex === 'number' && tabIndex >= 0;
|
|
182
|
-
}
|
|
183
|
-
);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
function restoreActiveElementIndex(element, activeElementIndex) {
|
|
187
|
-
const focusable = getFocusableElements(element)[activeElementIndex];
|
|
188
|
-
|
|
189
|
-
focusable && focusable.focus();
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
function saveActiveElementIndex(element) {
|
|
193
|
-
return getFocusableElements(element).indexOf(document.activeElement);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
function restoreInputValues(element, inputValues) {
|
|
197
|
-
const inputs = element.querySelectorAll('input, select, textarea');
|
|
198
|
-
|
|
199
|
-
[].forEach.call(inputs, (input, index) => {
|
|
200
|
-
const value = inputValues[index];
|
|
201
|
-
|
|
202
|
-
if (typeof value !== 'undefined') {
|
|
203
|
-
const { tagName, type } = input;
|
|
204
|
-
|
|
205
|
-
if (tagName === 'INPUT' && (type === 'checkbox' || type === 'radio')) {
|
|
206
|
-
input.checked = value;
|
|
207
|
-
} else {
|
|
208
|
-
input.value = value;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
function saveInputValues(element) {
|
|
215
|
-
const inputs = element.querySelectorAll('input, select, textarea');
|
|
216
|
-
|
|
217
|
-
return [].map.call(inputs, ({ checked, tagName, type, value }) => {
|
|
218
|
-
if (tagName === 'INPUT' && (type === 'checkbox' || type === 'radio')) {
|
|
219
|
-
return checked;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
return value;
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
const AdaptiveCardRenderer = ({ actionPerformedClassName, adaptiveCard, disabled: disabledFromProps, tapAction }) => {
|
|
227
|
-
const [{ adaptiveCardRenderer: adaptiveCardRendererStyleSet }] = useStyleSet();
|
|
228
|
-
const [{ GlobalSettings, HostConfig }] = useAdaptiveCardsPackage();
|
|
229
|
-
const [actionsPerformed, setActionsPerformed] = useState([]);
|
|
230
|
-
const [adaptiveCardsHostConfig] = useAdaptiveCardsHostConfig();
|
|
231
|
-
const [disabledFromComposer] = useDisabled();
|
|
232
|
-
const [errors, setErrors] = useState([]);
|
|
233
|
-
const [lastRender, setLastRender] = useState(0);
|
|
234
|
-
const activeElementIndexRef = useRef(-1);
|
|
235
|
-
const adaptiveCardElementRef = useRef();
|
|
236
|
-
const contentRef = useRef();
|
|
237
|
-
const inputValuesRef = useRef([]);
|
|
238
|
-
const localize = useLocalizer();
|
|
239
|
-
const performCardAction = usePerformCardAction();
|
|
240
|
-
const renderMarkdownAsHTML = useRenderMarkdownAsHTML();
|
|
241
|
-
const scrollToEnd = useScrollToEnd();
|
|
242
|
-
|
|
243
|
-
const disabled = disabledFromComposer || disabledFromProps;
|
|
244
|
-
|
|
245
|
-
// TODO: [P2] #3199 We should consider using `adaptiveCard.selectAction` instead.
|
|
246
|
-
// The null check for "tapAction" is in "handleClickAndKeyPressForTapAction".
|
|
247
|
-
const handleClickAndKeyPress = useCallback(
|
|
248
|
-
event => {
|
|
249
|
-
const { key, target, type } = event;
|
|
250
|
-
|
|
251
|
-
// Some items, e.g. tappable text, cannot be disabled thru DOM attributes
|
|
252
|
-
const { current } = contentRef;
|
|
253
|
-
const adaptiveCardRoot = current.querySelector('.ac-adaptiveCard[tabindex="0"]');
|
|
254
|
-
|
|
255
|
-
if (!adaptiveCardRoot) {
|
|
256
|
-
return console.warn(
|
|
257
|
-
'botframework-webchat: No Adaptive Card root container can be found; the card is probably on an unsupported Adaptive Card version.'
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
// For "keypress" event, we only listen to ENTER and SPACEBAR key.
|
|
262
|
-
if (type === 'keypress') {
|
|
263
|
-
if (key !== 'Enter' && key !== ' ') {
|
|
264
|
-
return;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
event.preventDefault();
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// We will call performCardAction if either:
|
|
271
|
-
// 1. We are on the target, or
|
|
272
|
-
// 2. The event-dispatching element is not interactive
|
|
273
|
-
if (target !== adaptiveCardRoot) {
|
|
274
|
-
const tabIndex = getTabIndex(target);
|
|
275
|
-
|
|
276
|
-
// If the user is clicking on something that is already clickable, do not allow them to click the card.
|
|
277
|
-
// E.g. a hero card can be tappable, and image and buttons inside the hero card can also be tappable.
|
|
278
|
-
if (typeof tabIndex === 'number' && tabIndex >= 0) {
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
performCardAction(tapAction);
|
|
284
|
-
scrollToEnd();
|
|
285
|
-
},
|
|
286
|
-
[contentRef, performCardAction, scrollToEnd, tapAction]
|
|
287
|
-
);
|
|
288
|
-
|
|
289
|
-
// Only listen to event if it is not disabled and have "tapAction" prop.
|
|
290
|
-
const handleClickAndKeyPressForTapAction = !disabled && tapAction ? handleClickAndKeyPress : undefined;
|
|
291
|
-
|
|
292
|
-
const addActionsPerformed = useCallback(
|
|
293
|
-
action => !~actionsPerformed.indexOf(action) && setActionsPerformed([...actionsPerformed, action]),
|
|
294
|
-
[actionsPerformed, setActionsPerformed]
|
|
295
|
-
);
|
|
296
|
-
|
|
297
|
-
const handleExecuteAction = useCallback(
|
|
298
|
-
action => {
|
|
299
|
-
// Some items, e.g. tappable image, cannot be disabled thru DOM attributes
|
|
300
|
-
if (disabled) {
|
|
301
|
-
return;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
addActionsPerformed(action);
|
|
305
|
-
|
|
306
|
-
const actionTypeName = action.getJsonTypeName();
|
|
307
|
-
|
|
308
|
-
if (actionTypeName === 'Action.OpenUrl') {
|
|
309
|
-
performCardAction({
|
|
310
|
-
type: 'openUrl',
|
|
311
|
-
value: action.url
|
|
312
|
-
});
|
|
313
|
-
} else if (actionTypeName === 'Action.Submit') {
|
|
314
|
-
if (typeof action.data !== 'undefined') {
|
|
315
|
-
const { data: actionData } = action;
|
|
316
|
-
|
|
317
|
-
if (actionData && actionData.__isBotFrameworkCardAction) {
|
|
318
|
-
const { cardAction } = actionData;
|
|
319
|
-
const { displayText, text, type, value } = cardAction;
|
|
320
|
-
|
|
321
|
-
performCardAction({ displayText, text, type, value });
|
|
322
|
-
} else {
|
|
323
|
-
performCardAction({
|
|
324
|
-
type: typeof action.data === 'string' ? 'imBack' : 'postBack',
|
|
325
|
-
value: action.data
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
scrollToEnd();
|
|
331
|
-
} else {
|
|
332
|
-
console.error(`Web Chat: received unknown action from Adaptive Cards`);
|
|
333
|
-
console.error(action);
|
|
334
|
-
}
|
|
335
|
-
},
|
|
336
|
-
[addActionsPerformed, disabled, performCardAction, scrollToEnd]
|
|
337
|
-
);
|
|
338
|
-
|
|
339
|
-
useLayoutEffect(() => {
|
|
340
|
-
const { current } = contentRef;
|
|
341
|
-
|
|
342
|
-
if (!current || !adaptiveCard) {
|
|
343
|
-
activeElementIndexRef.current = -1;
|
|
344
|
-
inputValuesRef.current = [];
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
// Currently, the only way to set the Markdown engine is to set it thru static member of AdaptiveCard class
|
|
348
|
-
|
|
349
|
-
// TODO: [P3] Checks if we could make the "renderMarkdownAsHTML" per card
|
|
350
|
-
// This could be limitations from Adaptive Cards package (not supported as of 1.2.5)
|
|
351
|
-
// Because there could be timing difference between .parse and .render, we could be using wrong Markdown engine
|
|
352
|
-
|
|
353
|
-
adaptiveCard.constructor.onProcessMarkdown = (text, result) => {
|
|
354
|
-
if (renderMarkdownAsHTML) {
|
|
355
|
-
result.outputHtml = renderMarkdownAsHTML(text);
|
|
356
|
-
result.didProcess = true;
|
|
357
|
-
}
|
|
358
|
-
};
|
|
359
|
-
|
|
360
|
-
if (adaptiveCardsHostConfig) {
|
|
361
|
-
adaptiveCard.hostConfig = isPlainObject(adaptiveCardsHostConfig)
|
|
362
|
-
? new HostConfig(adaptiveCardsHostConfig)
|
|
363
|
-
: adaptiveCardsHostConfig;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
// For accessibility issue #1340, `tabindex="0"` must not be set for the root container if it is not interactive.
|
|
367
|
-
GlobalSettings.setTabIndexAtCardRoot = !!tapAction;
|
|
368
|
-
|
|
369
|
-
const { validationEvents } = adaptiveCard.validateProperties();
|
|
370
|
-
|
|
371
|
-
if (validationEvents.length) {
|
|
372
|
-
return setErrors(validationEvents.reduce((items, { message }) => [...items, new Error(message)], []));
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
let element;
|
|
376
|
-
|
|
377
|
-
try {
|
|
378
|
-
element = adaptiveCard.render();
|
|
379
|
-
} catch (error) {
|
|
380
|
-
return setErrors([error]);
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
if (!element) {
|
|
384
|
-
return setErrors([new Error('Adaptive Card rendered as empty element')]);
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
// Clear errors on next render
|
|
388
|
-
setErrors([]);
|
|
389
|
-
|
|
390
|
-
restoreInputValues(element, inputValuesRef.current);
|
|
391
|
-
|
|
392
|
-
current.appendChild(element);
|
|
393
|
-
adaptiveCardElementRef.current = element;
|
|
394
|
-
|
|
395
|
-
// Focus can only be restored after the DOM is attached.
|
|
396
|
-
restoreActiveElementIndex(element, activeElementIndexRef.current);
|
|
397
|
-
|
|
398
|
-
setLastRender(Date.now());
|
|
399
|
-
|
|
400
|
-
return () => {
|
|
401
|
-
activeElementIndexRef.current = saveActiveElementIndex(element);
|
|
402
|
-
inputValuesRef.current = saveInputValues(element);
|
|
403
|
-
|
|
404
|
-
current.removeChild(adaptiveCardElementRef.current);
|
|
405
|
-
|
|
406
|
-
adaptiveCardElementRef.current = undefined;
|
|
407
|
-
};
|
|
408
|
-
}, [
|
|
409
|
-
adaptiveCard,
|
|
410
|
-
adaptiveCardsHostConfig,
|
|
411
|
-
contentRef,
|
|
412
|
-
GlobalSettings,
|
|
413
|
-
HostConfig,
|
|
414
|
-
renderMarkdownAsHTML,
|
|
415
|
-
setErrors,
|
|
416
|
-
tapAction
|
|
417
|
-
]);
|
|
418
|
-
|
|
419
|
-
useEffect(() => {
|
|
420
|
-
// Set onExecuteAction without causing unnecessary re-render.
|
|
421
|
-
adaptiveCard.onExecuteAction = disabled ? undefined : handleExecuteAction;
|
|
422
|
-
}, [adaptiveCard, disabled, handleExecuteAction]);
|
|
423
|
-
|
|
424
|
-
useEffect(() => {
|
|
425
|
-
// If the Adaptive Card get re-rendered, re-disable elements as needed.
|
|
426
|
-
if (disabled) {
|
|
427
|
-
return disableInputElementsWithUndo(adaptiveCardElementRef.current);
|
|
428
|
-
}
|
|
429
|
-
}, [disabled, lastRender]);
|
|
430
|
-
|
|
431
|
-
useEffect(() => {
|
|
432
|
-
// If the Adaptive Card changed, reset all actions performed.
|
|
433
|
-
setActionsPerformed([]);
|
|
434
|
-
}, [adaptiveCard]);
|
|
435
|
-
|
|
436
|
-
useEffect(() => {
|
|
437
|
-
// Add aria-pressed and role attribute to the AC action button selected by the user.
|
|
438
|
-
actionsPerformed.forEach(({ renderedElement }) => {
|
|
439
|
-
if (renderedElement && adaptiveCardElementRef.current.contains(renderedElement)) {
|
|
440
|
-
setAttributeWithUndo(renderedElement, 'aria-pressed', 'true');
|
|
441
|
-
setAttributeWithUndo(renderedElement, 'role', 'button');
|
|
442
|
-
}
|
|
443
|
-
});
|
|
444
|
-
|
|
445
|
-
// Add developers to highlight actions when they have been clicked.
|
|
446
|
-
if (!actionPerformedClassName) {
|
|
447
|
-
return;
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
const undoStack = actionsPerformed.map(
|
|
451
|
-
({ renderedElement }) =>
|
|
452
|
-
renderedElement &&
|
|
453
|
-
adaptiveCardElementRef.current.contains(renderedElement) &&
|
|
454
|
-
addPersistentClassWithUndo(renderedElement, actionPerformedClassName)
|
|
455
|
-
);
|
|
456
|
-
|
|
457
|
-
return () => undoStack.forEach(undo => undo && undo());
|
|
458
|
-
}, [actionsPerformed, actionPerformedClassName, lastRender]);
|
|
459
|
-
|
|
460
|
-
return errors.length ? (
|
|
461
|
-
node_env === 'development' ? (
|
|
462
|
-
<ErrorBox error={errors[0]} type={localize('ADAPTIVE_CARD_ERROR_BOX_TITLE_RENDER')} />
|
|
463
|
-
) : (
|
|
464
|
-
false
|
|
465
|
-
)
|
|
466
|
-
) : (
|
|
467
|
-
<div
|
|
468
|
-
className={classNames(adaptiveCardRendererStyleSet + '', 'webchat__adaptive-card-renderer')}
|
|
469
|
-
onClick={handleClickAndKeyPressForTapAction}
|
|
470
|
-
onKeyPress={handleClickAndKeyPressForTapAction}
|
|
471
|
-
ref={contentRef}
|
|
472
|
-
/>
|
|
473
|
-
);
|
|
474
|
-
};
|
|
475
|
-
|
|
476
|
-
AdaptiveCardRenderer.defaultProps = {
|
|
477
|
-
actionPerformedClassName: '',
|
|
478
|
-
disabled: undefined,
|
|
479
|
-
tapAction: undefined
|
|
480
|
-
};
|
|
481
|
-
|
|
482
|
-
AdaptiveCardRenderer.propTypes = {
|
|
483
|
-
actionPerformedClassName: PropTypes.string,
|
|
484
|
-
adaptiveCard: PropTypes.any.isRequired,
|
|
485
|
-
disabled: PropTypes.bool,
|
|
486
|
-
tapAction: PropTypes.shape({
|
|
487
|
-
type: PropTypes.string.isRequired,
|
|
488
|
-
value: PropTypes.string
|
|
489
|
-
})
|
|
490
|
-
};
|
|
491
|
-
|
|
492
|
-
export default AdaptiveCardRenderer;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
import AdaptiveCardAttachment from './Attachment/AdaptiveCardAttachment';
|
|
4
|
-
import AnimationCardAttachment from './Attachment/AnimationCardAttachment';
|
|
5
|
-
import AudioCardAttachment from './Attachment/AudioCardAttachment';
|
|
6
|
-
import HeroCardAttachment from './Attachment/HeroCardAttachment';
|
|
7
|
-
import OAuthCardAttachment from './Attachment/OAuthCardAttachment';
|
|
8
|
-
import ReceiptCardAttachment from './Attachment/ReceiptCardAttachment';
|
|
9
|
-
import SignInCardAttachment from './Attachment/SignInCardAttachment';
|
|
10
|
-
import ThumbnailCardAttachment from './Attachment/ThumbnailCardAttachment';
|
|
11
|
-
import VideoCardAttachment from './Attachment/VideoCardAttachment';
|
|
12
|
-
|
|
13
|
-
export default function createAdaptiveCardsAttachmentMiddleware() {
|
|
14
|
-
// This is not returning a React component, but a render function.
|
|
15
|
-
/* eslint-disable-next-line react/display-name */
|
|
16
|
-
return () => next => (...args) => {
|
|
17
|
-
const [{ activity, attachment }] = args;
|
|
18
|
-
|
|
19
|
-
return attachment.contentType === 'application/vnd.microsoft.card.hero' ? (
|
|
20
|
-
<HeroCardAttachment activity={activity} attachment={attachment} />
|
|
21
|
-
) : attachment.contentType === 'application/vnd.microsoft.card.adaptive' ? (
|
|
22
|
-
<AdaptiveCardAttachment activity={activity} attachment={attachment} />
|
|
23
|
-
) : attachment.contentType === 'application/vnd.microsoft.card.animation' ? (
|
|
24
|
-
<AnimationCardAttachment activity={activity} attachment={attachment} />
|
|
25
|
-
) : attachment.contentType === 'application/vnd.microsoft.card.audio' ? (
|
|
26
|
-
<AudioCardAttachment activity={activity} attachment={attachment} />
|
|
27
|
-
) : attachment.contentType === 'application/vnd.microsoft.card.oauth' ? (
|
|
28
|
-
<OAuthCardAttachment activity={activity} attachment={attachment} />
|
|
29
|
-
) : attachment.contentType === 'application/vnd.microsoft.card.receipt' ? (
|
|
30
|
-
<ReceiptCardAttachment activity={activity} attachment={attachment} />
|
|
31
|
-
) : attachment.contentType === 'application/vnd.microsoft.card.signin' ? (
|
|
32
|
-
<SignInCardAttachment activity={activity} attachment={attachment} />
|
|
33
|
-
) : attachment.contentType === 'application/vnd.microsoft.card.thumbnail' ? (
|
|
34
|
-
<ThumbnailCardAttachment activity={activity} attachment={attachment} />
|
|
35
|
-
) : attachment.contentType === 'application/vnd.microsoft.card.video' ? (
|
|
36
|
-
<VideoCardAttachment activity={activity} attachment={attachment} />
|
|
37
|
-
) : (
|
|
38
|
-
next(...args)
|
|
39
|
-
);
|
|
40
|
-
};
|
|
41
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export default function createBrowserWebSpeechPonyfillFactory() {
|
|
2
|
-
if (!window.SpeechRecognition && !window.webkitSpeechRecognition) {
|
|
3
|
-
console.warn('Web Chat: This browser does not support Web Speech API Speech Recognition.');
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
if (!window.speechSynthesis) {
|
|
7
|
-
console.warn('Web Chat: This browser does not support Web Speech API Speech Synthesis.');
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
return () => ({
|
|
11
|
-
SpeechGrammarList: window.SpeechGrammarList || window.webkitSpeechGrammarList,
|
|
12
|
-
SpeechRecognition: window.SpeechRecognition || window.webkitSpeechRecognition,
|
|
13
|
-
speechSynthesis: window.speechSynthesis,
|
|
14
|
-
SpeechSynthesisUtterance: window.SpeechSynthesisUtterance
|
|
15
|
-
});
|
|
16
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { AudioConfig } from 'microsoft-cognitiveservices-speech-sdk/distrib/lib/src/sdk/Audio/AudioConfig';
|
|
2
|
-
import createPonyfill from 'web-speech-cognitive-services/lib/SpeechServices';
|
|
3
|
-
|
|
4
|
-
export default function createCognitiveServicesSpeechServicesPonyfillFactory({
|
|
5
|
-
audioConfig,
|
|
6
|
-
audioContext,
|
|
7
|
-
audioInputDeviceId,
|
|
8
|
-
credentials,
|
|
9
|
-
enableTelemetry,
|
|
10
|
-
speechRecognitionEndpointId,
|
|
11
|
-
speechSynthesisDeploymentId,
|
|
12
|
-
speechSynthesisOutputFormat,
|
|
13
|
-
textNormalization
|
|
14
|
-
}) {
|
|
15
|
-
if (!window.navigator.mediaDevices && !audioConfig) {
|
|
16
|
-
console.warn(
|
|
17
|
-
'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.'
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
return () => ({});
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (audioConfig && audioInputDeviceId) {
|
|
24
|
-
console.warn(
|
|
25
|
-
'botframework-webchat: "audioConfig" and "audioInputDeviceId" cannot be set at the same time; ignoring "audioInputDeviceId".'
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// WORKAROUND: We should prevent AudioContext object from being recreated because they may be blessed and UX-wise expensive to recreate.
|
|
30
|
-
// In Cognitive Services SDK, if they detect the "end" function is falsy, they will not call "end" but "suspend" instead.
|
|
31
|
-
// And on next recognition, they will re-use the AudioContext object.
|
|
32
|
-
if (!audioConfig) {
|
|
33
|
-
audioConfig = audioInputDeviceId
|
|
34
|
-
? AudioConfig.fromMicrophoneInput(audioInputDeviceId)
|
|
35
|
-
: AudioConfig.fromDefaultMicrophoneInput();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return ({ referenceGrammarID } = {}) => {
|
|
39
|
-
const { SpeechGrammarList, SpeechRecognition, speechSynthesis, SpeechSynthesisUtterance } = createPonyfill({
|
|
40
|
-
audioConfig,
|
|
41
|
-
audioContext,
|
|
42
|
-
credentials,
|
|
43
|
-
enableTelemetry,
|
|
44
|
-
referenceGrammars: referenceGrammarID ? [`luis/${referenceGrammarID}-PRODUCTION`] : [],
|
|
45
|
-
speechRecognitionEndpointId,
|
|
46
|
-
speechSynthesisDeploymentId,
|
|
47
|
-
speechSynthesisOutputFormat,
|
|
48
|
-
textNormalization
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
SpeechGrammarList,
|
|
53
|
-
SpeechRecognition,
|
|
54
|
-
speechSynthesis,
|
|
55
|
-
SpeechSynthesisUtterance
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
}
|
package/src/createDirectLine.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { DirectLine } from 'botframework-directlinejs';
|
|
2
|
-
|
|
3
|
-
export default function createDirectLine({
|
|
4
|
-
botAgent,
|
|
5
|
-
conversationId,
|
|
6
|
-
conversationStartProperties,
|
|
7
|
-
domain,
|
|
8
|
-
fetch,
|
|
9
|
-
pollingInterval,
|
|
10
|
-
secret,
|
|
11
|
-
streamUrl,
|
|
12
|
-
token,
|
|
13
|
-
watermark,
|
|
14
|
-
webSocket
|
|
15
|
-
}) {
|
|
16
|
-
return new DirectLine({
|
|
17
|
-
botAgent,
|
|
18
|
-
conversationId,
|
|
19
|
-
conversationStartProperties,
|
|
20
|
-
domain,
|
|
21
|
-
fetch,
|
|
22
|
-
pollingInterval,
|
|
23
|
-
secret,
|
|
24
|
-
streamUrl,
|
|
25
|
-
token,
|
|
26
|
-
watermark,
|
|
27
|
-
webSocket,
|
|
28
|
-
createFormData: attachments => {
|
|
29
|
-
const formData = new FormData();
|
|
30
|
-
|
|
31
|
-
attachments.forEach(({ contentType, data, filename, name }) => {
|
|
32
|
-
formData.append(name, new Blob(data, { contentType }), filename);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
return formData;
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { DirectLineStreaming } from 'botframework-directlinejs';
|
|
2
|
-
|
|
3
|
-
export default function createDirectLineAppServiceExtension({ botAgent, conversationId, domain, token }) {
|
|
4
|
-
return Promise.resolve(
|
|
5
|
-
new DirectLineStreaming({
|
|
6
|
-
botAgent,
|
|
7
|
-
conversationId,
|
|
8
|
-
domain,
|
|
9
|
-
token
|
|
10
|
-
})
|
|
11
|
-
);
|
|
12
|
-
}
|