-
Notifications
You must be signed in to change notification settings - Fork 119
feat(ai-chat-log): Adding docs for new component #3963
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
Changes from 69 commits
b22cdd1
5c21b5b
6a8f9de
e4984c3
f51a267
e0fffdf
8437c06
b35952f
6fe0f56
bb64b73
a7d924f
5ee7cf4
925fd0a
9cb001a
2d941d0
9dcf2db
6e627ec
9da6bcf
6bdfff2
64b9cfd
b210d2c
0407ea3
ba59388
ab9835e
369cad7
2c6d0a2
173a752
90310f2
fe3e6bb
26de793
0f27f00
3f6fff4
b1b8bed
2da7c1a
86c31f3
2d05ede
954b8a8
9f64266
ccaa288
dcf1a75
3346998
3b07554
9baedf4
7584fde
c7c914e
dab49e1
5cfe884
f1b742c
53bae02
a670e5f
4d91f51
3b9fa3f
755d8d9
e61f918
3580d95
94a4000
de58ef1
3fb49a3
29f68f9
634fabe
732f39b
207c3fb
dede25f
a06a129
ce5e32b
107797f
5dd1810
69a5a15
c06291e
fbe0c69
deddcdd
9e7f85e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,302 @@ | ||
export const basicBotMessage = ` | ||
const BasicMessage = () => { | ||
return ( | ||
<AIChatLog> | ||
<AIChatMessage variant="bot"> | ||
<AIChatMessageAuthor aria-label="AI said">Good Bot</AIChatMessageAuthor> | ||
<AIChatMessageBody> | ||
Here is what I found, error code 30003 means: The destination phone is unavailable or turned off, or it may be a landline or phone that doesn't support SMS. | ||
</AIChatMessageBody> | ||
</AIChatMessage> | ||
</AIChatLog> | ||
); | ||
}; | ||
|
||
render( | ||
<BasicMessage /> | ||
)`.trim(); | ||
export const basicHumanMessage = ` | ||
const BasicMessage = () => { | ||
return ( | ||
<AIChatLog> | ||
<AIChatMessage variant="user"> | ||
<AIChatMessageAuthor aria-label="You said at 2:36pm">Gibby Radki</AIChatMessageAuthor> | ||
<AIChatMessageBody> | ||
I would like some information on twilio error codes for undelivered messages | ||
</AIChatMessageBody> | ||
</AIChatMessage> | ||
</AIChatLog> | ||
); | ||
}; | ||
|
||
render( | ||
<BasicMessage /> | ||
)`.trim(); | ||
export const botWithFeedback = ` | ||
const MessageWithFeedback = () => { | ||
return ( | ||
<AIChatLog> | ||
<AIChatMessage variant="bot"> | ||
<AIChatMessageAuthor aria-label="AI said">Good Bot</AIChatMessageAuthor> | ||
<AIChatMessageBody> | ||
Here is what I found, error code 30003 means: The destination phone is unavailable or turned off, or it may be a landline or phone that doesn't support SMS. | ||
</AIChatMessageBody> | ||
<AIChatMessageActionGroup aria-label="Feedback form"> | ||
<AIChatMessageActionCard> | ||
Is this helpful? | ||
<Button variant="reset" size="reset"> | ||
<ThumbsUpIcon decorative={false} title="like result" /> | ||
</Button> | ||
<Button variant="reset" size="reset"> | ||
<ThumbsDownIcon decorative={false} title="dislike result" /> | ||
</Button> | ||
</AIChatMessageActionCard> | ||
<AIChatMessageActionCard> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: I think I added some aria labels to the rewrite button and maybe also the thumbs up/down buttons in the stories - can you copy whatever I did there for the action card sections in these examples? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great catch. I will address this in the next commit |
||
<Button variant="reset" size="reset"> | ||
<RefreshIcon decorative={true}/> Rewrite | ||
</Button> | ||
<Button variant="reset" size="reset"> | ||
<CopyIcon decorative={true}/> Copy | ||
</Button> | ||
</AIChatMessageActionCard> | ||
</AIChatMessageActionGroup> | ||
</AIChatMessage> | ||
</AIChatLog> | ||
); | ||
}; | ||
|
||
render( | ||
<MessageWithFeedback /> | ||
)`.trim(); | ||
export const botWithBodyActions = ` | ||
const MessageWithFeedback = () => { | ||
return ( | ||
<AIChatLog> | ||
<AIChatMessage variant="bot"> | ||
<AIChatMessageAuthor aria-label="AI said">Good Bot</AIChatMessageAuthor> | ||
<AIChatMessageBody> | ||
Below is a list of actions that can be taken with flex wrapping supported: | ||
<ButtonGroup> | ||
<Button variant="secondary" size="rounded_small" onClick={() => {}} > | ||
View Logs | ||
</Button> | ||
<Button variant="secondary" size="rounded_small" onClick={() => {}}> | ||
Run Diagnostics | ||
</Button> | ||
<Button variant="secondary" size="rounded_small" onClick={() => {}}> | ||
Submit Bug Report | ||
</Button> | ||
<Button variant="secondary" size="rounded_small" onClick={() => {}}> | ||
Access Documentation | ||
</Button> | ||
<Button variant="secondary" size="rounded_small" onClick={() => {}}> | ||
Contact Support | ||
</Button> | ||
<Button variant="secondary" size="rounded_small" onClick={() => {}}> | ||
Enable Debug Mode | ||
</Button> | ||
</ButtonGroup> | ||
</AIChatMessageBody> | ||
</AIChatMessage> | ||
</AIChatLog> | ||
); | ||
}; | ||
|
||
render( | ||
<MessageWithFeedback /> | ||
)`.trim(); | ||
export const botWithLoadingStopButton = ` | ||
const MessageWithLoadingAndStop = () => { | ||
return ( | ||
<AIChatLog> | ||
<AIChatMessage variant="bot"> | ||
<AIChatMessageAuthor aria-label="AI said" bot> | ||
Good Bot | ||
</AIChatMessageAuthor> | ||
<AIChatMessageBody> | ||
<AIChatMessageLoading onStopLoading={() => {}} /> | ||
</AIChatMessageBody> | ||
</AIChatMessage> | ||
</AIChatLog> | ||
); | ||
}; | ||
|
||
render( | ||
<MessageWithLoadingAndStop /> | ||
)`.trim(); | ||
export const botWithLoading = ` | ||
const MessageWithLoading = () => { | ||
return ( | ||
<AIChatLog> | ||
<AIChatMessage variant="bot"> | ||
<AIChatMessageAuthor aria-label="AI said" bot> | ||
Good Bot | ||
</AIChatMessageAuthor> | ||
<AIChatMessageBody> | ||
<AIChatMessageLoading /> | ||
</AIChatMessageBody> | ||
</AIChatMessage> | ||
</AIChatLog> | ||
); | ||
}; | ||
|
||
render( | ||
<MessageWithLoading /> | ||
)`.trim(); | ||
export const kitchenSink = ` | ||
const AIChatLogExample = () => { | ||
return ( | ||
<AIChatLog> | ||
<AIChatMessage variant="user"> | ||
<AIChatMessageAuthor aria-label="You said">Gibby Radki</AIChatMessageAuthor> | ||
<AIChatMessageBody> | ||
Hi, I'm getting errors codes when sending an SMS. | ||
</AIChatMessageBody> | ||
</AIChatMessage> | ||
<AIChatMessage variant="bot"> | ||
<AIChatMessageAuthor aria-label="AI said">Good Bot</AIChatMessageAuthor> | ||
<AIChatMessageBody> | ||
Error codes can be returned from various parts of the process. What error codes are you encountering? | ||
<ButtonGroup> | ||
<Button variant="secondary" size="rounded_small" onClick={() => {}} > | ||
21608 | ||
</Button> | ||
<Button variant="secondary" size="rounded_small" onClick={() => {}}> | ||
30007 | ||
</Button> | ||
<Button variant="secondary" size="rounded_small" onClick={() => {}}> | ||
30009 | ||
</Button> | ||
</ButtonGroup> | ||
</AIChatMessageBody> | ||
</AIChatMessage> | ||
<AIChatMessage variant="bot"> | ||
<AIChatMessageAuthor aria-label="AI said">Good Bot</AIChatMessageAuthor> | ||
<AIChatMessageBody> | ||
Error 21608 means you're trying to send a message from an unverified number. Is your number verified in your Twilio account? | ||
</AIChatMessageBody> | ||
<AIChatMessageActionGroup aria-label="Feedback form"> | ||
<AIChatMessageActionCard> | ||
Is this helpful? | ||
<Button variant="reset" size="reset"> | ||
<ThumbsUpIcon decorative={false} title="like result" /> | ||
</Button> | ||
<Button variant="reset" size="reset"> | ||
<ThumbsDownIcon decorative={false} title="dislike result" /> | ||
</Button> | ||
</AIChatMessageActionCard> | ||
</AIChatMessageActionGroup> | ||
</AIChatMessage> | ||
<AIChatMessage variant="user"> | ||
<AIChatMessageAuthor aria-label="You said" bot> | ||
Gibby Radki | ||
</AIChatMessageAuthor> | ||
<AIChatMessageBody> | ||
No, how do I verify it? | ||
</AIChatMessageBody> | ||
</AIChatMessage> | ||
<AIChatMessage variant="bot"> | ||
<AIChatMessageAuthor aria-label="AI said" bot> | ||
Good Bot | ||
</AIChatMessageAuthor> | ||
<AIChatMessageBody> | ||
<AIChatMessageLoading onStopLoading={() => {}} /> | ||
</AIChatMessageBody> | ||
</AIChatMessage> | ||
</AIChatLog> | ||
); | ||
}; | ||
|
||
render( | ||
<AIChatLogExample /> | ||
)`.trim(); | ||
export const aiChatLoggerExample = ` | ||
const aiChatFactory = ([ message, variant, metaLabel, meta ]) => { | ||
const time = new Date(0).toLocaleString( | ||
'en-US', | ||
{ hour: 'numeric', minute: 'numeric', timeZone: 'UTC', hour12: true } | ||
) | ||
|
||
return { | ||
variant, | ||
content: ( | ||
<AIChatMessage variant={variant}> | ||
<AIChatMessageAuthor aria-label={metaLabel + time}>{meta}</AIChatMessageAuthor> | ||
<AIChatMessageBody> | ||
{message} | ||
</AIChatMessageBody> | ||
</AIChatMessage> | ||
) | ||
} | ||
}; | ||
|
||
const chatTemplates = [ | ||
["Hello", "user", "You said at ", "Gibby Radki"], | ||
["Hi there", "bot", "AI said at ", "Good Bot"], | ||
["Greetings", "user", "You said at ", "Gibby Radki"], | ||
["Good to meet you", "bot", "AI said at ", "Good Bot"] | ||
]; | ||
|
||
const AIChatLoggerExample = () => { | ||
const [templateIdx, setTemplateIdx] = React.useState(2); | ||
const { aiChats, push, pop, clear } = useAIChatLogger( | ||
aiChatFactory(chatTemplates[0]), | ||
aiChatFactory(chatTemplates[1]) | ||
); | ||
const [loading, setLoading] = React.useState(false); | ||
|
||
const pushChat = () => { | ||
const template = chatTemplates[templateIdx]; | ||
setTemplateIdx((idx) => ++idx % chatTemplates.length); | ||
const chat = aiChatFactory(template); | ||
|
||
if (template[1] === "bot") { | ||
const id = uid(chat.content); | ||
setLoading(true); | ||
push({ | ||
id, | ||
variant: template[1], | ||
content: ( | ||
<AIChatMessage variant="bot"> | ||
<AIChatMessageAuthor aria-label="AI said">Good Bot</AIChatMessageAuthor> | ||
<AIChatMessageBody> | ||
<AIChatMessageLoading /> | ||
</AIChatMessageBody> | ||
</AIChatMessage> | ||
), | ||
}); | ||
setTimeout(() => { | ||
pop(id); | ||
setLoading(false); | ||
push(chat); | ||
}, 1000); | ||
} else { | ||
push(chat); | ||
} | ||
} | ||
|
||
const popChat = () => { | ||
pop(); | ||
setTemplateIdx((idx) => idx === 0 ? idx : --idx % chatTemplates.length); | ||
} | ||
|
||
return( | ||
<Stack orientation="vertical"> | ||
<ButtonGroup> | ||
<Button variant="primary" disabled={loading} onClick={pushChat}> | ||
Push Chat | ||
</Button> | ||
<Button variant="primary" disabled={loading} onClick={popChat}> | ||
Pop Chat | ||
</Button> | ||
<Button variant="primary" disabled={loading} onClick={clear}> | ||
Clear Chat | ||
</Button> | ||
</ButtonGroup> | ||
<AIChatLogger aiChats={aiChats} /> | ||
</Stack> | ||
) | ||
} | ||
|
||
render(<AIChatLoggerExample />); | ||
`.trim(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
niceeee