Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ Notes: web developers are advised to use [`~` (tilde range)](https://github.com/
- `@msinternal/botframework-webchat-react-hooks` for helpers for React hooks
- Added link sanitization and ESLint rules, in PR [#5564](https://github.com/microsoft/BotFramework-WebChat/pull/5564), by [@compulim](https://github.com/compulim)
- Added blob URL sanitization and ESLint rules, in PR [#5568](https://github.com/microsoft/BotFramework-WebChat/pull/5568), by [@compulim](https://github.com/compulim)
- Added new prop `enableStreaming` to composer that activates streamed responses in PR [#5467](https://github.com/microsoft/BotFramework-WebChat/pull/5467), by [pranavjoshi001](https://github.com/pranavjoshi001)

### Changed

Expand Down
10 changes: 10 additions & 0 deletions packages/api/src/hooks/Composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
sendPostBack,
setDictateInterims,
setDictateState,
setEnableStreaming,
setLanguage,
setNotification,
setSendBox,
Expand Down Expand Up @@ -111,6 +112,7 @@ const DISPATCHERS = {
sendPostBack,
setDictateInterims,
setDictateState,
setEnableStreaming,
setNotification,
setSendBox,
setSendBoxAttachments,
Expand Down Expand Up @@ -232,6 +234,7 @@ type ComposerCoreProps = Readonly<{
type: string,
quality: number
) => Promise<URL>;
enableStreaming?: boolean;
grammars?: any;
groupActivitiesMiddleware?: OneOrMany<GroupActivitiesMiddleware>;
locale?: string;
Expand Down Expand Up @@ -277,6 +280,7 @@ const ComposerCore = ({
directLine,
disabled,
downscaleImageToDataURL,
enableStreaming,
grammars,
groupActivitiesMiddleware,
locale,
Expand Down Expand Up @@ -317,6 +321,10 @@ const ComposerCore = ({
dispatch(setSendTypingIndicator(!!sendTypingIndicator));
}, [dispatch, sendTypingIndicator]);

useEffect(() => {
dispatch(setEnableStreaming(!!enableStreaming));
}, [dispatch, enableStreaming]);

useEffect(() => {
dispatch(
createConnectAction({
Expand Down Expand Up @@ -648,6 +656,7 @@ ComposerCore.defaultProps = {
dir: 'auto',
disabled: false,
downscaleImageToDataURL: undefined,
enableStreaming: false,
grammars: [],
groupActivitiesMiddleware: undefined,
locale: window.navigator.language || 'en-US',
Expand Down Expand Up @@ -690,6 +699,7 @@ ComposerCore.propTypes = {
}).isRequired,
disabled: PropTypes.bool,
downscaleImageToDataURL: PropTypes.func,
enableStreaming: PropTypes.bool,
grammars: PropTypes.arrayOf(PropTypes.string),
groupActivitiesMiddleware: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.func), PropTypes.func]),
locale: PropTypes.string,
Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/actions/setEnableStreaming.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const SET_ENABLE_STREAMING = 'WEB_CHAT/SET_ENABLE_STREAMING';

export default function setEnableStreaming(enableStreaming: boolean) {
return {
type: SET_ENABLE_STREAMING,
payload: { enableStreaming }
};
}

export { SET_ENABLE_STREAMING };
2 changes: 2 additions & 0 deletions packages/core/src/createReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import sendTypingIndicator from './reducers/sendTypingIndicator';
import shouldSpeakIncomingActivity from './reducers/shouldSpeakIncomingActivity';
import suggestedActions from './reducers/suggestedActions';
import suggestedActionsOriginActivity from './reducers/suggestedActionsOriginActivity';
import enableStreaming from './reducers/enableStreaming';

import type { GlobalScopePonyfill } from './types/GlobalScopePonyfill';

Expand All @@ -26,6 +27,7 @@ export default function createReducer(ponyfill: GlobalScopePonyfill) {
connectivityStatus,
dictateInterims,
dictateState,
enableStreaming,
internal: createInternalReducer(ponyfill),
language,
notifications: createNotificationsReducer(ponyfill),
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import setSendBox from './actions/setSendBox';
import setSendBoxAttachments from './actions/setSendBoxAttachments';
import setSendTimeout from './actions/setSendTimeout';
import setSendTypingIndicator from './actions/setSendTypingIndicator';
import setEnableStreaming from './actions/setEnableStreaming';
import startDictate from './actions/startDictate';
import startSpeakingActivity from './actions/startSpeakingActivity';
import stopDictate from './actions/stopDictate';
Expand Down Expand Up @@ -121,6 +122,7 @@ export {
sendPostBack,
setDictateInterims,
setDictateState,
setEnableStreaming,
setLanguage,
setNotification,
setSendBox,
Expand Down
16 changes: 16 additions & 0 deletions packages/core/src/reducers/enableStreaming.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { SET_ENABLE_STREAMING } from '../actions/setEnableStreaming';

const DEFAULT_STATE = false;

export default function enableStreaming(state = DEFAULT_STATE, { payload, type }) {
switch (type) {
case SET_ENABLE_STREAMING:
state = payload.enableStreaming;
break;

default:
break;
}

return state;
}
5 changes: 4 additions & 1 deletion packages/core/src/sagas/sendMessageToPostActivitySaga.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { put, takeEvery } from 'redux-saga/effects';
import { put, select, takeEvery } from 'redux-saga/effects';

import postActivity from '../actions/postActivity';
import sendMessage, { SEND_MESSAGE } from '../actions/sendMessage';
import whileConnected from './effects/whileConnected';
import enableStreaming from '../selectors/enableStreaming';

function* postActivityWithMessage({
payload: { attachments = [], channelData, method, text }
}: ReturnType<typeof sendMessage>) {
const isStreamingEnabled = yield select(enableStreaming);
yield put(
postActivity(
{
Expand All @@ -23,6 +25,7 @@ function* postActivityWithMessage({
...channelData,
attachmentSizes: attachments.map(({ blob: { size } }) => size)
},
...(isStreamingEnabled && { deliveryMode: 'stream' }),
text: text || undefined,
textFormat: 'plain',
type: 'message'
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/selectors/enableStreaming.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { ReduxState } from '../types/internal/ReduxState';

export default ({ enableStreaming }: ReduxState): boolean => enableStreaming;
1 change: 1 addition & 0 deletions packages/core/src/types/internal/ReduxState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type ReduxState = {
sendTimeout: number;
sendTypingIndicator: boolean;
shouldSpeakIncomingActivity: boolean;
enableStreaming: boolean;
};

export type { ReduxState };