Add node-wit types definitions

This commit is contained in:
JulienDuf
2017-01-02 15:23:47 -05:00
parent 9685bf5527
commit 58659b5a39
4 changed files with 120 additions and 0 deletions

85
node-wit/index.d.ts vendored Normal file
View File

@@ -0,0 +1,85 @@
// Type definitions for node-wit 4.2
// Project: https://github.com/wit-ai/node-wit#readme
// Definitions by: Julien Dufresne <https://github.com/julienduf>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="bluebird" />
import * as Promise from "bluebird";
export namespace log {
class Logger {
constructor(lvl: string);
}
const DEBUG = 'debug';
const INFO = 'info';
const WARN = 'warn';
const ERROR = 'error';
}
export interface WitEntityValue {
value?: string;
expressions?: string[];
}
export interface WitEntity {
id?: string;
values?: WitEntityValue[];
}
export interface WitContext {
state?: string[];
reference_time?: string;
timezone?: string;
entities?: WitEntity[];
location?: string;
}
export interface WitRequest {
sessinId?: string;
context?: WitContext;
text?: string;
entities?: WitEntity[];
}
export interface WitResponse {
text?: string;
qickReplies?: Object;
}
export interface WitOption {
accessToken?: string;
actions?: Object;
logger?: log.Logger;
}
export interface MessageResponseEntity {
confidence?: number;
value?: string;
}
export interface MessageResponse {
msg_id: string;
_text: string;
entities: Array<MessageResponseEntity>;
}
export declare class Wit {
constructor(option: WitOption);
message(message: string, context: WitContext): Promise<MessageResponse>;
converse(sessinId: string, message: string, context: WitContext, reset?: boolean): Promise<MessageResponse>;
runActions(sessinId: string, message: string, context: WitContext, maxSteps?: number): Promise<WitContext>;
}

View File

@@ -0,0 +1,14 @@
import { Wit, log } from "node-wit";
var wit = new Wit({accessToken: "", logger: new log.Logger(log.DEBUG)});
wit.message("Hello", {}).then((res) => {
console.log(res._text);
for (let entity of res.entities) {
console.log(entity.value + ": " + entity.confidence * 100 + "%");
}
}).catch((err) => {
});

20
node-wit/tsconfig.json Normal file
View File

@@ -0,0 +1,20 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"node-wit-tests.ts"
]
}

1
node-wit/tslint.json Normal file
View File

@@ -0,0 +1 @@
{ "extends": "../tslint.json" }