|
| 1 | +export const basicBotMessage = ` |
| 2 | +const BasicMessage = () => { |
| 3 | + return ( |
| 4 | + <AIChatLog> |
| 5 | + <AIChatMessage variant="bot"> |
| 6 | + <AIChatMessageAuthor aria-label="AI said">Good Bot</AIChatMessageAuthor> |
| 7 | + <AIChatMessageBody> |
| 8 | + 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. |
| 9 | + </AIChatMessageBody> |
| 10 | + </AIChatMessage> |
| 11 | + </AIChatLog> |
| 12 | + ); |
| 13 | +}; |
| 14 | +
|
| 15 | +render( |
| 16 | + <BasicMessage /> |
| 17 | +)`.trim(); |
| 18 | +export const basicHumanMessage = ` |
| 19 | +const BasicMessage = () => { |
| 20 | + return ( |
| 21 | + <AIChatLog> |
| 22 | + <AIChatMessage variant="user"> |
| 23 | + <AIChatMessageAuthor aria-label="You said at 2:36pm">Gibby Radki</AIChatMessageAuthor> |
| 24 | + <AIChatMessageBody> |
| 25 | + I would like some information on twilio error codes for undelivered messages |
| 26 | + </AIChatMessageBody> |
| 27 | + </AIChatMessage> |
| 28 | + </AIChatLog> |
| 29 | + ); |
| 30 | +}; |
| 31 | +
|
| 32 | +render( |
| 33 | + <BasicMessage /> |
| 34 | +)`.trim(); |
| 35 | +export const botWithFeedback = ` |
| 36 | +const MessageWithFeedback = () => { |
| 37 | + return ( |
| 38 | + <AIChatLog> |
| 39 | + <AIChatMessage variant="bot"> |
| 40 | + <AIChatMessageAuthor aria-label="AI said">Good Bot</AIChatMessageAuthor> |
| 41 | + <AIChatMessageBody> |
| 42 | + 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. |
| 43 | + </AIChatMessageBody> |
| 44 | + <AIChatMessageActionGroup> |
| 45 | + <AIChatMessageActionCard aria-label="Feedback form"> |
| 46 | + Is this helpful? |
| 47 | + <Button variant="reset" size="reset" aria-label="this is a helpful response"> |
| 48 | + <ThumbsUpIcon decorative={false} title="like result" /> |
| 49 | + </Button> |
| 50 | + <Button variant="reset" size="reset"> |
| 51 | + <ThumbsDownIcon decorative={false} title="dislike result" aria-label="this is not a helpful response" /> |
| 52 | + </Button> |
| 53 | + </AIChatMessageActionCard> |
| 54 | + <AIChatMessageActionCard aria-label="Rewrite and copy buttons"> |
| 55 | + <Button variant="reset" size="reset"> |
| 56 | + <RefreshIcon decorative={true}/> Rewrite |
| 57 | + </Button> |
| 58 | + <Button variant="reset" size="reset"> |
| 59 | + <CopyIcon decorative={true}/> Copy |
| 60 | + </Button> |
| 61 | + </AIChatMessageActionCard> |
| 62 | + </AIChatMessageActionGroup> |
| 63 | + </AIChatMessage> |
| 64 | + </AIChatLog> |
| 65 | + ); |
| 66 | +}; |
| 67 | +
|
| 68 | +render( |
| 69 | + <MessageWithFeedback /> |
| 70 | +)`.trim(); |
| 71 | +export const botWithBodyActions = ` |
| 72 | +const MessageWithFeedback = () => { |
| 73 | + return ( |
| 74 | + <AIChatLog> |
| 75 | + <AIChatMessage variant="bot"> |
| 76 | + <AIChatMessageAuthor aria-label="AI said">Good Bot</AIChatMessageAuthor> |
| 77 | + <AIChatMessageBody> |
| 78 | + <Paragraph>Below is a list of actions that can be taken with flex wrapping supported:</Paragraph> |
| 79 | + <ButtonGroup> |
| 80 | + <Button variant="secondary" size="rounded_small" onClick={() => {}} > |
| 81 | + View Logs |
| 82 | + </Button> |
| 83 | + <Button variant="secondary" size="rounded_small" onClick={() => {}}> |
| 84 | + Run Diagnostics |
| 85 | + </Button> |
| 86 | + <Button variant="secondary" size="rounded_small" onClick={() => {}}> |
| 87 | + Submit Bug Report |
| 88 | + </Button> |
| 89 | + </ButtonGroup> |
| 90 | + </AIChatMessageBody> |
| 91 | + </AIChatMessage> |
| 92 | + </AIChatLog> |
| 93 | + ); |
| 94 | +}; |
| 95 | +
|
| 96 | +render( |
| 97 | + <MessageWithFeedback /> |
| 98 | +)`.trim(); |
| 99 | +export const botWithLoadingStopButton = ` |
| 100 | +const MessageWithLoadingAndStop = () => { |
| 101 | + return ( |
| 102 | + <AIChatLog> |
| 103 | + <AIChatMessage variant="bot"> |
| 104 | + <AIChatMessageAuthor aria-label="AI said" bot> |
| 105 | + Good Bot |
| 106 | + </AIChatMessageAuthor> |
| 107 | + <AIChatMessageBody> |
| 108 | + <AIChatMessageLoading onStopLoading={() => {}} /> |
| 109 | + </AIChatMessageBody> |
| 110 | + </AIChatMessage> |
| 111 | + </AIChatLog> |
| 112 | + ); |
| 113 | +}; |
| 114 | +
|
| 115 | +render( |
| 116 | + <MessageWithLoadingAndStop /> |
| 117 | +)`.trim(); |
| 118 | +export const botWithLoading = ` |
| 119 | +const MessageWithLoading = () => { |
| 120 | + return ( |
| 121 | + <AIChatLog> |
| 122 | + <AIChatMessage variant="bot"> |
| 123 | + <AIChatMessageAuthor aria-label="AI said" bot> |
| 124 | + Good Bot |
| 125 | + </AIChatMessageAuthor> |
| 126 | + <AIChatMessageBody> |
| 127 | + <AIChatMessageLoading /> |
| 128 | + </AIChatMessageBody> |
| 129 | + </AIChatMessage> |
| 130 | + </AIChatLog> |
| 131 | + ); |
| 132 | +}; |
| 133 | +
|
| 134 | +render( |
| 135 | + <MessageWithLoading /> |
| 136 | +)`.trim(); |
| 137 | +export const kitchenSink = ` |
| 138 | +const AIChatLogExample = () => { |
| 139 | + return ( |
| 140 | + <AIChatLog> |
| 141 | + <AIChatMessage variant="user"> |
| 142 | + <AIChatMessageAuthor aria-label="You said">Gibby Radki</AIChatMessageAuthor> |
| 143 | + <AIChatMessageBody> |
| 144 | + Hi, I'm getting errors codes when sending an SMS. |
| 145 | + </AIChatMessageBody> |
| 146 | + </AIChatMessage> |
| 147 | + <AIChatMessage variant="bot"> |
| 148 | + <AIChatMessageAuthor aria-label="AI said">Good Bot</AIChatMessageAuthor> |
| 149 | + <AIChatMessageBody> |
| 150 | + <Paragraph>Error codes can be returned from various parts of the process. What error codes are you encountering?</Paragragh> |
| 151 | + <ButtonGroup> |
| 152 | + <Button variant="secondary" size="rounded_small" onClick={() => {}} > |
| 153 | + 21608 |
| 154 | + </Button> |
| 155 | + <Button variant="secondary" size="rounded_small" onClick={() => {}}> |
| 156 | + 30007 |
| 157 | + </Button> |
| 158 | + <Button variant="secondary" size="rounded_small" onClick={() => {}}> |
| 159 | + 30009 |
| 160 | + </Button> |
| 161 | + </ButtonGroup> |
| 162 | + </AIChatMessageBody> |
| 163 | + </AIChatMessage> |
| 164 | + <AIChatMessage variant="bot"> |
| 165 | + <AIChatMessageAuthor aria-label="AI said">Good Bot</AIChatMessageAuthor> |
| 166 | + <AIChatMessageBody> |
| 167 | + Error 21608 means you're trying to send a message from an unverified number. Is your number verified in your Twilio account? |
| 168 | + </AIChatMessageBody> |
| 169 | + <AIChatMessageActionGroup> |
| 170 | + <AIChatMessageActionCard aria-label="Feedback form"> |
| 171 | + Is this helpful? |
| 172 | + <Button variant="reset" size="reset" aria-label="this is a helpful response"> |
| 173 | + <ThumbsUpIcon decorative={false} title="like result" /> |
| 174 | + </Button> |
| 175 | + <Button variant="reset" size="reset"> |
| 176 | + <ThumbsDownIcon decorative={false} title="dislike result" aria-label="this is not a helpful response"/> |
| 177 | + </Button> |
| 178 | + </AIChatMessageActionCard> |
| 179 | + </AIChatMessageActionGroup> |
| 180 | + </AIChatMessage> |
| 181 | + <AIChatMessage variant="user"> |
| 182 | + <AIChatMessageAuthor aria-label="You said" bot> |
| 183 | + Gibby Radki |
| 184 | + </AIChatMessageAuthor> |
| 185 | + <AIChatMessageBody> |
| 186 | + No, how do I verify it? |
| 187 | + </AIChatMessageBody> |
| 188 | + </AIChatMessage> |
| 189 | + <AIChatMessage variant="bot"> |
| 190 | + <AIChatMessageAuthor aria-label="AI said" bot> |
| 191 | + Good Bot |
| 192 | + </AIChatMessageAuthor> |
| 193 | + <AIChatMessageBody> |
| 194 | + <AIChatMessageLoading onStopLoading={() => {}} /> |
| 195 | + </AIChatMessageBody> |
| 196 | + </AIChatMessage> |
| 197 | + </AIChatLog> |
| 198 | + ); |
| 199 | +}; |
| 200 | +
|
| 201 | +render( |
| 202 | + <AIChatLogExample /> |
| 203 | +)`.trim(); |
| 204 | +export const aiChatLoggerExample = ` |
| 205 | +const aiChatFactory = ([ message, variant, metaLabel, meta ]) => { |
| 206 | + const time = new Date(0).toLocaleString( |
| 207 | + 'en-US', |
| 208 | + { hour: 'numeric', minute: 'numeric', timeZone: 'UTC', hour12: true } |
| 209 | + ) |
| 210 | +
|
| 211 | + return { |
| 212 | + variant, |
| 213 | + content: ( |
| 214 | + <AIChatMessage variant={variant}> |
| 215 | + <AIChatMessageAuthor aria-label={metaLabel + time}>{meta}</AIChatMessageAuthor> |
| 216 | + <AIChatMessageBody> |
| 217 | + {message} |
| 218 | + </AIChatMessageBody> |
| 219 | + </AIChatMessage> |
| 220 | + ) |
| 221 | + } |
| 222 | +}; |
| 223 | +
|
| 224 | +const chatTemplates = [ |
| 225 | + ["Hello", "user", "You said at ", "Gibby Radki"], |
| 226 | + ["Hi there", "bot", "AI said at ", "Good Bot"], |
| 227 | + ["Greetings", "user", "You said at ", "Gibby Radki"], |
| 228 | + ["Good to meet you", "bot", "AI said at ", "Good Bot"] |
| 229 | +]; |
| 230 | +
|
| 231 | +const AIChatLoggerExample = () => { |
| 232 | + const [templateIdx, setTemplateIdx] = React.useState(2); |
| 233 | + const { aiChats, push, pop, clear } = useAIChatLogger( |
| 234 | + aiChatFactory(chatTemplates[0]), |
| 235 | + aiChatFactory(chatTemplates[1]) |
| 236 | + ); |
| 237 | + const [loading, setLoading] = React.useState(false); |
| 238 | +
|
| 239 | + const pushChat = () => { |
| 240 | + const template = chatTemplates[templateIdx]; |
| 241 | + setTemplateIdx((idx) => ++idx % chatTemplates.length); |
| 242 | + const chat = aiChatFactory(template); |
| 243 | +
|
| 244 | + if (template[1] === "bot") { |
| 245 | + const id = uid(chat.content); |
| 246 | + setLoading(true); |
| 247 | + push({ |
| 248 | + id, |
| 249 | + variant: template[1], |
| 250 | + content: ( |
| 251 | + <AIChatMessage variant="bot"> |
| 252 | + <AIChatMessageAuthor aria-label="AI said">Good Bot</AIChatMessageAuthor> |
| 253 | + <AIChatMessageBody> |
| 254 | + <AIChatMessageLoading /> |
| 255 | + </AIChatMessageBody> |
| 256 | + </AIChatMessage> |
| 257 | + ), |
| 258 | + }); |
| 259 | + setTimeout(() => { |
| 260 | + pop(id); |
| 261 | + setLoading(false); |
| 262 | + push(chat); |
| 263 | + }, 1000); |
| 264 | + } else { |
| 265 | + push(chat); |
| 266 | + } |
| 267 | + } |
| 268 | +
|
| 269 | + const popChat = () => { |
| 270 | + pop(); |
| 271 | + setTemplateIdx((idx) => idx === 0 ? idx : --idx % chatTemplates.length); |
| 272 | + } |
| 273 | +
|
| 274 | + return( |
| 275 | + <Stack orientation="vertical"> |
| 276 | + <ButtonGroup> |
| 277 | + <Button variant="primary" disabled={loading} onClick={pushChat}> |
| 278 | + Push Chat |
| 279 | + </Button> |
| 280 | + <Button variant="primary" disabled={loading} onClick={popChat}> |
| 281 | + Pop Chat |
| 282 | + </Button> |
| 283 | + <Button variant="primary" disabled={loading} onClick={clear}> |
| 284 | + Clear Chat |
| 285 | + </Button> |
| 286 | + </ButtonGroup> |
| 287 | + <AIChatLogger aiChats={aiChats} /> |
| 288 | + </Stack> |
| 289 | + ) |
| 290 | +} |
| 291 | +
|
| 292 | +render(<AIChatLoggerExample />); |
| 293 | +`.trim(); |
| 294 | +export const avatarExample = ` |
| 295 | +const AvatarExample = () => { |
| 296 | + return ( |
| 297 | + <AIChatLog> |
| 298 | + <AIChatMessage variant="user"> |
| 299 | + <AIChatMessageAuthor avatarIcon={LogoTwilioIcon} aria-label="You said">Gibby Radki</AIChatMessageAuthor> |
| 300 | + </AIChatMessage> |
| 301 | + <AIChatMessage variant="user"> |
| 302 | + <AIChatMessageAuthor avatarSrc={Logo.src} aria-label="You said">Gibby Radki</AIChatMessageAuthor> |
| 303 | + </AIChatMessage> |
| 304 | + </AIChatLog> |
| 305 | + ); |
| 306 | +}; |
| 307 | +
|
| 308 | +render( |
| 309 | + <AvatarExample /> |
| 310 | +)`.trim(); |
0 commit comments