翻譯|使用教程|編輯:龔雪|2021-09-24 10:06:04.183|閱讀 208 次
概述:本文主要介紹Kendo UI for Angular組件的對話式用戶界面功能,歡迎下載最新版產(chǎn)品體驗!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
Conversational UI組件彌合了Web 和下一代自然語言應(yīng)用程序之間的差距。Conversational UI 包提供了Kendo UI聊天組件,該組件允許用戶參與與其他用戶或聊天機器人的聊天會話。
Conversational UI Package 是 Kendo UI for Angular 的一部分,這是一個專業(yè)級 UI 庫,具有 100 多個組件,用于構(gòu)建現(xiàn)代且功能豐富的應(yīng)用程序。
以下示例演示了 Chat 的實際操作。
app.component.ts
import { Component } from '@angular/core'; import { Subject, from, merge, Observable } from 'rxjs'; import { switchMap, map, windowCount, scan, take, tap } from 'rxjs/operators'; import { ChatModule, Message, User, Action, ExecuteActionEvent, SendMessageEvent } from '@progress/kendo-angular-conversational-ui'; import { ChatService } from './chat.service'; @Component({ providers: [ ChatService ], selector: 'my-app', template: ` <kendo-chat [messages]="feed | async" [user]="user" (sendMessage)="sendMessage($event)" > </kendo-chat> ` }) export class AppComponent { public feed: Observable<Message[]>; public readonly user: User = { id: 1 }; public readonly bot: User = { id: 0 }; private local: Subject<Message> = new Subject<Message>(); constructor(private svc: ChatService) { const hello: Message = { author: this.bot, suggestedActions: [{ type: 'reply', value: 'Neat!' }, { 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!' }; // Merge local and remote messages into a single stream this.feed = merge( from([ hello ]), this.local, this.svc.responses.pipe( map((response): Message => ({ author: this.bot, text: response }) )) ).pipe( // ... and emit an array of all messages scan((acc: Message[], x: Message) => [...acc, x], []) ); } public sendMessage(e: SendMessageEvent): void { this.local.next(e.message); this.local.next({ author: this.bot, typing: true }); this.svc.submit(e.message.text); } }
chat.service.ts
import { Observable, Subject } from 'rxjs'; import { Injectable } from '@angular/core'; // Mock remote service @Injectable() export class ChatService { public readonly responses: Subject<string> = new Subject<string>(); public submit(question: string): void { const length = question.length; const answer = `"${question}" contains exactly ${length} symbols.`; setTimeout( () => this.responses.next(answer), 1000 ); } }
app.module.ts
import { NgModule } from '@angular/core'; import { Component } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { ChatModule } from '@progress/kendo-angular-conversational-ui'; import { AppComponent } from './app.component'; @NgModule({ imports: [ BrowserModule, BrowserAnimationsModule, ChatModule ], declarations: [ AppComponent ], bootstrap: [ AppComponent ] }) export class AppModule { }
main.ts
import './polyfills'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { AppModule } from './app.module'; const platform = platformBrowserDynamic(); platform.bootstrapModule(AppModule);
使用快速設(shè)置 (Angular CLI) 或手動添加包。
使用Angular CLI進行快速設(shè)置
Angular CLI 支持通過 ng add 命令添加包,該命令一步執(zhí)行一組其他單獨需要的命令。
ng add @progress/kendo-angular-conversational-ui
手動設(shè)置
1. 下載并安裝包及其對等依賴項。
npm install --save @progress/kendo-angular-conversational-ui @progress/kendo-angular-common @progress/kendo-angular-buttons @progress/kendo-angular-popup @progress/kendo-licensing
2. 安裝后,在您的應(yīng)用程序根或功能模塊中導(dǎo)入 ChatModule。
import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { ChatModule } from '@progress/kendo-angular-conversational-ui'; import { AppComponent } from './app.component'; @NgModule({ bootstrap: [ AppComponent ], declarations: [ AppComponent ], imports: [ BrowserModule, BrowserAnimationsModule, ChatModule ] }) export class AppModule { }
3. 您需要安裝一個Kendo UI主題來設(shè)置組件的樣式。
4. 對于Angular 9.x 及更高版本,安裝 @angular/localize 包:
5. 按照 Kendo UI for Angular My License 頁面上的說明激活您的授權(quán)許可。 如果您的應(yīng)用程序已包含 Kendo UI 許可文件,則可以跳過此步驟。
Conversational UI 包需要您的應(yīng)用程序必須安裝以下對等依賴項:
Kendo UI for Angular是Kendo UI系列商業(yè)產(chǎn)品的最新產(chǎn)品。Kendo UI for Angular是專用于Angular開發(fā)的專業(yè)級Angular組件。telerik致力于提供純粹的高性能Angular UI組件,無需任何jQuery依賴關(guān)系。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都網(wǎng)