From 7919dbc12566193d909d2adb4bb4c933db60f3a6 Mon Sep 17 00:00:00 2001
From: OvidijusParsiunas Set this to true or define an object with properties to remove the initial setup guidance message. demo
",id:"demo",level:3},{value:"Base Example",id:"base-example",level:4},{value:"Custom Response Example",id:"custom-response-example",level:4},{value:"Types",id:"types",level:2},{value:"DemoErrors
",id:"DemoErrors",level:3},{value:"DemoLoading
",id:"DemoLoading",level:3}];function j(e){const s={a:"a",code:"code",em:"em",h1:"h1",h2:"h2",h3:"h3",h4:"h4",header:"header",li:"li",p:"p",pre:"pre",ul:"ul",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(s.header,{children:(0,r.jsx)(s.h1,{id:"demo",children:"Demo"})}),"\n",(0,r.jsx)(s.p,{children:"This is used by default to demonstrate the component's capabilities without connecting to any APIs."}),"\n",(0,r.jsx)(s.h3,{id:"demo",children:(0,r.jsx)(s.code,{children:"demo"})}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:["Type: ",(0,r.jsx)(s.code,{children:"true"})," | { ",(0,r.jsx)("br",{}),"\n\xa0\xa0\xa0\xa0 ",(0,r.jsx)(s.code,{children:"response?:"})," ",(0,r.jsx)(s.a,{href:"/docs/connect#Response",children:(0,r.jsx)(s.code,{children:"Response"})})," | (",(0,r.jsx)(s.a,{href:"/docs/messages/#MessageContent",children:(0,r.jsx)(s.code,{children:"message: MessageContent"})}),") => ",(0,r.jsx)(s.a,{href:"/docs/connect#Response",children:(0,r.jsx)(s.code,{children:"Response"})}),", ",(0,r.jsx)("br",{}),"\n\xa0\xa0\xa0\xa0 ",(0,r.jsx)(s.a,{href:"#DisplayErrors",children:(0,r.jsx)(s.code,{children:"displayErrors?: DisplayErrors"})}),", ",(0,r.jsx)("br",{}),"\n\xa0\xa0\xa0\xa0 ",(0,r.jsx)(s.a,{href:"#DemoLoading",children:(0,r.jsx)(s.code,{children:"displayLoading?: DemoLoading"})}),", ",(0,r.jsx)("br",{}),"\n\xa0\xa0\xa0\xa0 ",(0,r.jsx)(s.code,{children:"displayFileAttachmentContainer?: boolean"})," ",(0,r.jsx)("br",{}),"\n}}"]}),"\n"]}),"\n",(0,r.jsxs)(s.p,{children:["Set this to ",(0,r.jsx)(s.em,{children:"true"})," or define an object with properties to remove the initial setup guidance message. ",(0,r.jsx)("br",{}),"\n",(0,r.jsx)(s.code,{children:"response"})," is used to override the default demo response with a custom one. It can either be a ",(0,r.jsx)(s.a,{href:"/docs/connect#Response",children:(0,r.jsx)(s.code,{children:"Response"})})," object or a function that returns\na ",(0,r.jsx)(s.a,{href:"/docs/connect#Response",children:(0,r.jsx)(s.code,{children:"Response"})})," object. ",(0,r.jsx)("br",{}),"\nThe following properties are used to toggle elements to showcase their design without making any user actions: ",(0,r.jsx)("br",{}),"\n",(0,r.jsx)(s.code,{children:"displayErrors"})," is used to display error messages. ",(0,r.jsx)("br",{}),"\n",(0,r.jsx)(s.code,{children:"displayLoading"})," is used to display various loading spinners. ",(0,r.jsx)("br",{}),"\n",(0,r.jsx)(s.code,{children:"displayFileAttachmentContainer"})," is used to display the element that encapsulates all of the files to be sent on the next message. ",(0,r.jsx)("br",{})]}),"\n","\n",(0,r.jsx)(l.A,{children:()=>n(61886).readdAutoNavShadowToggle()}),"\n",(0,r.jsx)(s.h4,{id:"base-example",children:"Base Example"}),"\n",(0,r.jsx)(t.A,{children:(0,r.jsx)(a.A,{style:{borderRadius:"8px"},demo:!0})}),"\n",(0,r.jsxs)(d.A,{children:[(0,r.jsx)(c.A,{value:"js",label:"Sample code",children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-html",children:'demo
true
| {
response?:
Response
| (message: MessageContent
) => Response
,
- displayLoadingBubble?: boolean
,
- displayFileAttachmentContainer?: boolean
,
- displayErrors?: {
- default?: boolean
,
- service?: boolean
,
- speechToText?: boolean
+ displayErrors?: DisplayErrors
,
+ displayLoading?: DemoLoading
,
+ displayFileAttachmentContainer?: boolean
}}
response
is used to override the default demo response with a custom one. It can either be a Response
object or a function that returns
a Response
object.
The following properties are used to toggle elements to showcase their design without making any user actions:
-displayLoadingBubble
is used to display the loading bubble.
-displayFileAttachmentContainer
is used to display the element that encapsulates all of the files to be sent on the next message.
-displayErrors
is used to display error messages; for the component via default
, an API error via service
and a speech to text issue via speechToText
.
-This is mainly used to showcase the override capabilities in errorMessages
. displayErrors
is used to display error messages.
+displayLoading
is used to display various loading spinners.
+displayFileAttachmentContainer
is used to display the element that encapsulates all of the files to be sent on the next message.
chatElementRef.demo = {
response: (message) => {
const options = ['rock', 'paper', 'scissors'];
const userOption = message.text?.toLocaleLowerCase();
const aiOption = options[Math.floor(Math.random() * 3)];
let response = `I guessed ${aiOption}. `;
if (userOption === aiOption) response += 'Draw';
else if (userOption === 'rock') response += aiOption === 'paper' ? 'I win!' : 'You win!';
else if (userOption === 'paper') response += aiOption === 'scissors' ? 'I win!' : 'You win!';
else if (userOption === 'scissors') response += aiOption === 'rock' ? 'I win!' : 'You win!';
else response = 'Guess either Rock, Paper or Scissors';
return {text: response};
},
};
<!-- This example is for Vanilla JS and should be tailored to your framework (see Examples) -->
<deep-chat
id="chat-element"
introMessage='{"text": "Rock, Paper, Scissors! Make your guess and see who wins!"}'
style="border-radius: 8px"
></deep-chat>
<script>
// ...other code
const chatElementRef = document.getElementById('chat-element');
chatElementRef.demo = {
response: (message) => {
const options = ['rock', 'paper', 'scissors'];
const userOption = message.text?.toLocaleLowerCase();
const aiOption = options[Math.floor(Math.random() * 3)];
let response = `I guessed ${aiOption}. `;
if (userOption === aiOption) response += 'Draw';
else if (userOption === 'rock') response += aiOption === 'paper' ? 'I win!' : 'You win!';
else if (userOption === 'paper') response += aiOption === 'scissors' ? 'I win!' : 'You win!';
else if (userOption === 'scissors') response += aiOption === 'rock' ? 'I win!' : 'You win!';
else response = 'Guess either Rock, Paper or Scissors';
return {text: response};
},
};
DemoErrors
default?: boolean
, service?: boolean
, speechToText?: boolean
}Display various error messages. This is mainly used to showcase the override capabilities in errorMessages
.
+default
displays a default component error.
+service
is an API error.
+speechToText
is a speech to text issue error.
<deep-chat demo='{"displayErrors": {"service": true}}'></deep-chat>
<!-- This example is for Vanilla JS and should be tailored to your framework (see Examples) -->
<deep-chat demo='{"displayErrors": {"service": true}}' style="border-radius: 8px"></deep-chat>
DemoLoading
message?: boolean
, history?:
{full?: boolean
, small?: boolean
} Display various loading spinners.
+message
is a loading spinner inside a message bubble.
+history
is a loading spinner that is displayed when messages are being loading via loadHistory
.
+full
is a spinner that covers the entire chat message window on the initial load. small
is displayed when there are messages
+already present inside the chat. If full
is set to true and messages are added, the chat will automatically display the small
+spinner.
<deep-chat
demo='{
"displayLoadingBubble": true,
"displayFileAttachmentContainer": true,
"displayErrors": {"service": true}
}'
></deep-chat>
<!-- This example is for Vanilla JS and should be tailored to your framework (see Examples) -->
<deep-chat
demo='{
"displayLoadingBubble": true,
"displayFileAttachmentContainer": true,
"displayErrors": {"service": true}
}'
style="border-radius: 8px"
></deep-chat>
<deep-chat demo='{"displayLoading": {"message": true, "history": {"small": true}}}'></deep-chat>
<!-- This example is for Vanilla JS and should be tailored to your framework (see Examples) -->
<deep-chat demo='{"displayLoading": {"message": true, "history": {"small": true}}}' style="border-radius: 8px"></deep-chat>