如何从angular js的dialogflow的内联编辑器中获取响应

时间:2019-10-18 11:32:22

标签: angularjs dialogflow

我正在将我的dialogflow代理与angular js集成在一起,所以我无法从由dialogflow提供的内联编辑器中编写的实现中获取数据。我在实现编辑器中针对不同意图编写了逻辑。

这是用angular-进行对话的代码:

import { Injectable } from '@angular/core';
import { environment } from '../../environments/environment';


import { ApiAiClient } from 'api-ai-javascript/es6/ApiAiClient'
import { Observable } from 'rxjs';
import {BehaviorSubject} from 'rxjs';

// Message class for displaying messages in the component
export class Message {
  constructor(public content: string, public sentBy: string) {}
}

@Injectable({
  providedIn: 'root'
})
export class ChatService {

  readonly token = environment.dialogflow.angularBot;
  readonly client = new ApiAiClient({ accessToken: this.token });

  conversation = new BehaviorSubject<Message[]>([]);

  constructor() { }

  converse(msg: string) {
    const userMessage = new Message(msg, 'user');
    this.update(userMessage);

    return this.client.textRequest(msg)
               .then(res => {
                  const speech = res.result.fulfillment.speech;
                  const botMessage = new Message(speech, 'bot');
                  this.update(botMessage);
               });
  }

  // Adds message to source
  update(msg: Message) {
    this.conversation.next([msg]);
  }
}

我无法从实现中获取响应,我可以从意图中获取响应。

0 个答案:

没有答案
相关问题