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 widget snippet #2

Merged
merged 2 commits into from
Dec 27, 2023
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
8 changes: 7 additions & 1 deletion packages/chat-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ export const createConversation = (config: Config): ConversationHandler => {
newResponse,
);
} else {
console.warn(
"Invalid message structure, expected object with field 'messages'.",
);
failureHandler();
}
};
Expand Down Expand Up @@ -335,7 +338,10 @@ export const createConversation = (config: Config): ConversationHandler => {
)
.then((res: any) => res.json())
.then(messageResponseHandler)
.catch(failureHandler);
.catch((err) => {
console.warn(err);
failureHandler();
});
}
};

Expand Down
63 changes: 33 additions & 30 deletions packages/website/src/snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ convo.subscribe((responses, newResponse) => {
// Send a message to the bot
convo.sendText("Hello, I want to order a coffee");`;

const packageVersion = "0.0.5";

export const setupSnippet = ({
config,
titleBar,
Expand All @@ -65,7 +67,7 @@ export const setupSnippet = ({
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<script defer src="https://unpkg.com/@nlxai/chat-widget@0.1.0/lib/umd/index.js"></script>${
<script defer src="https://unpkg.com/@nlxai/chat-widget@${packageVersion}/lib/index.umd.js"></script>${
customModalitiesExample
? `
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/htm/3.1.1/htm.js" integrity="sha512-RilD4H0wcNNxG2GvB+L1LRXCntT0zgRvRLnmGu+e9wWaLKGkPifz3Ozb6+WPsyEkTBLw6zWCwwEjs9JLL1KIHg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>`
Expand Down Expand Up @@ -115,12 +117,12 @@ export const setupSnippet = ({
}
titleBar: ${indentBy(
" ",
JSON.stringify(titleBar, null, 2)
JSON.stringify(titleBar, null, 2),
)},${
behavior === Behavior.WelcomeIntentOnOpen
? indentBy(
" ",
`
behavior === Behavior.WelcomeIntentOnOpen
? indentBy(
" ",
`
// CUSTOM BEHAVIOR SNIPPET
onExpand: (conversationHandler) => {
const checkMessages = (messages) => {
Expand All @@ -131,41 +133,42 @@ onExpand: (conversationHandler) => {
}
conversationHandler.subscribe(checkMessages);
},
// CUSTOM BEHAVIOR SNIPPET END`
)
: behavior === Behavior.UseSessionStorage
? indentBy(
" ",
`
// CUSTOM BEHAVIOR SNIPPET END`,
)
: behavior === Behavior.UseSessionStorage
? indentBy(
" ",
`
// CUSTOM BEHAVIOR SNIPPET
storeIn: "sessionStorage",
// CUSTOM BEHAVIOR SNIPPET END`
)
: behavior === Behavior.UseLocalStorage
? indentBy(
" ",
`
// CUSTOM BEHAVIOR SNIPPET END`,
)
: behavior === Behavior.UseLocalStorage
? indentBy(
" ",
`
// CUSTOM BEHAVIOR SNIPPET
storeIn: "localStorage",
// CUSTOM BEHAVIOR SNIPPET END`
)
: ""
}${
theme
? ` theme: ${indentBy(
" ",
JSON.stringify(theme, null, 2)
)}`
: ""
}
// CUSTOM BEHAVIOR SNIPPET END`,
)
: ""
}
${
theme
? `theme: ${indentBy(
" ",
JSON.stringify(theme, null, 2),
)}`
: ""
}
});${
behavior === Behavior.CustomIntentOnInactivity
? indentBy(
" ",
`
// CUSTOM BEHAVIOR SNIPPET
${sendWelcomeOnTimeoutSnippet}
// CUSTOM BEHAVIOR SNIPPET END`
// CUSTOM BEHAVIOR SNIPPET END`,
)
: ""
}
Expand Down
Loading