我正在尝试使用Angular 7和DialogFlow构建聊天机器人,但是当我将其部署到Firebase时,出现错误
src / app / chat / chat.service.ts(18,33)中的ERROR:错误TS2339:属性 类型'{production:boolean;上不存在'dialogflow' }'。
当我运行ng build --prod
这是我的chat.service.ts
import { Injectable } from '@angular/core';
import { environment } from '../../environments/environment';
import { ApiAiClient } from 'api-ai-javascript/es6/ApiAiClient';
import { Observable } from 'rxjs/Observable';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
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() { }
update(msg: Message){
this.conversation.next([msg]);
}
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);
});
}
talk(){
this.client.textRequest('Who Are You!')
.then(res => console.log(res));
}
}
如何进行修复?请帮助我。
答案 0 :(得分:1)
对于生产环境,ts将替换为environment.prod.ts
在您的环境中添加angularBot属性。prod.ts
还要检查此内容:https://blog.angularindepth.com/becoming-an-angular-environmentalist-45a48f7c20d8
答案 1 :(得分:0)
当您运行ng build时,prod angular-cli将使用environment.prod.ts文件,而您的environment.prod.ts文件环境变量没有对话流程,因此会出现错误。
查看更多信息-Property 'firebase' does not exist on type { production: boolean; }