-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do we integrate it with Ionic 2 #28
Comments
You probably can use https://github.com/api-ai/api-ai-javascript to integrate with typescript and angular 2? |
@Gugic - Using the javascript SDK with Ionic v2 throws below exception:
|
@sunilkconsultant did you manage to use the Javascript SDK in Ionic 2 ? Regards |
@deepakbandela you can get this working with Ionic 2 and Angular 2. You just need to declare the variable import { Injectable } from '@angular/core';
import { Platform } from 'ionic-angular';
declare var ApiAIPromises: any;
@Injectable()
export class ChatbotService {
private accessToken = 'TOKEN_HERE' //best to take from environmental variables
private readySource: string;
private client: any;
constructor(
private platform: Platform
) {
this.platform.ready().then((readySource) => {
this.readySource = readySource;
if (readySource == 'dom'){
var ApiAiClient = require('api-ai-javascript').ApiAiClient;
this.client = new ApiAiClient({ accessToken: this.accessToken });
} else {
ApiAIPromises.init({
clientAccessToken: this.accessToken,
lang: "en"
}).then((data) => {
console.log('ApiAi initialised');
}).catch((error) => {
console.error('ApiAi Error: ',error)
});
}
});
}
async communicate(): Promise<any> {
let response: any;
if (this.readySource == 'dom'){
response = await this.client.textRequest('Demo request');
} else {
response = await ApiAIPromises.requestVoice();
}
return response.result;
}
} Hope this helps |
getting the following error ::
Any suggestions / ideas... |
Use the cordova plugin but it only works when on a device. Add the typeof check for dev in the browser.
then....
|
Hello, I tried a @m69 code in my project in ionic but i have this error.
I add You have a idea ? Thanks |
Same here, clean ionic app (fresh) But in Chrome browser I get this:
Can one switch off .map checking for ionic serve? |
Keep in mind that I'm using the cordova plugin and not the JS library. I can confirm I have it working properly - on a device only because of cordova. I'll take another look for ya later today :) |
@m69 , can you maybe just include a .map file when you build? |
Hello, I tried a code in my project in ionic but i have this error. ApiAIPlugin is not defined I add declare const ApiAIPlugin: any; in my code and add also public ApiAIPlugin: ApiAIPlugin in my constructor and nothing. I have a same error. You have a idea ? Thanks |
I'm having the same error. This cordova plugin seems broken I can't even build my app now. |
Guys, I found a work around. Use the api-ai-javascript plugin: https://github.com/dialogflow/dialogflow-javascript-client Follow their instructions to install and then
Next, create a blank file named index.js.map in node_modules/api-ai-javascript/ |
Vivek, Runtime Error |
Did you create a blank file named index.js.map in node_modules/api-ai-javascript/? |
No, I had just written one single command: and then this code in constructor: const client = new ApiAiClient({accessToken:'4596e9d3a1b641db86d96a0ae86e165f'}); |
Then create that file. It's required |
What should I supposed to write in it??? |
Keep it blank |
Thanks Brother: |
Thanks Guys. polyfills.js:3 POST https://api.api.ai/v1/query?v=20150910 net::ERR_CACHE_MISS Error ApiAiRequestError when I build it on my android device |
If it works in the browser it should work on your phone. Did you remove the cordova plugin? It may cause some issues |
when I build it on my android device alert "ApiAiRequestError" but run ionic serve is normal. |
Hello, |
having trouble integrating it with Ionic 2 on Angular 2 with Typescript.
Do you have an installation for Ionic2 and Angular2?
The text was updated successfully, but these errors were encountered: