New to Kendo UI for AngularStart a free 30-day trial

Using with Microsoft Bot Framework

The Chat provides integration options for connecting the component to chat bots which are built with Microsoft Bot Framework.

Travel Agent Chat Bot

The following example demonstrates how to connect the Chat to chat bots which run on Azure Bot Service and use the Direct Line protocol to create a Travel Agent Chat Bot.

ts
import { Component, ViewEncapsulation } from '@angular/core';
import { Subject, Observable, merge } from 'rxjs';
import { scan } from 'rxjs/operators';
import { Message, User, Action, SendMessageEvent } from '@progress/kendo-angular-conversational-ui';
import { Agent } from './agent';

// API secret
const secret = 'YOUR API SECRET';

@Component({
  encapsulation: ViewEncapsulation.None,
  selector: 'my-app',
  styles: [`
    .k-card-image {
      max-width: 250px;
    }
  `],
  template: `
      <kendo-chat
        [messages]="feed | async"
        [user]="user"
        (sendMessage)="sendMessage($event)"
      >
        <ng-template kendoChatAttachmentTemplate let-att>
          <ng-container [ngSwitch]="att.contentType">
            <kendo-chat-hero-card *ngSwitchCase="'application/vnd.microsoft.card.hero'"
              imageUrl="{{ att.content.images ? att.content.images[0]?.url : '' }}"
              [title]="att.content.title || att.content.text"
              [subtitle]="att.content.subtitle"
              [actions]="att.content.buttons"
              (executeAction)="heroAction($event)"
            >
            </kendo-chat-hero-card>

            <adaptive-card [data]="att.content" *ngSwitchCase="'application/vnd.microsoft.card.adaptive'">
            </adaptive-card>

            <div class="k-card" *ngSwitchDefault>
              {{ att.content | json }}
            </div>
          </ng-container>
        </ng-template>
      </kendo-chat>
    `
})
export class AppComponent {
  public feed: Observable<Message[]>;

  public readonly user: User = {
    id: 'User'
  };

  public readonly bot: User = {
    id: 'Botyo-BotTesting',
    name: 'Travel Agent',
    avatarUrl: 'https://demos.telerik.com/kendo-ui/content/chat/VacationBot.png'
  };

  private agent: Agent = new Agent(this.bot, secret);
  private local: Subject<Message> = new Subject<Message>();

  constructor() {
    // Merge local and remote messages into a single stream
    this.feed = merge(
      this.local,
      this.agent.responses
    ).pipe(
      // ... and emit an array of all messages
      scan((acc: Message[], x: Message) => [...acc, x], [])
    );
  }

  public sendMessage(e: SendMessageEvent): void {
    this.send(e.message);
  }

  public heroAction(button: Action): void {
    if (button.type === 'imBack') {
      const message = {
        author: this.user,
        text: button.value
      };

      this.send(message);
    }
  }

  private send(message: Message) {
    this.local.next(message);
    this.local.next({
      author: this.bot,
      typing: true
    });

    this.agent.submit(message);
  }
}
In this article
Travel Agent Chat BotSuggested Links
Not finding the help you need?
Contact Support