Skip to content

Commit

Permalink
prettify
Browse files Browse the repository at this point in the history
  • Loading branch information
kwinto committed Sep 26, 2024
1 parent 3919118 commit 4db2e9a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
10 changes: 8 additions & 2 deletions src/common/ActionButtons/ActionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@ const ActionButton: FC<ActionButtonProps> = props => {
} = props;

const buttonType =
"type" in button ? button.type : "content_type" in button ? button.content_type : "contentType" in button ? (button as any).contentType : null;

"type" in button
? button.type
: "content_type" in button
? button.content_type
: "contentType" in button
? (button as any).contentType
: null;

if (!buttonType) return null;

const buttonLabel = getWebchatButtonLabel(button) || "";
Expand Down
2 changes: 1 addition & 1 deletion src/common/ActionButtons/ActionButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useRandomId } from "src/messages/hooks";

type buttonPayloadCompatibility = {
contentType?: string;
}
};

export interface ActionButtonsProps {
className?: string;
Expand Down
6 changes: 3 additions & 3 deletions src/matcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ const defaultConfig: MatchConfig[] = [
const isTextWithButtons =
(channelConfig?.message?.attachment as IWebchatTemplateAttachment)?.payload
?.template_type === "button";
const hasMessengerText = channelConfig?.message?.text;

const hasMessengerText = channelConfig?.message?.text;

const isDefaultPreviewEnabled = config?.settings?.widgetSettings?.enableDefaultPreview;
const hasDefaultPreview = message?.data?._cognigy?._defaultPreview;
// DefaultPreview chooses text over _webchat / _facebook content
const shouldSkip = isDefaultPreviewEnabled && !hasDefaultPreview && message.text
const shouldSkip = isDefaultPreviewEnabled && !hasDefaultPreview && message.text;

return !shouldSkip && (isQuickReplies || isTextWithButtons || hasMessengerText);
},
Expand Down
32 changes: 16 additions & 16 deletions test/demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const action: MessageSender = (text, data) =>
alert("Text: " + JSON.stringify(text, null, 2) + " Data: " + JSON.stringify(data, null, 2));

type DeepPartial<T> = {
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
};

type TScreen = {
Expand Down Expand Up @@ -74,36 +74,36 @@ const screens: TScreen[] = [
config: {
settings: {
widgetSettings: {
enableDefaultPreview: true
}
}
}
enableDefaultPreview: true,
},
},
},
},
{
message: {
data: {
_cognigy: {
_webchat: {
message: {
text: "RENDER WRONG"
}
text: "RENDER WRONG",
},
},
_defaultPreview: {
message: {
text: "RENDER OK"
}
text: "RENDER OK",
},
},
}
}
},
},
},
config: {
settings: {
widgetSettings: {
enableDefaultPreview: true
}
}
}
}
enableDefaultPreview: true,
},
},
},
},
],
},
{
Expand Down

0 comments on commit 4db2e9a

Please sign in to comment.