Getting Started with the KendoReact Conversational UI

This guide provides essential information about using the KendoReact Conversational UI package and Chat componentyou will learn how to install the Conversational UI package, add a Chat component to your project, style the component, and activate your license.


After completing this guide, you will be able to reproduce the following example.

Example
View Source
Edit In Stackblitz  
Change Theme:

Setting Up Your React Project

Before you install the KendoReact Conversational UI, make sure that you have a running React project. The easiest way to set up a React project is to use the Create React App approach that is described in the Get Started with KendoReact article.

Using the Chat Component

To use Chat component:

  1. Install the Conversational UI package in your project.

  2. Import the Chat component in the current application module.

  3. Add the required entities for the Chat.

  4. Set and update the Chat messages.

  5. Add the component to your markup.

  6. Add the KendoReact CSS styles.

  7. Run the application.

Installing the Conversational UI Package

Install the package and its dependencies. Use Node.js v5.0.0 or later.

npm install --save @progress/kendo-react-conversational-ui @progress/kendo-react-buttons @progress/kendo-react-intl @progress/kendo-licensing

Importing the Component

In the src/App.js file of your React project, import Chat, ChatMessageSendEvent, and Message from the Conversational UI package.

// ES2015 module syntax
import { Chat, ChatMessageSendEvent, Message } from "@progress/kendo-react-conversational-ui";
// CommonJS format
const { Chat, ChatMessageSendEvent, Message } = require('@progress/kendo-react-conversational-ui');

Adding the Required Entities

Add a user, bot, and initialMessages.

const user = {
  id: 1,
  avatarUrl: "https://via.placeholder.com/24/008000/008000.png",
};

const bot = { id: 0 };

const initialMessages: Message[] = [
  {
    author: bot,
    timestamp: new Date(),
    text: "Hello, This is the KendoReact Chat component.",
  },
];

For more information about the available entities and binding them to data, see the Data Binding article.

Setting and Updating the Messages

Set the component messages and configure the updating of the messages collection in the state.

const App = () => {
  const [messages, setMessages] = React.useState(initialMessages);

  const addNewMessage = (event: ChatMessageSendEvent) => {
    setMessages([...messages, event.message]);
  };
  ...

Adding the Component

After successfully installing and importing the Chat component, add the component's markup to the src/App.js file in your project.

<Chat
user={user}
messages={messages}
onMessageSend={addNewMessage}
placeholder={"Type a message..."}
width={400}
/>

Adding the KendoReact CSS Styles

To style the Chat, install and import the Default theme, which is one of the three beautiful themes for KendoReact.

  1. Install the Default theme package.

    npm install --save @progress/kendo-theme-default
  2. Import the CSS file from the package in src/App.js. Add this import before your existing App.css import.

    import '@progress/kendo-theme-default/dist/all.css';

Running the Application

  1. Build and run the application.

    npm start
  2. Navigate to http://localhost:3000 to see the KendoReact Chat component on the page.

Activating Your License Key

Follow the instructions on the KendoReact My License page to activate your trial or commercial license. You can skip this step if your application already contains a KendoReact license file.

Dependencies

The Conversational UI package requires you to install the following peer dependencies in your application:

Package NameDescription
react 16.8.2*Contains the functionality necessary to define React components.
react-domContains the React renderer for the web.
@progress/kendo-licensingContains the internal infrastructure related to licensing.
@progress/kendo-react-buttonsContains the KendoReact Buttons components.
@progress/kendo-react-intlContains the KendoReact Internationalization package that applies the desired cultures by providing services and pipes for the parsing and formatting of dates and numbers.

Learning Resources