diff --git a/types/react-native-dialogflow/index.d.ts b/types/react-native-dialogflow/index.d.ts new file mode 100644 index 0000000000..c1b663ddb5 --- /dev/null +++ b/types/react-native-dialogflow/index.d.ts @@ -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 +// 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; + function requestQuery( + query: string, + resultCallback: (result: object) => void, + errorCallback: (error: Error) => void + ): Promise; + 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; + function requestQuery( + query: string, + resultCallback: (result: object) => void, + errorCallback: (error: Error) => void + ): Promise; + 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; +} diff --git a/types/react-native-dialogflow/react-native-dialogflow-tests.tsx b/types/react-native-dialogflow/react-native-dialogflow-tests.tsx new file mode 100644 index 0000000000..15b69ffa49 --- /dev/null +++ b/types/react-native-dialogflow/react-native-dialogflow-tests.tsx @@ -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 { + 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 ( + + ); + } +} diff --git a/types/react-native-dialogflow/tsconfig.json b/types/react-native-dialogflow/tsconfig.json new file mode 100644 index 0000000000..6a7fdedb5d --- /dev/null +++ b/types/react-native-dialogflow/tsconfig.json @@ -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" + ]} diff --git a/types/react-native-dialogflow/tslint.json b/types/react-native-dialogflow/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/react-native-dialogflow/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }