Git Product home page Git Product logo

dialogflow-javascript-client's Introduction

DEPRECATED

Deprecated
This Dialogflow client library and Dialogflow API V1 have been deprecated and will be shut down on October 23th, 2019. Please migrate to Dialogflow API V2.

You can use this library as common pre-built .js (choose there).

Or you can install it with nodejs and that import as es6 (or .ts) module. See below.

npm install [email protected]

Usage

.textRequest

const client = new ApiAi.ApiAiClient({accessToken: 'YOUR_ACCESS_TOKEN'});
const promise = client.textRequest(longTextRequest);

promise
    .then(handleResponse)
    .catch(handleError);

function handleResponse(serverResponse) {
        console.log(serverResponse);
}
function handleError(serverError) {
        console.log(serverError);
}

.eventRequest

const promise = client.eventRequest("EVENT_NAME", options);

TypeScript and ES6

This SDK written with Typescript and all it's sources are available in this package. So basically if you are using something like webpack or browserify with ES6 imports and so on, you can just install this SDK with $ npm install api-ai-javascript --save-dev command and then import original sources with something like:

import {ApiAiClient} from "api-ai-javascript";

const client = new ApiAiClient({accessToken: 'YOUR_ACCESS_TOKEN'})

.textRequest('Hello!')
    .then((response) => {/* do something */})
    .catch((error) => {/* do something here too */})

Note: If you are going to build es5 version of your bundle with ApiAiClient inside, please add some typings for promises (e.g. @types/es6-promise)

You also can import and use all defined interfaces and ApiAiConstants:

import {IRequestOptions, IServerResponse, ApiAiConstants} from "api-ai-javascript/ApiAiClient"
const lang = ApiAiConstants.AVAILABLE_LANGUAGES.EN;

You can find full list of interfaces here

Development

  • Checkout from this repository, do not forget to switch to "v2" branch
  • run $ npm install
  • run $ webpack -w or just $ npm start (as an option for non globally installed dev-server - $ ./node_modules/.bin/webpack-dev-server)
  • develop! (webpack will automatically compile SDK to ./target/ApiAi.js file on each change, just include it into some test HTML file (./demo/index.html will probably do the job) and test it).

Building

$ npm run-script build command will build everything

Testing

$ npm test

Changelog

2.0.0-beta.21

  • tts and asr support removed (discontinued on API.AI side)

2.0.0-beta.19

  • minor typings changes

2.0.0-beta.18

  • some minor typings changes

2.0.0-beta.17

  • dependencies updated
  • webrtc typings removed (now part of typescript default lib)

2.0.0-beta.16

  • some linting (ionic2 compatibility issues)

2.0.0-beta.15

  • minor fixes, minor readme updates
  • exported constants

2.0.0-beta.14

  • minor fixes
  • GainNode removed (for now) as non-working in current setup

2.0.0-beta.13

  • IStreamClient is aligned with StreamClient needs, thanks to @muuki88 (#26)
  • Callbacks in IStremClientOptions are now typed properly
  • Added IStreamClient.getGain(): GainNode (#25) to allow set up gain of listener
  • Fixed UTF8 requests, thanks to @elaval (#24)

2.0.0-beta.12

  • Possibility to import ApiAiClient separately from ApiAiStreamClient
  • Typescript project demo setup added

2.0.0-beta.8

Breaking changes:

  • Main class renamed from Client to ApiAiClient
  • StreamClient renamed (in exports at least) to ApiAiStreamClient
  • StreamClient class is no longer available inside main ApiAiClient class and now should be passed directly in ApiAiClient constructor: const client = new ApiAiClient("ACCESS_TOKEN", {streamClientClass: ApiAiStreamClient}).That was made to allow building your applications without streamclient at all (streamclient now takes about 70% of whole library). And also there will be other implementation of streamClient in the future

Non-breaking changes:

  • Demo updated

How to make contributions?

Please read and follow the steps in the CONTRIBUTING.md.

License

See LICENSE.

Terms

Your use of this sample is subject to, and by using or downloading the sample files you agree to comply with, the Google APIs Terms of Service.

This is not an official Google product.

dialogflow-javascript-client's People

Contributors

ayeletdn avatar freakpirate avatar gugic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dialogflow-javascript-client's Issues

Error on Androïd: No live audio input in this browser

Got a "No live audio input in this browser" on Chrome for Androïd.
Didn't see any prompt.

Let's say I am not bothered with the user typing the text instead of using the mic, how should I switch off the use of microphone?
Thanks.

Demo no longer works

I've used the demo provided here in the past to build a proof-of-concept. Until last Friday (April 16th 2016) both my POC and the provided demo worked fine. Now they don't; I simply never get a call to onResults() and the submitted queries don't show up in the logs in the api.ai console. Neither the demo code nor my POC have been touched and they run on different systems.

What I notice has changed is that now when I call stopListening() the api object is immediately closed (possibly preventing the transmission of the results) where before it stayed open.

Doesn't open web socket connection

Hi,
Trying to run example but this is not working. I've tried all I know for this. And looks like callback onOpen not work. Could you help me, what I'm doing wrong?
Thanks, Taras

screen shot 2017-06-22 at 3 56 57 pm

Can't minify your source

[15:21:42] Starting 'minify-js'...

events.js:160
      throw er; // Unhandled 'error' event
      ^
GulpUglifyError: unable to minify JavaScript
  at createError (/home/circleci/tucana/node_modules/gulp-uglify/lib/create-error.js:6:14)
  at apply (/home/circleci/tucana/node_modules/gulp-uglify/node_modules/lodash/_apply.js:16:25)
  at wrapper (/home/circleci/tucana/node_modules/gulp-uglify/node_modules/lodash/_createCurry.js:41:12)
  at /home/circleci/tucana/node_modules/gulp-uglify/lib/minify.js:54:15
  at DestroyableTransform._transform (/home/circleci/tucana/node_modules/gulp-uglify/composer.js:10:23)
  at DestroyableTransform.Transform._read (/home/circleci/tucana/node_modules/gulp-uglify/node_modules/readable-stream/lib/_stream_transform.js:182:10)
  at DestroyableTransform.Transform._write (/home/circleci/tucana/node_modules/gulp-uglify/node_modules/readable-stream/lib/_stream_transform.js:170:83)
  at doWrite (/home/circleci/tucana/node_modules/gulp-uglify/node_modules/readable-stream/lib/_stream_writable.js:406:64)
  at writeOrBuffer (/home/circleci/tucana/node_modules/gulp-uglify/node_modules/readable-stream/lib/_stream_writable.js:395:5)
  at DestroyableTransform.Writable.write (/home/circleci/tucana/node_modules/gulp-uglify/node_modules/readable-stream/lib/_stream_writable.js:322:11)
  at write (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_readable.js:623:24)
  at flow (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_readable.js:632:7)
  at Transform.pipeOnReadable (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_readable.js:664:5)
  at emitNone (events.js:86:13)
  at Transform.emit (events.js:185:7)
  at emitReadable_ (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_readable.js:448:10)
  at emitReadable (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_readable.js:444:5)
  at readableAddChunk (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_readable.js:187:9)
  at Transform.Readable.push (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_readable.js:149:10)
  at Transform.push (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_transform.js:145:32)
  at Transform._transform (/home/circleci/tucana/node_modules/gulp-ng-annotate/index.js:84:10)
  at Transform._read (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_transform.js:184:10)
  at Transform._write (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_transform.js:172:12)
  at doWrite (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_writable.js:237:10)
  at writeOrBuffer (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_writable.js:227:5)
  at Transform.Writable.write (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_writable.js:194:11)
  at DestroyableTransform.ondata (/home/circleci/tucana/node_modules/gulp-ignore/node_modules/readable-stream/lib/_stream_readable.js:612:20)
  at emitOne (events.js:96:13)
  at DestroyableTransform.emit (events.js:188:7)
  at addChunk (/home/circleci/tucana/node_modules/gulp-ignore/node_modules/readable-stream/lib/_stream_readable.js:284:12)
  at readableAddChunk (/home/circleci/tucana/node_modules/gulp-ignore/node_modules/readable-stream/lib/_stream_readable.js:271:11)
  at DestroyableTransform.Readable.push (/home/circleci/tucana/node_modules/gulp-ignore/node_modules/readable-stream/lib/_stream_readable.js:238:10)
  at DestroyableTransform.Transform.push (/home/circleci/tucana/node_modules/gulp-ignore/node_modules/readable-stream/lib/_stream_transform.js:146:32)
  at DestroyableTransform._transform (/home/circleci/tucana/node_modules/gulp-ignore/index.js:18:9)
  at DestroyableTransform.Transform._read (/home/circleci/tucana/node_modules/gulp-ignore/node_modules/readable-stream/lib/_stream_transform.js:182:10)
  at DestroyableTransform.Transform._write (/home/circleci/tucana/node_modules/gulp-ignore/node_modules/readable-stream/lib/_stream_transform.js:170:83)
  at doWrite (/home/circleci/tucana/node_modules/gulp-ignore/node_modules/readable-stream/lib/_stream_writable.js:406:64)
  at writeOrBuffer (/home/circleci/tucana/node_modules/gulp-ignore/node_modules/readable-stream/lib/_stream_writable.js:395:5)
  at DestroyableTransform.Writable.write (/home/circleci/tucana/node_modules/gulp-ignore/node_modules/readable-stream/lib/_stream_writable.js:322:11)
  at write (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_readable.js:623:24)
  at flow (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_readable.js:632:7)
  at DestroyableTransform.pipeOnReadable (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_readable.js:664:5)
  at emitNone (events.js:86:13)
  at DestroyableTransform.emit (events.js:185:7)
  at emitReadable_ (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_readable.js:448:10)
  at emitReadable (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_readable.js:444:5)
  at readableAddChunk (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_readable.js:187:9)
  at DestroyableTransform.Readable.push (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_readable.js:149:10)
  at DestroyableTransform.Transform.push (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_transform.js:145:32)
  at afterTransform (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_transform.js:101:12)
  at TransformState.afterTransform (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_transform.js:79:12)
  at DestroyableTransform.noop [as _transform] (/home/circleci/tucana/node_modules/through2/through2.js:26:3)
  at DestroyableTransform.Transform._read (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_transform.js:184:10)
  at DestroyableTransform.Transform._write (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_transform.js:172:12)
  at doWrite (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_writable.js:237:10)
  at writeOrBuffer (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_writable.js:227:5)
  at DestroyableTransform.Writable.write (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_writable.js:194:11)
  at write (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_readable.js:623:24)
  at flow (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_readable.js:632:7)
  at DestroyableTransform.pipeOnReadable (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_readable.js:664:5)
  at emitNone (events.js:86:13)
  at DestroyableTransform.emit (events.js:185:7)
  at emitReadable_ (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_readable.js:448:10)
  at emitReadable (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_readable.js:444:5)
  at readableAddChunk (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_readable.js:187:9)
  at DestroyableTransform.Readable.push (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_readable.js:149:10)
  at DestroyableTransform.Transform.push (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_transform.js:145:32)
  at afterTransform (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_transform.js:101:12)
  at TransformState.afterTransform (/home/circleci/tucana/node_modules/readable-stream/lib/_stream_transform.js:79:12)
  at /home/circleci/tucana/node_modules/gulp/node_modules/vinyl-fs/lib/src/getContents/bufferFile.js:12:5
  at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:446:3)

error Command failed with exit code 1.

Our full minification work and if i do
ApiAi = require 'api-ai-javascript' that break straight our build
also same problem with import {ApiAiClient} from "api-ai-javascript"
as you can see we use gulp minify and gulp uglify to do that.
We have many differents libs include in our project i don't get why your's break everything 😟

Angular 2 integration

Hi,
I'm trying to integrate api.ai with my angular 2 (4 beta 8 actually) application but I get these errors:

ERROR in [at-loader] node_modules\api-ai-javascript\ts\Request\Request.ts:25:16
    TS2322: Type 'Promise<void>' is not assignable to type 'Promise<IServerResponse>'.
  Type 'void' is not assignable to type 'IServerResponse'.

ERROR in [at-loader] node_modules\api-ai-javascript\ts\Request\TTSRequest.ts:63:20
    TS2322: Type 'Promise<void>' is not assignable to type 'Promise<{}>'.
  Type 'void' is not assignable to type '{}'.

Here the extract of packages.json:


"dependencies": {
        "@angular/common": "~4.0.0-beta.8",
        "@angular/compiler": "~4.0.0-beta.8",
        "@angular/core": "~4.0.0-beta.8",
        "@angular/forms": "~4.0.0-beta.8",
        "@angular/http": "~4.0.0-beta.8",
        "@angular/platform-browser": "~4.0.0-beta.8",
        "@angular/platform-browser-dynamic": "~4.0.0-beta.8",
        "@angular/router": "~4.0.0-beta.8",

        "@angular/compiler-cli": "~4.0.0-beta.8",
        "@angular/platform-server": "~4.0.0-beta.8",

        "core-js": "^2.4.1",
        "reflect-metadata": "^0.1.10",
        "rxjs": "5.2.0",
        "zone.js": "^0.7.7",
        
        "font-awesome": "4.7.0"
    },
    "devDependencies": {
        "@types/core-js": "^0.9.35",
        "@types/jasmine": "^2.5.43",
        "@types/node": "^7.0.5",
        "@types/selenium-webdriver": "^2.53.39",
        "angular2-template-loader": "^0.6.2",
        "awesome-typescript-loader": "3.0.7",
        "enhanced-resolve": "3.1.0",
        "gulp": "3.9.1",
        "gulp-clean": "0.3.2",
        "gulp-concat": "2.6.1",
        "gulp-sass": "3.1.0",
        "html-loader": "0.4.4",
        "html-minify-loader": "^1.1.0",
        "html-webpack-plugin": "2.28.0",
        "imports-loader": "0.7.0",
        "json-loader": "0.5.4",
        "raw-loader": "^0.5.1",
        "rimraf": "2.6.0",
        "ts-loader": "2.0.1",
        "typescript": "2.1.6",
        "webpack":"2.2.1",
        "webpack-dev-server": "2.4.1",
        "webpack-visualizer-plugin": "^0.1.10",
        "magic-string":"0.19.0",
        "@ngtools/webpack":"^1.2.10",

        "api-ai-javascript": "^2.0.0-beta.16"
    }

Can you help me?
Thanks,
Alberto

Implement eventRequest

When I call client.eventRequest('event_name') as described in the readme, it's treated as a textRequest() and it doesn't trigger the event passed.
I saw that both EventRequest and TextRequest extend Request without adding any changes.

Websocket closing connection automatically (if lang=de)

Hi,

I use the streamClient but the websocket-connection closing connection automatically.
selection_039

I removed lang from client instantiation (so lang is default / en) and now it's working:

const client = new ApiAi.ApiAiClient({
      accessToken: '###',
      streamClientClass: ApiAi.ApiAiStreamClient,
      // lang: 'de'
});

I tested it also with the simple-demo - same results.

Stefan

Not working on iOS or Safari

Apparently you cannot access microphone via getUserMedia in Safari on OSX and Safari/Chrome on iOS due to OS limitation, so the recorder is not working.
I think a reference to which browsers are currently supported would be helpful.

Publish .js and .d.ts files on npmjs instead of .ts.

See microsoft/TypeScript#15363.

Currently this package publishes .ts files in the package on npmjs, so that rules like noImplicitAny get picked up when you import { ... } from "api-ai-javascript".

The recommendation is to instead publish .js files with the corresponding .d.ts files. See the link at the top of this comment for the issue thread on the TypeScript repo about this.

An example of another repo that has made this change to their TS project publishing: Goyoo/node-k8s-client#37.

IStreamClient interface only exposes startListening

Hi,

The typescript variant of IStreamClient only exposes startListening, which makes this example uncompilable:

const client = new ApiAi.Client({accessToken: "ACCESS_TOKEN", streamClientClass: ApiAi.ApiAiStreamClient});
const streamClient = client.createStreamClient(); // in that case some default settings will be applied
streamClient.onInit = function () {
    console.log("> ON INIT use direct assignment property");
    streamClient.open();
};

streamClient.init();
streamClient.startListening();
streamClient.stopListening();

readme hyperlink issue

The readme's hyperlink under "How to use the agent" is forwarding to an incorrect url.

Add package to npm

Is this official javascript package available in npm?

I would love to use this on an existing webpack build, but I can't find a maintanable way of doing it since I have to download the package again everytime I want to update.

The node js SDK is already available on npm, so why not this one too? This is the one I need since I'm only making a frontend app.

Property 'AudioContext' does not exist on type 'Window'.

I'm using Ionic2 with Typescript. Unfortunately I couldn't use the cordova plugin version as type definitions are not available yet.

Running the JS version into my Ionic2 project. After following though the installation steps, I see following error.

Property 'AudioContext' does not exist on type 'Window'.
Cannot find name 'webkitAudioContext'.

How do we fix this?

There seem to be only /query request

Overview

In API.AI, there are some API like /intents /contexts.

But It doesn't seem to be support them in this library, why?

I'll send pull request if reason is just lack of contributor.

Disable microphone request

Hi,
I was wondering if there was a way to disable the microphone request. I'm using the client for text and don't want to have users confirm mic access every time they load the page.

Thanks,
Steve

Export Interfaces.ts and Constants.ts

Hi,

In order to write properly type classes it should be easy to access the relevant types.
At the moment I need to import IServerResponse like this

import {IServerResponse} from '../../node_modules/api-ai-javascript/ts/Interfaces';

const response: IServerResponse = ...

It would be nice to import it like

import {IServerResponse} from 'api-ai-javascript';

Using speech recognition api endpoint?

Is it possible to use the speech recognition api endpoint through the javascript sdk?
If so, how do I make sure the access_token I use remains secure?

Push release tags to github

Hi,

It would be awesome to see the releases along with the changelog in the github release section :)

thanks a lot and for all the work,
Muki

Websocket connection closing without response.

We have been working on creating of a Prove of Concept integration for Voice support for our application last week and got the base working using the javascript API.
Since last weekend however the integration stopped working. The websocket connection is opened and closed without any feedback data send. Also it looks like the server does not receive any client data either.
Anyone an idea if anything has changed server side that cause the javascript api to stop working?

Issues on IE11

I am trying to build test bot following the way like demo file. But which is not working on IE11.
how to fix ?

Not receiving responses in electron app

Hi,

I'm using api.ai in an electron app however I am unable to get any results back.

My code looks like this:

var config = {
server: 'wss://api.api.ai:4435/api/ws/query',
token: 'my_access_token',// Use Client access token there (see agent keys).
sessionId: '1234'
};

var apiAi = new ApiAi(config);

apiAi.onInit = function(){
console.log("INITED");
apiAi.open();
}

apiAi.init();

$("link").on('click', function(){
apiAi.startListening();
})

apiAi.onStartListening = function(){
console.log("started listening")
}

apiAi.onResults = function(data){
console.log(data.result);
}

I am able to receive the debug message 'started listening' but I am not receiving any results back after that. However if I do apiAi.sendJson('data to send'), then I receive the results back which means I'm connecting to my agent correctly.

add to bower

Adding to bower would make project integration easier. Just a recommendation.

WebSocket is already in CLOSING or CLOSED state.

Hi there,

Great potential in this lib, thanks.

Copy pasting the code results in

WebSocket is already in CLOSING or CLOSED state.

which seems to break up the state?

(function() {
  'use strict';

  angular
    .module('findr')
    .controller('MainController', MainController);

  /** @ngInject */
  function MainController($rootScope, $timeout, webDevTec, toastr) {
    var vm = this;
    var apiAi = new ApiAi($rootScope.apiAiConfig);

    vm.classAnimation = '';
    vm.Listening = false;

    activate();

    //
    // Private methods
    //
    function activate() {
      $timeout(function() {
        vm.classAnimation = 'rubberBand';
      }, 4000);
    }

    function processResult(data) {
      console.log('Processing api.ai data')
    }

    //
    // Scope methods
    //
    vm.startListening = function () {
      apiAi.init();
      vm.Listening = true;
    }

    vm.stopListening = function () {

      apiAi.stopListening();
      apiAi.close();

      vm.Listening = false;
    }

    //
    // Api ai events
    //
    apiAi.onInit = function () {
        console.log('onInit');
        apiAi.open();
    };

    apiAi.onOpen = function () {
        console.log('onOpen');
        console.log(apiAi.isOpen())
        apiAi.startListening();
    };

    apiAi.onClose = function () {
      console.log('onClose');
      vm.Listening = false;
      console.log(apiAi.isOpen())
    };

    apiAi.onStartListening = function () {
      console.log('onStartListening');
      vm.Listening = true;
    };
    /**
     * It's triggered when listening is stopped.
     */
    apiAi.onStopListening = function () {
      console.log('onStopListening');
      vm.Listening = false;
      console.log(apiAi.isOpen())
    };


// apiAi.onEvent = function (code, data) {
apiAi.onError = function (code, data) {
  console.log('onError')
  console.log(code)
  console.log(data)
};

    apiAi.onResults = function (data) {
        console.log('onResults');
        console.log(data)

        var status = data.status;

        var code;
        if (!(status && (code = status.code) && isFinite(parseFloat(code)) && code < 300 && code > 199)) {
            text.innerHTML = JSON.stringify(status);
            return;
        }
        processResult(data.result);
    };

  }
})();

Similar to this perhaps? faye/faye#371

demo

Require error

I installled this package through npm install api-ai-javascript for my node app, using ecs6.

I require it using var ApiAi = require('api-ai-javascript');

And I have this error :

apppath\node_modules\api-ai-javascript\index.js:1
(function (exports, require, module, __filename, __dirname) { export * from "./srces6/_build";
                                                              ^^^^^^

SyntaxError: Unexpected reserved word
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (appFileWhereRequireIsDone:1:77)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)

I can't understand why there is export in a js file, is that not only for ts?

I also try using this package with files under target path, but I had another error while running an example.
I prefer npm package.

How should I import and use your module?

node problems

I'm guessing this library isn't meant to be run server side, but I was having problems with the API.ai official libs and tried it to get the issue below

removing your package the problem went away.

../node_modules/@types/webrtc/RTCPeerConnection.d.ts(35,5): error TS2403: Subsequent variable declarations must have the same type.  Variable 'type' must be of type 'string', but here has type 'RTCSdpType'.
../node_modules/@types/webrtc/RTCPeerConnection.d.ts(35,5): error TS2687: All declarations of 'type' must have identical modifiers.
../node_modules/@types/webrtc/RTCPeerConnection.d.ts(41,14): error TS2403: Subsequent variable declarations must have the same type.  Variable 'type' must be of type 'string', but here has type 'RTCSdpType'.
../node_modules/@types/webrtc/RTCPeerConnection.d.ts(41,14): error TS2687: All declarations of 'type' must have identical modifiers.
../node_modules/@types/webrtc/RTCPeerConnection.d.ts(42,14): error TS2687: All declarations of 'sdp' must have identical modifiers.
../node_modules/@types/webrtc/RTCPeerConnection.d.ts(59,5): error TS2687: All declarations of 'candidate' must have identical modifiers.
../node_modules/@types/webrtc/RTCPeerConnection.d.ts(66,14): error TS2687: All declarations of 'candidate' must have identical modifiers.
../node_modules/@types/webrtc/RTCPeerConnection.d.ts(67,14): error TS2687: All declarations of 'sdpMid' must have identical modifiers.
../node_modules/@types/webrtc/RTCPeerConnection.d.ts(68,14): error TS2687: All declarations of 'sdpMLineIndex' must have identical modifiers.
../node_modules/@types/webrtc/RTCPeerConnection.d.ts(204,5): error TS2687: All declarations of 'maxFramerate' must have identical modifiers.
../node_modules/@types/webrtc/RTCPeerConnection.d.ts(240,5): error TS2403: Subsequent variable declarations must have the same type.  Variable 'degradationPreference' must be of type 'string', but here has type 'RTCDegradationPreference'.
../node_modules/@types/webrtc/RTCPeerConnection.d.ts(315,5): error TS2403: Subsequent variable declarations must have the same type.  Variable 'iceTransportPolicy' must be of type 'string', but here has type 'RTCIceTransportPolicy'.
../node_modules/@types/webrtc/RTCPeerConnection.d.ts(316,5): error TS2403: Subsequent variable declarations must have the same type.  Variable 'bundlePolicy' must be of type 'string', but here has type 'RTCBundlePolicy'.
../node_modules/@types/webrtc/RTCPeerConnection.d.ts(401,6): error TS2300: Duplicate identifier 'RTCSessionDescriptionCallback'.
../node_modules/@types/webrtc/RTCPeerConnection.d.ts(405,6): error TS2300: Duplicate identifier 'RTCPeerConnectionErrorCallback'.
../node_modules/@types/webrtc/RTCPeerConnection.d.ts(409,6): error TS2300: Duplicate identifier 'RTCStatsCallback'.
../node_modules/@types/webrtc/RTCPeerConnection.d.ts(428,14): error TS2403: Subsequent variable declarations must have the same type.  Variable 'signalingState' must be of type 'string', but here has type 'RTCSignalingState'.
../node_modules/@types/webrtc/RTCPeerConnection.d.ts(429,14): error TS2403: Subsequent variable declarations must have the same type.  Variable 'iceGatheringState' must be of type 'string', but here has type 'RTCIceGatheringState'.
../node_modules/@types/webrtc/RTCPeerConnection.d.ts(430,14): error TS2403: Subsequent variable declarations must have the same type.  Variable 'iceConnectionState' must be of type 'string', but here has type 'RTCIceConnectionState'.
../node_modules/@types/webrtc/RTCPeerConnection.d.ts(432,14): error TS2687: All declarations of 'canTrickleIceCandidates' must have identical modifiers.
../node_modules/@types/webrtc/RTCPeerConnection.d.ts(438,5): error TS2403: Subsequent variable declarations must have the same type.  Variable 'onnegotiationneeded' must be of type '(this: RTCPeerConnection, ev: Event) => any', but here has type 'EventHandler'.
../node_modules/@types/webrtc/RTCPeerConnection.d.ts(439,5): error TS2403: Subsequent variable declarations must have the same type.  Variable 'onicecandidate' must be of type '(this: RTCPeerConnection, ev: RTCPeerConnectionIceEvent) => any', but here has type '(event: RTCPeerConnectionIceEvent) => void'.
../node_modules/@types/webrtc/RTCPeerConnection.d.ts(441,5): error TS2403: Subsequent variable declarations must have the same type.  Variable 'onsignalingstatechange' must be of type '(this: RTCPeerConnection, ev: Event) => any', but here has type 'EventHandler'.
../node_modules/@types/webrtc/RTCPeerConnection.d.ts(442,5): error TS2403: Subsequent variable declarations must have the same type.  Variable 'oniceconnectionstatechange' must be of type '(this: RTCPeerConnection, ev: Event) => any', but here has type 'EventHandler'.
../node_modules/@types/webrtc/RTCPeerConnection.d.ts(443,5): error TS2403: Subsequent variable declarations must have the same type.  Variable 'onicegatheringstatechange' must be of type '(this: RTCPeerConnection, ev: Event) => any', but here has type 'EventHandler'.
../node_modules/@types/webrtc/RTCPeerConnection.d.ts(491,13): error TS2403: Subsequent variable declarations must have the same type.  Variable 'RTCPeerConnection' must be of type '{ new (configuration: RTCConfiguration): RTCPeerConnection; prototype: RTCPeerConnection; }', but here has type 'RTCPeerConnectionStatic'.
../node_modules/@types/webrtc/RTCPeerConnection.d.ts(492,13): error TS2403: Subsequent variable declarations must have the same type.  Variable 'RTCSessionDescription' must be of type '{ new (descriptionInitDict?: RTCSessionDescriptionInit): RTCSessionDescription; prototype: RTCSes...', but here has type 'RTCSessionDescriptionStatic'.
../node_modules/@types/webrtc/RTCPeerConnection.d.ts(493,13): error TS2403: Subsequent variable declarations must have the same type.  Variable 'RTCIceCandidate' must be of type '{ new (candidateInitDict?: RTCIceCandidateInit): RTCIceCandidate; prototype: RTCIceCandidate; }', but here has type 'RTCIceCandidateStatic'.
../node_modules/typescript/lib/lib.es6.d.ts(20104,11): error TS2300: Duplicate identifier 'RTCSessionDescriptionCallback'.
../node_modules/typescript/lib/lib.es6.d.ts(20107,11): error TS2300: Duplicate identifier 'RTCPeerConnectionErrorCallback'.
../node_modules/typescript/lib/lib.es6.d.ts(20110,11): error TS2300: Duplicate identifier 'RTCStatsCallback'.
lib/nlp/ApiAiBot.ts(20,11): error TS6133: 'event' is declared but never used.
tests/ApiAiBot.test.ts(1,7): error TS6133: 'test' is declared but never used.
tests/ApiAiBot.test.ts(5,9): error TS6133: 'AppConfig' is declared but never used.
tests/ApiAiBot.test.ts(8,5): error TS6133: 'testmsg' is declared but never used.

StreamClient: Howto

I'm trying to let users ask questions through their microphones, convert that to text and send it to api.ai. I've implemented the StreamClient example code from the README content and it seems to at least init the stream client since my browser asks me whether I want to allow access to the mic for that web portal. I can also see that the "onInit" function is being triggered.

My initial design is simple: user hits a button on the portal and starts asking the question - once he/she stops talking (1-2 seconds of silence) I'd assume that the speech recorder stops recording and either provides the result in text form (a string that I can use to call the api.ai /query method) or automatically pushes the recoreded audio to api.ai and provides the results from the server as JSON.

How would I achieve that?
Thanks
Kurt

No microphone access using Javascript SDK

My project needs to access the device's microphone, and I am trying to achieve it using the Javascript SDK.

Here is the code as follows,
const streamClient = client.createStreamClient();
streamClient.onInit = function () {
console.log("Entered streamClient function");
streamClient.open();
};

The issue is that the streamClient is not created because webkitAudioContext is not defined. Why is this issue occuring? Is there a work around for this?

PS: I am able to send and receive text responses using the same SDK. So I guess it is only the microphone part of the SDK that has bugs.

Challenge with International Characters (utf-8 issue)

Hi! I have been trying this API (in typescript) and it works very well in English. But I am having some issues with international characters.

For example if I send the request:
"¿Cuál es la población de España?" (which is spanish for "What is the population in Spain?")

It gets resolved (result.resolvedQuery) to:
"¿Cuál es la población de España?"

I noticed that the problem is solved if the HTTPRequest was sent specifying the charset (utf-8) in the Content Type headers.

This could be achieved if line 43 in ts/XhrRequest.ts:

                headers["Content-Type"] = "application/json";

Is changed to:

                headers["Content-Type"] = "application/json; charset=utf-8";

It works OK and I get the right result.resolvedQuery:
"¿Cuál es la población de España?"

Sample code to reproduce the issue:

this.aiClient = new Client({accessToken: this.token});
this.aiClient.textRequest("¿Cuál es la población de España?")
    .then((response:any) => console.log(response.result.resolvedQuery));

Add GainNode

Hi,

In the startUserMedia method in the StreamClient a GainNode could be added as well to configure the microphone gain.

No way to use it without https ?

I'm building my personal website, no audio inputs, just general information about my resume.. And people block their microphones when the browser asks for it.

Error Resolving ApiAiBaseError Symbol Value in angular-cli

Hey,

I'm using the Typescript version of the apiai-javascript-client in my angular-cli project. When I try to run ng build --prod I get this error:

ERROR in Error encountered resolving symbol values statically. Reference to a non-exported class ApiAiBaseError. Consider exporting the class, resolving symbol ApiAiClientConfigurationError in /.../node_modules/api-ai-javascript/ts/Errors.ts

It seems like adding an export in front of abstract class ApiAiBaseError extends Error fixes the issue, for me at least.

Problem with Typescript

Hi,
I need help. I installed api-ai with "npm install api-ai-javascript --save-dev", and put code 'import {ApiAiClient, ApiAiStreamClient} from "api-ai-javascript";' in my code file. It shows lots of errors.

Typescript Error
Property 'AudioContext' does not exist on type 'Window'.
...opbox/Websites/Cueat/App/node_modules/api-ai-javascript/ts/Request/TTSRequest.ts
this.uri = Constants.DEFAULT_TTS_HOST;
const AudioContext = window.AudioContext || webkitAudioContext;

Typescript Error
Cannot find name 'webkitAudioContext'.
...opbox/Websites/Cueat/App/node_modules/api-ai-javascript/ts/Request/TTSRequest.ts
this.uri = Constants.DEFAULT_TTS_HOST;
const AudioContext = window.AudioContext || webkitAudioContext;

Typescript Error
Property 'AudioContext' does not exist on type 'Window'.
...ropbox/Websites/Cueat/App/node_modules/api-ai-javascript/ts/Stream/Processors.ts
_resamplerJSRegisterer();
window.AudioContext = window.AudioContext || webkitAudioContext;

Typescript Error
Property 'AudioContext' does not exist on type 'Window'.
...ropbox/Websites/Cueat/App/node_modules/api-ai-javascript/ts/Stream/Processors.ts
_resamplerJSRegisterer();
window.AudioContext = window.AudioContext || webkitAudioContext;

Typescript Error
Cannot find name 'webkitAudioContext'.
...ropbox/Websites/Cueat/App/node_modules/api-ai-javascript/ts/Stream/Processors.ts
_resamplerJSRegisterer();
window.AudioContext = window.AudioContext || webkitAudioContext;

Typescript Error
Property 'AudioContext' does not exist on type 'Window'.
...pbox/Websites/Cueat/App/node_modules/api-ai-javascript/ts/Stream/StreamClient.ts
try {
window.AudioContext = window.AudioContext || webkitAudioContext;
navigator.getUserMedia =

Typescript Error
Property 'AudioContext' does not exist on type 'Window'.
...pbox/Websites/Cueat/App/node_modules/api-ai-javascript/ts/Stream/StreamClient.ts
try {
window.AudioContext = window.AudioContext || webkitAudioContext;
navigator.getUserMedia =

Typescript Error
Cannot find name 'webkitAudioContext'.
...pbox/Websites/Cueat/App/node_modules/api-ai-javascript/ts/Stream/StreamClient.ts
try {
window.AudioContext = window.AudioContext || webkitAudioContext;
navigator.getUserMedia =

Typescript Error
Property 'webkitGetUserMedia' does not exist on type 'Navigator'.
...pbox/Websites/Cueat/App/node_modules/api-ai-javascript/ts/Stream/StreamClient.ts
navigator.getUserMedia =
navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
window.URL = window.URL || window.webkitURL;

Typescript Error
Property 'mozGetUserMedia' does not exist on type 'Navigator'.
...pbox/Websites/Cueat/App/node_modules/api-ai-javascript/ts/Stream/StreamClient.ts
navigator.getUserMedia =
navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
window.URL = window.URL || window.webkitURL;

Typescript Error
Cannot find name 'ActiveXObject'.
.../Sync/Dropbox/Websites/Cueat/App/node_modules/api-ai-javascript/ts/XhrRequest.ts
() => new XMLHttpRequest(),
() => new ActiveXObject("Msxml2.XMLHTTP"),
() => new ActiveXObject("Msxml3.XMLHTTP"),

Typescript Error
Cannot find name 'ActiveXObject'.
.../Sync/Dropbox/Websites/Cueat/App/node_modules/api-ai-javascript/ts/XhrRequest.ts
() => new ActiveXObject("Msxml2.XMLHTTP"),
() => new ActiveXObject("Msxml3.XMLHTTP"),
() => new ActiveXObject("Microsoft.XMLHTTP")

Typescript Error
Cannot find name 'ActiveXObject'.
.../Sync/Dropbox/Websites/Cueat/App/node_modules/api-ai-javascript/ts/XhrRequest.ts
() => new ActiveXObject("Msxml3.XMLHTTP"),
() => new ActiveXObject("Microsoft.XMLHTTP")
];

Typescript Error
Supplied parameters do not match any signature of call target.
D:/Documents/Sync/Dropbox/Websites/Cueat/App/src/pages/home/home.ts
M_RequestMenuByText(Text){
const client = new ApiAiClient('YOUR_ACCESS_TOKEN', {streamClientClass: ApiAiStreamClient});
client

Demo not working cannot connect to websocket

Hello, trying to connect to the websocket but I keep getting the message in the js console "use direct assignment property" and the connection just hangs... without opening nor closing. Thought was a firewall issue but I'm getting that from every device.

When trying to send a json message or record voice, I'm getting the following error from the console:


api.ai.min.js:16 Uncaught InvalidStateError: Failed to execute 'send' on 'WebSocket': Still in CONNECTING state.e.startListening @ api.ai.min.js:16_start @ app.js:188App.start @ app.js:37onclick @ index.html:47

Language change example

Hi guys,

Can you add an example how I can change recognition language? I'm trying to make Russian eWallet assistant.

What I've tried: change "lang": "RU", to RU and to create Russian agent on your site.

P.S.: I know some of you are Russian :).

Property 'status' does not exist on type 'XMLHttpRequestEventTarget'

Hi,

When I try to compile the current v2 branch I get

ERROR in [at-loader] node_modules/api-ai-javascript/src/XhrRequest.ts:69:26 
    Property 'status' does not exist on type 'XMLHttpRequestEventTarget'.

ERROR in [at-loader] node_modules/api-ai-javascript/src/XhrRequest.ts:69:48 
    Property 'status' does not exist on type 'XMLHttpRequestEventTarget'.

I guess this can be fixed by replacing

if (this.status >= 200 && this.status < 300)

with

if (client.status >= 200 && client.status < 300)

Android Google Chrome issue

The current version doesn't seem to work with Google Chrome on Android. The reason seems to be navigator.getUserMedia, which is going to be deprecated. I tried using the navigator.mediaDevices.getUserMedia promise, but it doesn't work either.

Get text as user speaks

Hi,

I've been playing for a while with your js SDK and i'm missing a way to get a text string as user is speaking. Using webkitSpeechRecognition you can get instant transcription of the text as user speaks, in real time, while with your SDK you have to wait until a result event is triggered. Is it possible asking for?

Thank you!

[TypeScript] Parameters in IServerResponse

Hi,

I use api.ai with angular 2 and i wanted to access to Parameters object in the response,
but sadly typescript say that it doesn't exist on IServerResponse

By now i have modified IServerResponse to include parameters as "any" type but i wanted to kow if its a "bug" or if you havn't include it consciously ?

By the way, the way thanks for your great job,
Api.Ai is awesome !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.