Add types for react-native-dialogflow (#27617)

* Add types for react-native-dialogflow

* Fix lint issues.

* Formatting changes.

* Lint again.
This commit is contained in:
Jason Merino
2018-07-26 11:55:28 -07:00
committed by Andy
parent 7563e14289
commit b178c7f6bb
4 changed files with 166 additions and 0 deletions

View File

@@ -0,0 +1,93 @@
// Type definitions for react-native-dialogflow 3.2
// Project: https://github.com/innFactory/react-native-dialogflow#readme
// Definitions by: Jason Merino <https://github.com/jasonmerino>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.6
export namespace Dialogflow {
const LANG_CHINESE_CHINA = 'zh-CN';
const LANG_CHINESE_HONGKONG: 'zh-HK';
const LANG_CHINESE_TAIWAN: 'zh-TW';
const LANG_DUTCH: 'nl';
const LANG_ENGLISH: 'en';
const LANG_ENGLISH_GB: 'en-GB';
const LANG_ENGLISH_US: 'en-US';
const LANG_FRENCH: 'fr';
const LANG_GERMAN: 'de';
const LANG_ITALIAN: 'it';
const LANG_JAPANESE: 'ja';
const LANG_KOREAN: 'ko';
const LANG_PORTUGUESE: 'pt';
const LANG_PORTUGUESE_BRAZIL: 'pt-BR';
const LANG_RUSSIAN: 'ru';
const LANG_SPANISH: 'es';
const LANG_UKRAINIAN: 'uk';
function setConfiguration(accessToken: string, languageTag: string): void;
function setEntities(entities: any[]): void;
function startListening(resultCallback: (result: object) => void, errorCallback: (error: Error) => void): void;
function finishListening(): void;
function requestEvent(
eventName: string,
eventData: object,
resultCallback: (result: object) => void,
errorCallback: (error: Error) => void
): Promise<any>;
function requestQuery(
query: string,
resultCallback: (result: object) => void,
errorCallback: (error: Error) => void
): Promise<any>;
function onListeningStarted(callback: () => void): void;
function onListeningFinished(callback: () => void): void;
function onAudioLevel(callback: (level: number) => void): void;
function setContexts(contexts: any[]): void;
function resetContexts(resultCallback: (result: object) => void, errorCallback: (error: Error) => void): void;
function setPermanentContexts(contexts: any[]): void;
}
export namespace Dialogflow_V2 {
const LANG_CHINESE_CHINA = 'zh-CN';
const LANG_CHINESE_HONGKONG: 'zh-HK';
const LANG_CHINESE_TAIWAN: 'zh-TW';
const LANG_DUTCH: 'nl';
const LANG_ENGLISH: 'en';
const LANG_ENGLISH_GB: 'en-GB';
const LANG_ENGLISH_US: 'en-US';
const LANG_FRENCH: 'fr';
const LANG_GERMAN: 'de';
const LANG_ITALIAN: 'it';
const LANG_JAPANESE: 'ja';
const LANG_KOREAN: 'ko';
const LANG_PORTUGUESE: 'pt';
const LANG_PORTUGUESE_BRAZIL: 'pt-BR';
const LANG_RUSSIAN: 'ru';
const LANG_SPANISH: 'es';
const LANG_UKRAINIAN: 'uk';
function setConfiguration(
serviceAccount: string,
privateKey: string,
language: string,
projectId: string
): void;
function startListening(resultCallback: (result: object) => void, errorCallback: (error: Error) => void): void;
function finishListening(): void;
function requestEvent(
eventName: string,
eventData: object,
resultCallback: (result: object) => void,
errorCallback: (error: Error) => void
): Promise<any>;
function requestQuery(
query: string,
resultCallback: (result: object) => void,
errorCallback: (error: Error) => void
): Promise<any>;
function onListeningStarted(callback: () => void): void;
function onListeningFinished(callback: () => void): void;
function onAudioLevel(callback: (level: number) => void): void;
function setContexts(contexts: any[]): void;
function resetContexts(resultCallback: (result: object) => void, errorCallback: (error: Error) => void): void;
function setPermanentContexts(contexts: any[]): void;
}

View File

@@ -0,0 +1,49 @@
import * as React from 'react';
import { View } from 'react-native';
import {
Dialogflow,
Dialogflow_V2,
} from 'react-native-dialogflow';
const accessToken = 'accessToken';
const eventName = 'event';
const eventData = {};
const query = '';
const serviceAccount = '_@_.iam.gserviceaccount.com';
const privateKey = '-----BEGIN PRIVATE KEY-----\n_\n-----END PRIVATE KEY-----';
const projectId = 'projectId';
class Screen1 extends React.Component<any> {
componentDidMount() {
Dialogflow.setConfiguration(accessToken, Dialogflow.LANG_ENGLISH);
Dialogflow.setEntities([]);
Dialogflow.startListening(() => {}, () => {});
Dialogflow.finishListening();
Dialogflow.requestEvent(eventName, eventData, () => {}, () => {});
Dialogflow.requestQuery(query, () => {}, () => {});
Dialogflow.onListeningStarted(() => {});
Dialogflow.onListeningFinished(() => {});
Dialogflow.onAudioLevel(() => {});
Dialogflow.setContexts([]);
Dialogflow.resetContexts(() => {}, () => {});
Dialogflow.setPermanentContexts([]);
Dialogflow_V2.setConfiguration(serviceAccount, privateKey, Dialogflow_V2.LANG_ENGLISH, projectId);
Dialogflow_V2.startListening(() => {}, () => {});
Dialogflow_V2.finishListening();
Dialogflow_V2.requestEvent(eventName, eventData, () => {}, () => {});
Dialogflow_V2.requestQuery(query, () => {}, () => {});
Dialogflow_V2.onListeningStarted(() => {});
Dialogflow_V2.onListeningFinished(() => {});
Dialogflow_V2.onAudioLevel(() => {});
Dialogflow_V2.setContexts([]);
Dialogflow_V2.resetContexts(() => {}, () => {});
Dialogflow_V2.setPermanentContexts([]);
}
render() {
return (
<View />
);
}
}

View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react-native"
},
"files": [
"index.d.ts",
"react-native-dialogflow-tests.tsx"
]}

View File

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