Skip to content

Commit

Permalink
Fix start behavior after accepting privacy policy
Browse files Browse the repository at this point in the history
  • Loading branch information
sushmi21 committed Jul 10, 2024
1 parent 23c4553 commit 8a91b2a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
12 changes: 12 additions & 0 deletions src/webchat-ui/components/WebchatUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,18 @@ export class WebchatUI extends React.PureComponent<
.slice(index + 1)
.some(message => message.source === "user");

// Find message with control command 'acceptPrivacyPolicy' and remove it. This message type need not be passed to the Message component.
// If we do not filter this message, it will cause the collatation of the first user message.
if ((message.data?._cognigy as any)?.controlCommands) {
const controlCommands = (message.data?._cognigy as any)?.controlCommands;
const acceptPrivacyPolicyIndex = controlCommands.findIndex(
command => command.type === "acceptPrivacyPolicy"
);
if (acceptPrivacyPolicyIndex > -1) {
messages.splice(index, 1);
}
}

return (
<Message
key={JSON.stringify({ message, index })}
Expand Down
13 changes: 7 additions & 6 deletions src/webchat/store/autoinject/autoinject-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,17 @@ export const createAutoInjectMiddleware = (webchat: Webchat): Middleware<unknown
// Don't trigger the auto inject message when the history is not empty
// except if explicitly set via enableAutoInjectWithHistory
if (!config.settings.widgetSettings.enableInjectionWithoutEmptyHistory) {
const isEmptyExceptEngagementMesage = state.messages
.filter(message => message.source !== 'engagement')
.length === 0;

if (!isEmptyExceptEngagementMesage) {
// Exclude engagement messages from state.messages
const messagesExcludeEngagementMessages = state.messages.filter(message => message.source !== 'engagement');
// Exclude privacy policy accepted message type from filtered message list
const messagesExcludingEngagementAndPrivacyMessage = messagesExcludeEngagementMessages.filter(message => (message.data?._cognigy as any)?.controlCommands === 'acceptPrivacyPolicy');
const isEmptyExceptEngagementAndPrivacyMessage = messagesExcludingEngagementAndPrivacyMessage.length === 0;

if (!isEmptyExceptEngagementAndPrivacyMessage) {
break;
}
}


// We are going to send the auto-inject message, now!
const text = state.config.settings.startBehavior.getStartedPayload;
const data = state.config.settings.startBehavior.getStartedData;
Expand Down

0 comments on commit 8a91b2a

Please sign in to comment.