Getting Started with KendoReact Conversational UI

The KendoReact Conversational UI bridges the gap between the Web and the next-generation natural language applications and delivers the Chat component which allows the user to participate in chat sessions with other users or with chat bots.

The KendoReact Chat component is part of the KendoReact library of React UI components. It is distributed through NPM under the kendo-react-conversational-ui package.

Basic Usage

The following example demonstrates the Chat Component in action.

import React from 'react';
import ReactDOM from 'react-dom';
import { Chat } from '@progress/kendo-react-conversational-ui';
class App extends React.Component {
    constructor(props) {
        super(props);
        this.user = {
            id: 1,
            avatarUrl: "https://via.placeholder.com/24/008000/008000.png"
        };
        this.bot = { id: 0 };
        this.state = {
            messages: [
                {
                    author: this.bot,
                    suggestedActions: [
                        {
                            type: 'reply',
                            value: 'Oh, really?'
                        }, {
                            type: 'reply',
                            value: 'Thanks, but this is boring.'
                        }
                    ],
                    timestamp: new Date(),
                    text: "Hello, this is a demo bot. I don't do much, but I can count symbols!"
                }
            ]
        };
    }

    addNewMessage = (event) => {
        let botResponce = Object.assign({}, event.message);
        botResponce.text = this.countReplayLength(event.message.text);
        botResponce.author = this.bot;
        this.setState((prevState) => ({
            messages: [
                ...prevState.messages,
                event.message
            ]
        }));
        setTimeout(() => {
            this.setState(prevState => ({
                messages: [
                    ...prevState.messages,
                    botResponce
                ]
            }));
        }, 1000);
    };

    countReplayLength = (question) => {
        let length = question.length;
        let answer = question + " contains exactly " + length + " symbols.";
        return answer;
    }

    render() {
        return (
            <div>
                <Chat user={this.user}
                    messages={this.state.messages}
                    onMessageSend={this.addNewMessage}
                    placeholder={"Type a message..."}
                    width={400}>
                </Chat>
            </div>
        );
    }
}

ReactDOM.render(
    <App />,
    document.querySelector('my-app')
);

Functionality and Features

Installation

  1. Download and install the package. Use Node.js v5.0.0 or later.

    npm install --save @progress/kendo-react-conversational-ui @progress/kendo-react-buttons @progress/kendo-react-intl
  2. Once installed, import the package module.

    // ES2015 module syntax
    import { Chat } from '@progress/kendo-react-conversational-ui';
    // CommonJS format
    const { Chat } = require('@progress/kendo-react-conversational-ui');
  3. You are required to install one of the Kendo UI themes to style your components. For more information on how to add the styles, refer to the article on getting started.

Dependencies

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

  • react 16.8.2*
  • react-dom
  • @progress/kendo-react-buttons
  • @progress/kendo-react-intl
 /