-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pre-chat message with starter prompts (#5255)
* Add pre-chat message with starter prompts * Add pre-chat message * useSuggestedActions: add origin activity * Add maxMessageLength.infinity test * Incorp PR changes * Apply PR suggestions * Flush on CSS vars
- Loading branch information
Showing
36 changed files
with
771 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+8.67 KB
...inity-js-fluent-theme-applied-handles-max-message-length-of-infinity-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+31.7 KB
...age-activity-js-fluent-theme-applied-should-display-pre-chat-message-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+43.6 KB
...-fluent-theme-applied-should-display-pre-chat-message-in-wide-format-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<!doctype html> | ||
<html lang="en-US"> | ||
<head> | ||
<link href="/assets/index.css" rel="stylesheet" type="text/css" /> | ||
<script crossorigin="anonymous" src="https://unpkg.com/@babel/standalone/babel.min.js"></script> | ||
<script crossorigin="anonymous" src="https://unpkg.com/[email protected]/umd/react.production.min.js"></script> | ||
<script crossorigin="anonymous" src="https://unpkg.com/[email protected]/umd/react-dom.production.min.js"></script> | ||
<script crossorigin="anonymous" src="/test-harness.js"></script> | ||
<script crossorigin="anonymous" src="/test-page-object.js"></script> | ||
<script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script> | ||
<script crossorigin="anonymous" src="/__dist__/botframework-webchat-fluent-theme.production.min.js"></script> | ||
</head> | ||
<body> | ||
<main id="webchat"></main> | ||
<script type="text/babel"> | ||
run(async function () { | ||
const { | ||
React, | ||
ReactDOM: { render }, | ||
WebChat: { FluentThemeProvider, ReactWebChat } | ||
} = window; // Imports in UMD fashion. | ||
|
||
const { directLine, store } = testHelpers.createDirectLineEmulator(); | ||
|
||
const App = () => ( | ||
<ReactWebChat directLine={directLine} store={store} styleOptions={{ maxMessageLength: Infinity }} /> | ||
); | ||
|
||
render( | ||
<FluentThemeProvider> | ||
<App /> | ||
</FluentThemeProvider>, | ||
document.getElementById('webchat') | ||
); | ||
|
||
await pageConditions.uiConnected(); | ||
|
||
document.querySelector(`[data-testid="${WebChat.testIds.sendBoxTextBox}"]`).focus(); | ||
await host.sendKeys('Occaecat sunt eu enim tempor cillum laboris esse esse.'); | ||
|
||
// THEN: Should not show the message length indicator. | ||
await host.snapshot(); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */ | ||
|
||
describe('Fluent theme applied', () => { | ||
test('handles max message length of Infinity', () => runHTML('fluentTheme/maxMessageLength.infinity')); | ||
}); |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */ | ||
|
||
describe('Fluent theme applied', () => { | ||
test('should display pre-chat message', () => runHTML('fluentTheme/preChatMessageActivity')); | ||
}); |
106 changes: 106 additions & 0 deletions
106
__tests__/html/fluentTheme/preChatMessageActivity.wide.html
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */ | ||
|
||
describe('Fluent theme applied', () => { | ||
test('should display pre-chat message in wide format', () => runHTML('fluentTheme/preChatMessageActivity.wide')); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...core/src/actions/clearSuggestedActions.js → ...core/src/actions/clearSuggestedActions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { DirectLineCardAction } from '../types/external/DirectLineCardAction'; | ||
import type { WebChatActivity } from '../types/WebChatActivity'; | ||
|
||
const EMPTY_ARRAY: readonly DirectLineCardAction[] = Object.freeze([]); | ||
|
||
const SET_SUGGESTED_ACTIONS = 'WEB_CHAT/SET_SUGGESTED_ACTIONS' as const; | ||
|
||
export default function setSuggestedActions( | ||
suggestedActions: readonly DirectLineCardAction[] = EMPTY_ARRAY, | ||
originActivity: undefined | WebChatActivity = undefined | ||
) { | ||
return { | ||
type: SET_SUGGESTED_ACTIONS, | ||
payload: { originActivity, suggestedActions } | ||
}; | ||
} | ||
|
||
export { SET_SUGGESTED_ACTIONS }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
packages/core/src/reducers/suggestedActionsOriginActivity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type clearSuggestedActions from '../actions/clearSuggestedActions'; | ||
import { CLEAR_SUGGESTED_ACTIONS } from '../actions/clearSuggestedActions'; | ||
import type setSuggestedActions from '../actions/setSuggestedActions'; | ||
import { SET_SUGGESTED_ACTIONS } from '../actions/setSuggestedActions'; | ||
import type { WebChatActivity } from '../types/WebChatActivity'; | ||
|
||
type ClearSuggestedActions = ReturnType<typeof clearSuggestedActions>; | ||
type SetSuggestedActions = ReturnType<typeof setSuggestedActions>; | ||
type State = Readonly<{ activity: undefined | WebChatActivity }>; | ||
|
||
const DEFAULT_STATE: State = Object.freeze({ activity: undefined }); | ||
|
||
export default function suggestedActionsOriginActivity( | ||
state = DEFAULT_STATE, | ||
action: ClearSuggestedActions | SetSuggestedActions | ||
): State { | ||
switch (action.type) { | ||
case SET_SUGGESTED_ACTIONS: | ||
state = { activity: action.payload.originActivity }; | ||
|
||
break; | ||
|
||
case CLEAR_SUGGESTED_ACTIONS: | ||
state = DEFAULT_STATE; | ||
|
||
break; | ||
|
||
default: | ||
break; | ||
} | ||
|
||
return state; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
packages/fluent-theme/src/components/preChatActivity/PreChatMessageActivity.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
:global(.webchat-fluent) .pre-chat-message-activity { | ||
display: grid; | ||
grid-template-areas: 'body' 'toolbar'; | ||
grid-template-rows: auto auto; | ||
gap: var(--webchat-spacingHorizontalXXXL); | ||
padding: var(--webchat-spacingHorizontalXXXL); | ||
} | ||
|
||
:global(.webchat-fluent) .pre-chat-message-activity__body { | ||
font-family: var(--webchat-fontFamilyBase); | ||
font-size: var(--webchat-fontSizeBase300); | ||
font-weight: var(--webchat-fontWeightRegular); | ||
grid-area: body; | ||
line-height: var(--webchat-lineHeightBase300); | ||
text-align: center; | ||
} | ||
|
||
:global(.webchat-fluent) .pre-chat-message-activity__body h2 { | ||
color: var(--webchat-colorNeutralForeground1); | ||
font-family: inherit; | ||
font-weight: var(--webchat-fontWeightSemibold); | ||
font-size: var(--webchat-fontSizeHero700); | ||
line-height: var(--webchat-lineHeightHero700); | ||
margin: var(--webchat-spacingVerticalL) 0 0; | ||
} | ||
|
||
:global(.webchat-fluent) .pre-chat-message-activity__body img { | ||
border-radius: 4px; | ||
height: 64px; | ||
} | ||
|
||
:global(.webchat-fluent) .pre-chat-message-activity__toolbar { | ||
grid-area: toolbar; | ||
} |
35 changes: 35 additions & 0 deletions
35
packages/fluent-theme/src/components/preChatActivity/PreChatMessageActivity.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { hooks } from 'botframework-webchat-component'; | ||
import { type WebChatActivity } from 'botframework-webchat-core'; | ||
import React, { memo, useMemo } from 'react'; | ||
import { useStyles } from '../../styles/index.js'; | ||
import styles from './PreChatMessageActivity.module.css'; | ||
import StarterPromptsToolbar from './StarterPromptsToolbar.js'; | ||
|
||
type Props = Readonly<{ activity: WebChatActivity & { type: 'message' } }>; | ||
|
||
const { useRenderMarkdownAsHTML } = hooks; | ||
|
||
const PreChatMessageActivity = ({ activity }: Props) => { | ||
const classNames = useStyles(styles); | ||
const renderMarkdownAsHTML = useRenderMarkdownAsHTML(); | ||
|
||
const html = useMemo( | ||
() => (renderMarkdownAsHTML ? { __html: renderMarkdownAsHTML(activity.text || '') } : { __html: '' }), | ||
[activity.text, renderMarkdownAsHTML] | ||
); | ||
|
||
return ( | ||
<div className={classNames['pre-chat-message-activity']}> | ||
{/* eslint-disable-next-line react/no-danger */} | ||
<div className={classNames['pre-chat-message-activity__body']} dangerouslySetInnerHTML={html} /> | ||
<StarterPromptsToolbar | ||
cardActions={activity.suggestedActions?.actions || []} | ||
className={classNames['pre-chat-message-activity__toolbar']} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
PreChatMessageActivity.displayName = 'PreChatMessageActivity'; | ||
|
||
export default memo(PreChatMessageActivity); |
Oops, something went wrong.