dialogflow-cordova-client icon indicating copy to clipboard operation
dialogflow-cordova-client copied to clipboard

FAILED: Integration code for Ionic 2 native

Open ghost opened this issue 7 years ago • 2 comments

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();
    });
    


  }

 

ghost avatar Apr 20 '17 11:04 ghost

" 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) {

}

}

}

"

johndoe829 avatar May 01 '17 12:05 johndoe829

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)}
        );
      }
    });

m69 avatar Oct 04 '17 19:10 m69