mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-24 05:06:02 +08:00
Add node-wit types definitions
This commit is contained in:
85
node-wit/index.d.ts
vendored
Normal file
85
node-wit/index.d.ts
vendored
Normal 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>;
|
||||
}
|
||||
14
node-wit/node-wit-tests.ts
Normal file
14
node-wit/node-wit-tests.ts
Normal 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
20
node-wit/tsconfig.json
Normal 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
1
node-wit/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "../tslint.json" }
|
||||
Reference in New Issue
Block a user