dialogflow-cordova-client
dialogflow-cordova-client copied to clipboard
FAILED: Integration code for Ionic 2 native
Don't want to use javascript lib npm install api-ai-javascript --save
Below integration fails the build:
import { Component } from '@angular/core';
import { NavController, AlertController } from 'ionic-angular';
declare var ApiAIPlugin:any;
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public navCtrl: NavController, private alertCtrl: AlertController) {
ApiAIPlugin.init(
{
clientAccessToken: "", // insert your client access key here
lang: "en" // set lang tag from list of supported languages
}).then(result => {
// Could do something with the Response
console.log(result);
})
.catch(err => {
// Handle error
let alert = this.alertCtrl.create({
title: 'Error',
message: err.message,
buttons: ['OK']
});
alert.present();
});
}
" import { Component } from '@angular/core'; import { NavController } from 'ionic-angular'; import { TextToSpeech } from '@ionic-native/text-to-speech';
declare var ApiAIPlugin: any;
@Component({ selector: 'page-home', templateUrl: 'home.html' }) export class HomePage {
constructor(public tts: TextToSpeech, public navCtrl: NavController) {
ApiAIPlugin.init(
{
clientAccessToken: "908415e3087c4a66afe961857aca8099", // insert your client access key here
lang: "en" // set lang tag from list of supported languages
},
function (result) { /* success processing */ },
function (error) { /* error processing */ }
);
}
sendVoice() { try { ApiAIPlugin.requestVoice( {}, // empty for simple requests, some optional parameters can be here function (response) { this.tts.speak(JSON.stringify(response.result.fulfillment.speech), function () {
},
function (error) {
})
},
function (error) {
});
} catch (e) {
}
}
}
"
declare const ApiAIPlugin: any;
then....
platform.ready().then(() => {
// API AI
if (typeof ApiAIPlugin != 'undefined') {
ApiAIPlugin.init(
{
clientAccessToken: "", // insert your client access key here
lang: "en" // set lang tag from list of supported languages
},
result => { console.log('API AI ONLINE: ', result) },
error => { console.log('API AI OFFLINE: ', error)}
);
}
});