Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Adaptive card rendering issue in Webchat & Rerender on appId change #8238

Merged
merged 3 commits into from
Jul 1, 2021
Merged
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import React from 'react';
import { createStyleSet, Components } from 'botframework-webchat-component';
import { createStyleSet, Components } from 'botframework-webchat';
import { CommunicationColors, NeutralColors } from '@uifabric/fluent-theme';

import { ConversationService } from './utils/conversationService';
Expand Down
12 changes: 6 additions & 6 deletions Composer/packages/client/src/components/WebChat/WebChatPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { dispatcherState } from '../../recoilModel';
import { ConversationService } from './utils/conversationService';
import { WebChatHeader } from './WebChatHeader';
import { WebChatComposer } from './WebChatComposer';
import { BotSecrets, ChatData, RestartOption } from './types';
import { BotSecret, ChatData, RestartOption } from './types';

const BASEPATH = process.env.PUBLIC_URL || 'http://localhost:3000/';
// TODO: Refactor to include Webchat header component as a part of WebchatComposer to avoid this variable.
Expand All @@ -30,7 +30,7 @@ export interface WebChatPanelProps {
botData: {
projectId: string;
botUrl: string;
secrets: BotSecrets;
secret: BotSecret;
botName: string;
activeLocale: string;
botStatus: BotStatus;
Expand All @@ -53,7 +53,7 @@ export const WebChatPanel: React.FC<WebChatPanelProps> = ({
setActiveTabInDebugPanel,
setWebChatPanelVisibility,
} = useRecoilValue(dispatcherState);
const { projectId, botUrl, secrets, botName, activeLocale, botStatus } = botData;
const { projectId, botUrl, secret, botName, activeLocale, botStatus } = botData;
const [chats, setChatData] = useState<Record<string, ChatData>>({});
const [currentConversation, setCurrentConversation] = useState<string>('');
const [currentRestartOption, onSetRestartOption] = useState<RestartOption>(RestartOption.NewUserID);
Expand Down Expand Up @@ -134,7 +134,7 @@ export const WebChatPanel: React.FC<WebChatPanelProps> = ({
if (botUrl) {
setCurrentConversation('');
}
}, [botUrl]);
}, [botUrl, secret]);

useEffect(() => {
setIsRestartButtonDisabled(botStatus !== BotStatus.connected);
Expand All @@ -161,7 +161,7 @@ export const WebChatPanel: React.FC<WebChatPanelProps> = ({
const startConversation = async () => {
const chatData: ChatData = await conversationService.startNewConversation(
botUrl,
secrets,
secret,
projectId,
activeLocale
);
Expand Down Expand Up @@ -191,7 +191,7 @@ export const WebChatPanel: React.FC<WebChatPanelProps> = ({
oldChatData,
requireNewUserId,
activeLocale,
secrets
secret
);

TelemetryClient.track('WebChatConversationRestarted', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('<WebchatPanel />', () => {
botData: {
projectId: '123-12',
botUrl: 'http://localhost:3989/api/messages',
secrets: {
secret: {
msAppId: '',
msPassword: '',
},
Expand Down
2 changes: 1 addition & 1 deletion Composer/packages/client/src/components/WebChat/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type User = {
role: string;
};

export type BotSecrets = { msAppId: string; msPassword: string };
export type BotSecret = { msAppId: string; msPassword: string };
export type ChannelService = 'public' | 'usgov';

export type WebChatMode = 'livechat' | 'transcript';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ declare module 'botframework-webchat' {
export const renderWebChat: any;
export const createDirectLine: (options: any) => any;
export const hooks: any;
export const createStyleSet: any;
export const Components: {
AdaptiveCardContent: any;
AudioCardContent: any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { createDirectLine } from 'botframework-webchat';
import moment from 'moment';
import formatMessage from 'format-message';

import { BotSecrets, WebChatMode, User, ChatData, StartConversationPayload } from '../types';
import { BotSecret, WebChatMode, User, ChatData, StartConversationPayload } from '../types';

export const getDateTimeFormatted = (): string => {
return moment().local().format('YYYY-MM-DD HH:mm:ss');
Expand Down Expand Up @@ -36,7 +36,7 @@ export class ConversationService {
newConversationId: string,
userId: string,
activeLocale: string,
secrets: BotSecrets
secret: BotSecret
) {
const url = `${this.directlineHostUrl}/conversations/${oldConversationId}/updateConversation`;
return axios.put(
Expand All @@ -45,8 +45,8 @@ export class ConversationService {
conversationId: newConversationId,
userId,
locale: activeLocale,
msaAppId: secrets.msAppId,
msaPassword: secrets.msPassword,
msaAppId: secret.msAppId,
msaPassword: secret.msPassword,
},
{
headers: {
Expand Down Expand Up @@ -105,7 +105,7 @@ export class ConversationService {

public async startNewConversation(
botUrl: string,
secrets: BotSecrets,
secret: BotSecret,
projectId: string,
activeLocale: string
): Promise<ChatData> {
Expand All @@ -117,8 +117,8 @@ export class ConversationService {
channelServiceType: 'public',
members: [user],
mode: webChatMode,
msaAppId: secrets.msAppId,
msaPassword: secrets.msPassword,
msaAppId: secret.msAppId,
msaPassword: secret.msPassword,
locale: activeLocale,
});

Expand All @@ -134,7 +134,7 @@ export class ConversationService {
const webChatStore: unknown = createWebChatStore({});
return {
directline,
webChatMode: webChatMode,
webChatMode,
projectId,
user,
conversationId,
Expand All @@ -146,7 +146,7 @@ export class ConversationService {
oldChatData: ChatData,
requireNewUserID: boolean,
activeLocale: string,
secrets: BotSecrets
secret: BotSecret
) {
if (oldChatData.directline) {
oldChatData.directline.end();
Expand All @@ -164,7 +164,7 @@ export class ConversationService {
conversationId,
user.id,
activeLocale,
secrets
secret
);
const { endpointId } = resp.data;
const directline = await this.fetchDirectLineObject(conversationId, {
Expand Down
6 changes: 3 additions & 3 deletions Composer/packages/client/src/recoilModel/selectors/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export type TreeDataPerProject = {
type WebChatEssentials = {
projectId: string;
botName: string;
secrets: { msAppId: string; msPassword: string };
secret: { msAppId: string; msPassword: string };
botUrl: string;
activeLocale: string;
botStatus: BotStatus;
Expand Down Expand Up @@ -371,7 +371,7 @@ export const webChatEssentialsSelector = selectorFamily<WebChatEssentials, strin
key: 'webChatEssentialsSelector',
get: (projectId: string) => ({ get }) => {
const settings = get(settingsState(projectId));
const secrets = {
const secret = {
msAppId: settings.MicrosoftAppId || '',
msPassword: settings.MicrosoftAppPassword || '',
};
Expand All @@ -384,7 +384,7 @@ export const webChatEssentialsSelector = selectorFamily<WebChatEssentials, strin
return {
projectId,
botName,
secrets,
secret: secret,
botUrl,
activeLocale,
botStatus,
Expand Down
1 change: 0 additions & 1 deletion Composer/packages/client/src/utils/luUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export function getReferredLuFiles(luFiles: LuFile[], dialogs: DialogInfo[], che
return luFiles.filter((file) => {
const idWithoutLocale = getBaseName(file.id);
const contentNotEmpty = (checkContent && !!file.content) || !checkContent;
console.log('Content', dialogs);
return dialogs.some((dialog) => dialog.luFile === idWithoutLocale && contentNotEmpty);
});
}
Expand Down