0.0.51 β€’ Published 5 months ago

@cloudtrain/chatbot v0.0.51

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

CloudTrain Chatbot

The CloudTrain Chatbot is a customizable web component that enables seamless chatbot integration into your website or application.
Users must create an AI model on CloudTrain AI and generate an API key to use this component.


πŸš€ Features

  • AI chatbot web component.
  • Fully customizable chatbot suggestions.
  • Pass custom meta data to the AI model.
  • Responsive and lightweight.

πŸ“– Getting Started

1️⃣ Include the Component

Add the component to your HTML by including the following scripts:

<script type="module" src="https://cdn.jsdelivr.net/npm/@cloudtrain/chatbot@latest/dist/cloudtrain-chatbot/cloudtrain-chatbot.esm.js"></script>
<script nomodule src="https://cdn.jsdelivr.net/npm/@cloudtrain/chatbot@latest/dist/cloudtrain-chatbot/cloudtrain-chatbot.js"></script>

2️⃣ Usage

Add the <cloudtrain-chatbot> tag to your HTML file and pass your API key as an attribute:

<cloudtrain-chatbot api-key="YOUR_API_KEY_HERE"></cloudtrain-chatbot>

Replace YOUR_API_KEY_HERE with the API key generated at CloudTrain AI.


3️⃣ Adding Chat Suggestions

To add chat suggestions dynamically, use the chatSuggestions property:

<script>
  document.querySelector('cloudtrain-chatbot').chatSuggestions = [
    'How can I help you?',
    'Tell me more about your issue.',
    'What can I assist you with today?'
  ];
</script>

4️⃣ Passing Custom Meta Data

You can optionally pass a custom meta object to the chatbot. This object is forwarded to the AI model and can help personalize or contextualize responses.

<script>
  document.querySelector('cloudtrain-chatbot').meta = {
    name: "John"
  };
</script>

Example usage:

<script>
  const chatbot = document.querySelector('cloudtrain-chatbot');
  chatbot.meta = {
    name: "Alice",
    userRole: "admin",
    sessionId: "abc123"
  };
</script>

🌟 Example Integration

Here’s a full example of the chatbot integrated into an HTML page:

<!DOCTYPE html>
<html dir="ltr" lang="en">

<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0" />
  <title>CloudTrain Chatbot</title>

  <script type="module" src="https://cdn.jsdelivr.net/npm/@cloudtrain/chatbot@latest/dist/cloudtrain-chatbot/cloudtrain-chatbot.esm.js"></script>
  <script nomodule src="https://cdn.jsdelivr.net/npm/@cloudtrain/chatbot@latest/dist/cloudtrain-chatbot/cloudtrain-chatbot.js"></script>
</head>

<body>
  <!-- Chatbot Component -->
  <cloudtrain-chatbot api-key="2|SwQBlgdQZ2yYOTBxplQVlMIStfWNFJ7UYCTUlGSM896a1f55"></cloudtrain-chatbot>

  <!-- Customize Behavior -->
  <script>
    const chatbot = document.querySelector('cloudtrain-chatbot');

    chatbot.chatSuggestions = [
      'Suggestion 1',
      'Suggestion 2'
    ];

    chatbot.meta = {
      name: "Alice",
      userRole: "admin",
    };
  </script>
</body>

</html>

πŸ“Œ API Reference

πŸ”Ή Attributes

AttributeTypeRequiredDescription
api-keyStringβœ… YesThe API key generated on CloudTrain AI.
theme"light" | "dark" | "system" | undefined❌ NoSets the chatbot theme. Defaults to system preference if undefined.

πŸ”Ή Properties

PropertyTypeDescription
chatSuggestionsArrayAn array of strings used as chatbot prompts.
metaObjectOptional. A custom object sent to the AI model for context.

πŸ”‘ How to Generate API Key

  1. Go to CloudTrain AI.
  2. Create an AI model for your chatbot.
  3. Generate an API key for the model.
  4. Use the API key in the api-key attribute of the <cloudtrain-chatbot> tag.

🎨 Customizing Colors

You can override the default theme colors used by the chatbot using CSS variables.
Define your custom values directly on cloudtrain-chatbot or at the :root level.

Example: Override Foreground Color

cloudtrain-chatbot, :root {
  --cloudtrain-foreground: 0, 100%, 50%;
}

cloudtrain-chatbot[data-theme='dark'] {
  --cloudtrain-foreground: 120, 100%, 50%;
}

List of Supported CSS Variables

You can override the following variables to customize the chatbot's appearance:

  • --cloudtrain-background
  • --cloudtrain-foreground
  • --cloudtrain-border
  • --cloudtrain-primary
  • --cloudtrain-primary-foreground
  • --cloudtrain-input
  • --cloudtrain-muted-foreground
  • --cloudtrain-ring
  • --cloudtrain-accent
  • --cloudtrain-accent-foreground
  • --cloudtrain-message-icon

πŸ“œ License

This project is licensed under the MIT License.


πŸ’‘ Need help? Contact support at CloudTrain AI. πŸš€


0.0.51

5 months ago

0.0.50

5 months ago

0.0.49

5 months ago

0.0.48

5 months ago

0.0.47

5 months ago

0.0.46

5 months ago

0.0.45

5 months ago

0.0.44

5 months ago

0.0.43

5 months ago

0.0.42

5 months ago

0.0.41

5 months ago

0.0.40

5 months ago

0.0.39

5 months ago

0.0.38

5 months ago

0.0.37

5 months ago

0.0.36

5 months ago

0.0.35

5 months ago

0.0.34

7 months ago

0.0.33

8 months ago

0.0.32

8 months ago

0.0.31

8 months ago

0.0.30

8 months ago

0.0.29

8 months ago

0.0.28

8 months ago

0.0.27

8 months ago

0.0.26

8 months ago

0.0.25

8 months ago

0.0.24

8 months ago

0.0.23

8 months ago

0.0.22

8 months ago

0.0.21

8 months ago

0.0.20

8 months ago

0.0.19

8 months ago

0.0.18

8 months ago

0.0.17

8 months ago

0.0.16

8 months ago

0.0.15

8 months ago

0.0.14

8 months ago

0.0.13

8 months ago

0.0.12

8 months ago

0.0.11

8 months ago

0.0.10

8 months ago

0.0.9

8 months ago

0.0.8

8 months ago

0.0.7

8 months ago

0.0.6

8 months ago

0.0.5

8 months ago

0.0.4

8 months ago

0.0.3

8 months ago

0.0.2

9 months ago

0.0.1

9 months ago