I am currently integrating dialogflow into my ionic app. Below is the code snippet from my .ts file:
import { Component, NgZone } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
declare var ApiAIPromises: any;
@IonicPage()
@Component({
selector: 'page-chat-box',
templateUrl: 'chat-box.html',
})
export class ChatBoxPage {
answer;
constructor(public navCtrl: NavController,
public navParams: NavParams,
public ngZone: NgZone)
{
ApiAIPromises.init({
clientAccessToken: "xxxxxxxxxxxx"
})
.then((result) => console.log(result))
}
ionViewDidLoad() {
console.log('ionViewDidLoad ChatBoxPage');
}
goBack() {
this.navCtrl.pop();
}
ask(question) {
ApiAIPromises.requestText({
query: question
})
.then(({result: {fulfillment: {speech}}}) => {
this.ngZone.run(()=> {
this.answer = speech;
});
})
}
}
In addition to the code, I have also installed the plugin with the following command:
ionic cordova plugin add cordova-plugin-apiai
However, when attempting to run the application, an error occurs as shown below.
Uncaught (in promise): ReferenceError: ApiAIPromises is not defined ReferenceError: ApiAIPromises is not defined at new ChatBoxPage (chat-box.ts:19)