├── example ├── .watchmanconfig ├── .gitattributes ├── .babelrc ├── app.json ├── screenshot.png ├── android │ ├── app │ │ ├── src │ │ │ └── main │ │ │ │ ├── res │ │ │ │ ├── values │ │ │ │ │ ├── strings.xml │ │ │ │ │ └── styles.xml │ │ │ │ ├── mipmap-hdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-mdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xhdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ └── mipmap-xxhdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── dialogflowexample │ │ │ │ │ ├── MainActivity.java │ │ │ │ │ └── MainApplication.java │ │ │ │ └── AndroidManifest.xml │ │ ├── BUCK │ │ ├── proguard-rules.pro │ │ └── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── keystores │ │ ├── debug.keystore.properties │ │ └── BUCK │ ├── settings.gradle │ ├── build.gradle │ ├── gradle.properties │ ├── gradlew.bat │ └── gradlew ├── ios │ ├── DialogflowExample │ │ ├── Images.xcassets │ │ │ ├── Contents.json │ │ │ └── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ ├── AppDelegate.h │ │ ├── main.m │ │ ├── AppDelegate.m │ │ ├── Info.plist │ │ └── Base.lproj │ │ │ └── LaunchScreen.xib │ ├── DialogflowExampleTests │ │ ├── Info.plist │ │ └── DialogflowExampleTests.m │ ├── DialogflowExample-tvOSTests │ │ └── Info.plist │ ├── DialogflowExample-tvOS │ │ └── Info.plist │ └── DialogflowExample.xcodeproj │ │ └── xcshareddata │ │ └── xcschemes │ │ ├── DialogflowExample.xcscheme │ │ └── DialogflowExample-tvOS.xcscheme ├── .buckconfig ├── index.js ├── README.md ├── package.json ├── .gitignore ├── .flowconfig ├── App.android.js └── App.ios.js ├── header_img.png ├── .npmignore ├── android ├── src │ └── main │ │ ├── res │ │ ├── values │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ └── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── de │ │ └── innfactory │ │ └── apiai │ │ ├── RNApiAiPackage.java │ │ └── RNApiAiModule.java ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── build.gradle ├── gradlew.bat └── gradlew ├── .gitattributes ├── .buckconfig ├── .travis.yml ├── yarn.lock ├── __tests__ ├── index.ios.js └── index.android.js ├── ios ├── ApiAi │ ├── ApiAi.h │ └── ApiAi.m └── ApiAi.xcodeproj │ └── project.pbxproj ├── react-native-dialogflow.podspec ├── js ├── Errors.js ├── googleAuth │ ├── GoogleAuth.js │ └── postAsForm.js ├── ResetContextsRequest.js ├── Dialogflow.js ├── XhrRequest.js ├── RCTVoice.js └── Dialogflow_V2.js ├── package.json ├── .gitignore ├── LICENSE ├── index.js └── README.md /example/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /example/.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | -------------------------------------------------------------------------------- /header_img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/innFactory/react-native-dialogflow/HEAD/header_img.png -------------------------------------------------------------------------------- /example/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "module:metro-react-native-babel-preset" 4 | ] 5 | } -------------------------------------------------------------------------------- /example/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "DialogflowExample", 3 | "displayName": "DialogflowExample" 4 | } -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | example/ 3 | android/build/ 4 | ios/lib/DerivedData/ 5 | header_img.png 6 | travis.yml -------------------------------------------------------------------------------- /example/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/innFactory/react-native-dialogflow/HEAD/example/screenshot.png -------------------------------------------------------------------------------- /android/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | reactNativeApiAi 3 | 4 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | ios/* linguist-vendored=true 3 | android/* linguist-vendored=true 4 | example/* linguist-vendored=true -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | DialogflowExample 3 | 4 | -------------------------------------------------------------------------------- /example/ios/DialogflowExample/Images.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /.buckconfig: -------------------------------------------------------------------------------- 1 | 2 | [android] 3 | target = Google Inc.:Google APIs:23 4 | 5 | [maven_repositories] 6 | central = https://repo1.maven.org/maven2 7 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/innFactory/react-native-dialogflow/HEAD/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /example/.buckconfig: -------------------------------------------------------------------------------- 1 | 2 | [android] 3 | target = Google Inc.:Google APIs:23 4 | 5 | [maven_repositories] 6 | central = https://repo1.maven.org/maven2 7 | -------------------------------------------------------------------------------- /android/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/innFactory/react-native-dialogflow/HEAD/android/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/innFactory/react-native-dialogflow/HEAD/android/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/innFactory/react-native-dialogflow/HEAD/android/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/innFactory/react-native-dialogflow/HEAD/example/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /example/index.js: -------------------------------------------------------------------------------- 1 | import { AppRegistry } from 'react-native'; 2 | import App from './App'; 3 | 4 | AppRegistry.registerComponent('DialogflowExample', () => App); 5 | -------------------------------------------------------------------------------- /android/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/innFactory/react-native-dialogflow/HEAD/android/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/keystores/debug.keystore.properties: -------------------------------------------------------------------------------- 1 | key.store=debug.keystore 2 | key.alias=androiddebugkey 3 | key.store.password=android 4 | key.alias.password=android 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: android 2 | sudo: required 3 | jdk: oraclejdk8 4 | before_script: cd android 5 | android: 6 | components: 7 | - build-tools-25.0.3 8 | - android-25 -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/innFactory/react-native-dialogflow/HEAD/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/innFactory/react-native-dialogflow/HEAD/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/innFactory/react-native-dialogflow/HEAD/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/innFactory/react-native-dialogflow/HEAD/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/keystores/BUCK: -------------------------------------------------------------------------------- 1 | keystore( 2 | name = "debug", 3 | properties = "debug.keystore.properties", 4 | store = "debug.keystore", 5 | visibility = [ 6 | "PUBLIC", 7 | ], 8 | ) 9 | -------------------------------------------------------------------------------- /android/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 6 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 6 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # Example App 2 | 3 | How to run: 4 | ``` 5 | git clone https://github.com/innFactory/react-native-dialogflow.git 6 | cd react-native-dialogflow/example 7 | npm install 8 | react-native run-android 9 | ``` 10 | 11 | Screenshot 12 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | jsrsasign@^8.0.12: 6 | version "8.0.12" 7 | resolved "https://registry.yarnpkg.com/jsrsasign/-/jsrsasign-8.0.12.tgz#22abb9656d34a30b9530436720835e89c2e5c316" 8 | integrity sha1-Iqu5ZW00owuVMENnIINeicLlwxY= 9 | -------------------------------------------------------------------------------- /__tests__/index.ios.js: -------------------------------------------------------------------------------- 1 | import 'react-native'; 2 | import React from 'react'; 3 | import Index from '../index.ios.js'; 4 | 5 | // Note: test renderer must be required after react-native. 6 | import renderer from 'react-test-renderer'; 7 | 8 | it('renders correctly', () => { 9 | const tree = renderer.create( 10 | 11 | ); 12 | }); 13 | -------------------------------------------------------------------------------- /__tests__/index.android.js: -------------------------------------------------------------------------------- 1 | import 'react-native'; 2 | import React from 'react'; 3 | import Index from '../index.android.js'; 4 | 5 | // Note: test renderer must be required after react-native. 6 | import renderer from 'react-test-renderer'; 7 | 8 | it('renders correctly', () => { 9 | const tree = renderer.create( 10 | 11 | ); 12 | }); 13 | -------------------------------------------------------------------------------- /ios/ApiAi/ApiAi.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #import 4 | #if __has_include("RCTBridgeModule.h") 5 | #import "RCTBridgeModule.h" 6 | #else 7 | #import 8 | #endif 9 | #if __has_include("RCTLog.h") 10 | #import "RCTLog.h" 11 | #else 12 | #import 13 | #endif 14 | 15 | 16 | @interface ApiAi: NSObject 17 | 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'DialogflowExample' 2 | include ':react-native-dialogflow' 3 | project(':react-native-dialogflow').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-dialogflow/android') 4 | include ':react-native-voice' 5 | project(':react-native-voice').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-voice/android') 6 | 7 | include ':app' 8 | -------------------------------------------------------------------------------- /example/ios/DialogflowExample/AppDelegate.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #import 9 | 10 | @interface AppDelegate : UIResponder 11 | 12 | @property (nonatomic, strong) UIWindow *window; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /ios/ApiAi/ApiAi.m: -------------------------------------------------------------------------------- 1 | 2 | 3 | #import "ApiAi.h" 4 | #if __has_include("RCTBridge.h") 5 | #import "RCTBridge.h" 6 | #else 7 | #import 8 | #endif 9 | 10 | @implementation ApiAi 11 | RCT_EXPORT_MODULE(); 12 | 13 | /* 14 | RCT_EXPORT_METHOD(setConfiguration:(NSString *)clientAccessToken languageTag:(NSString *)languageTag) { 15 | 16 | } 17 | 18 | 19 | RCT_EXPORT_METHOD(startListening) { 20 | 21 | } 22 | */ 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /example/ios/DialogflowExample/main.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #import 9 | 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/dialogflowexample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.dialogflowexample; 2 | 3 | import com.facebook.react.ReactActivity; 4 | 5 | public class MainActivity extends ReactActivity { 6 | 7 | /** 8 | * Returns the name of the main component registered from JavaScript. 9 | * This is used to schedule rendering of the component. 10 | */ 11 | @Override 12 | protected String getMainComponentName() { 13 | return "DialogflowExample"; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "DialogflowExample", 3 | "version": "0.0.1", 4 | "private": true, 5 | "scripts": { 6 | "start": "node node_modules/react-native/local-cli/cli.js start", 7 | "test": "jest" 8 | }, 9 | "dependencies": { 10 | "jsrsasign": "^8.0.12", 11 | "react": "16.6.0-alpha.8af6728", 12 | "react-native": "0.57.3", 13 | "react-native-dialogflow": "../" 14 | }, 15 | "devDependencies": { 16 | "metro-react-native-babel-preset": "0.48.1" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /react-native-dialogflow.podspec: -------------------------------------------------------------------------------- 1 | require 'json' 2 | 3 | package = JSON.parse(File.read(File.join(__dir__, 'package.json'))) 4 | 5 | Pod::Spec.new do |spec| 6 | spec.name = package['name'] 7 | spec.version = package['version'] 8 | spec.author = package['author'] 9 | spec.license = package['license'] 10 | spec.homepage = package['repository']['url'] 11 | spec.source = { 12 | :git => "#{package['repository']['url']}.git" 13 | } 14 | spec.summary = package['description'] 15 | spec.source_files = 'ios/**/*.{h,m}' 16 | spec.platform = :ios, '8.0' 17 | spec.dependency 'React' 18 | end 19 | -------------------------------------------------------------------------------- /js/Errors.js: -------------------------------------------------------------------------------- 1 | export class ApiAiBaseError extends Error { 2 | constructor(message) { 3 | super(message); 4 | this.message = message; 5 | this.stack = new Error().stack; 6 | } 7 | } 8 | export class ApiAiClientConfigurationError extends ApiAiBaseError { 9 | constructor(message) { 10 | super(message); 11 | this.name = "ApiAiClientConfigurationError"; 12 | } 13 | } 14 | export class ApiAiRequestError extends ApiAiBaseError { 15 | constructor(message, code = null) { 16 | super(message); 17 | this.message = message; 18 | this.code = code; 19 | this.name = "ApiAiRequestError"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.2.3' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | mavenLocal() 18 | jcenter() 19 | maven { 20 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 21 | url "$rootDir/../node_modules/react-native/android" 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-dialogflow", 3 | "description": "A React-Native Bridge for the Google Dialogflow SDK", 4 | "version": "3.2.2", 5 | "author": "Anton Spöck (https://github.com/spoeck)", 6 | "dependencies": { 7 | "jsrsasign": "^8.0.12" 8 | }, 9 | "keywords": [ 10 | "ai", 11 | "api", 12 | "api-ai", 13 | "api.ai", 14 | "apiai", 15 | "dialogflow", 16 | "google", 17 | "react-native", 18 | "speak", 19 | "text-recognition", 20 | "voice" 21 | ], 22 | "license": "MIT", 23 | "peerDependencies": { 24 | "react-native": ">=0.40.0", 25 | "react-native-voice": ">=0.2.6" 26 | }, 27 | "repository": { 28 | "type": "git", 29 | "url": "https://github.com/innFactory/react-native-dialogflow" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /example/ios/DialogflowExample/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /example/ios/DialogflowExampleTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /example/ios/DialogflowExample-tvOSTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | android.useDeprecatedNdk=true 21 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # Xcode 6 | # 7 | build/ 8 | *.pbxuser 9 | !default.pbxuser 10 | *.mode1v3 11 | !default.mode1v3 12 | *.mode2v3 13 | !default.mode2v3 14 | *.perspectivev3 15 | !default.perspectivev3 16 | xcuserdata 17 | *.xccheckout 18 | *.moved-aside 19 | DerivedData 20 | *.hmap 21 | *.ipa 22 | *.xcuserstate 23 | project.xcworkspace 24 | 25 | # Android/IntelliJ 26 | # 27 | build/ 28 | .idea 29 | .gradle 30 | local.properties 31 | *.iml 32 | 33 | # node.js 34 | # 35 | node_modules/ 36 | npm-debug.log 37 | yarn-error.log 38 | 39 | # BUCK 40 | buck-out/ 41 | \.buckd/ 42 | *.keystore 43 | 44 | # fastlane 45 | # 46 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 47 | # screenshots whenever they are needed. 48 | # For more information about the recommended setup visit: 49 | # https://docs.fastlane.tools/best-practices/source-control/ 50 | 51 | */fastlane/report.xml 52 | */fastlane/Preview.html 53 | */fastlane/screenshots 54 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | header_img.png 2 | 3 | # OSX 4 | # 5 | .DS_Store 6 | 7 | # Xcode 8 | # 9 | build/ 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata 19 | *.xccheckout 20 | *.moved-aside 21 | DerivedData 22 | *.hmap 23 | *.ipa 24 | *.xcuserstate 25 | project.xcworkspace 26 | 27 | # Android/IntelliJ 28 | # 29 | build/ 30 | .idea 31 | .gradle 32 | local.properties 33 | *.iml 34 | 35 | # node.js 36 | # 37 | node_modules/ 38 | npm-debug.log 39 | yarn-error.log 40 | 41 | # BUCK 42 | buck-out/ 43 | \.buckd/ 44 | *.keystore 45 | 46 | # fastlane 47 | # 48 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 49 | # screenshots whenever they are needed. 50 | # For more information about the recommended setup visit: 51 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 52 | 53 | fastlane/report.xml 54 | fastlane/Preview.html 55 | fastlane/screenshots 56 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 innFactory 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 13 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /android/src/main/java/de/innfactory/apiai/RNApiAiPackage.java: -------------------------------------------------------------------------------- 1 | package de.innfactory.apiai; 2 | 3 | 4 | import com.facebook.react.ReactPackage; 5 | import com.facebook.react.bridge.JavaScriptModule; 6 | import com.facebook.react.bridge.NativeModule; 7 | import com.facebook.react.bridge.ReactApplicationContext; 8 | import com.facebook.react.uimanager.ViewManager; 9 | 10 | import java.lang.reflect.Array; 11 | import java.util.ArrayList; 12 | import java.util.Collections; 13 | import java.util.List; 14 | 15 | 16 | /** 17 | * Created by Anton Spöck on 2017-07-21 18 | **/ 19 | public class RNApiAiPackage implements ReactPackage{ 20 | 21 | public List> createJSModules() { 22 | return Collections.emptyList(); 23 | } 24 | 25 | @Override 26 | public List createViewManagers(ReactApplicationContext reactContext) { 27 | return Collections.emptyList(); 28 | } 29 | 30 | 31 | @Override 32 | public List createNativeModules( 33 | ReactApplicationContext reactContext) { 34 | List modules = new ArrayList<>(); 35 | 36 | modules.add(new RNApiAiModule(reactContext)); 37 | 38 | return modules; 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /example/ios/DialogflowExample/AppDelegate.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #import "AppDelegate.h" 9 | 10 | #import 11 | #import 12 | 13 | @implementation AppDelegate 14 | 15 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 16 | { 17 | NSURL *jsCodeLocation; 18 | 19 | jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil]; 20 | 21 | RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation 22 | moduleName:@"DialogflowExample" 23 | initialProperties:nil 24 | launchOptions:launchOptions]; 25 | rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1]; 26 | 27 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 28 | UIViewController *rootViewController = [UIViewController new]; 29 | rootViewController.view = rootView; 30 | self.window.rootViewController = rootViewController; 31 | [self.window makeKeyAndVisible]; 32 | return YES; 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/dialogflowexample/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.dialogflowexample; 2 | 3 | import android.app.Application; 4 | 5 | import com.facebook.react.ReactApplication; 6 | import de.innfactory.apiai.RNApiAiPackage; 7 | import com.wenkesj.voice.VoicePackage; 8 | import com.facebook.react.ReactNativeHost; 9 | import com.facebook.react.ReactPackage; 10 | import com.facebook.react.shell.MainReactPackage; 11 | import com.facebook.soloader.SoLoader; 12 | 13 | import java.util.Arrays; 14 | import java.util.List; 15 | 16 | public class MainApplication extends Application implements ReactApplication { 17 | 18 | private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { 19 | @Override 20 | public boolean getUseDeveloperSupport() { 21 | return BuildConfig.DEBUG; 22 | } 23 | 24 | @Override 25 | protected List getPackages() { 26 | return Arrays.asList( 27 | new MainReactPackage(), 28 | new RNApiAiPackage(), 29 | new VoicePackage() 30 | ); 31 | } 32 | 33 | @Override 34 | protected String getJSMainModuleName() { 35 | return "index"; 36 | } 37 | }; 38 | 39 | @Override 40 | public ReactNativeHost getReactNativeHost() { 41 | return mReactNativeHost; 42 | } 43 | 44 | @Override 45 | public void onCreate() { 46 | super.onCreate(); 47 | SoLoader.init(this, /* native exopackage */ false); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /example/.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | ; We fork some components by platform 3 | .*/*[.]android.js 4 | 5 | ; Ignore "BUCK" generated dirs 6 | /\.buckd/ 7 | 8 | ; Ignore unexpected extra "@providesModule" 9 | .*/node_modules/.*/node_modules/fbjs/.* 10 | 11 | ; Ignore duplicate module providers 12 | ; For RN Apps installed via npm, "Libraries" folder is inside 13 | ; "node_modules/react-native" but in the source repo it is in the root 14 | .*/Libraries/react-native/React.js 15 | 16 | ; Ignore polyfills 17 | .*/Libraries/polyfills/.* 18 | 19 | ; Ignore metro 20 | .*/node_modules/metro/.* 21 | 22 | [include] 23 | 24 | [libs] 25 | node_modules/react-native/Libraries/react-native/react-native-interface.js 26 | node_modules/react-native/flow/ 27 | node_modules/react-native/flow-github/ 28 | 29 | [options] 30 | emoji=true 31 | 32 | module.system=haste 33 | 34 | munge_underscores=true 35 | 36 | module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub' 37 | 38 | module.file_ext=.js 39 | module.file_ext=.jsx 40 | module.file_ext=.json 41 | module.file_ext=.native.js 42 | 43 | suppress_type=$FlowIssue 44 | suppress_type=$FlowFixMe 45 | suppress_type=$FlowFixMeProps 46 | suppress_type=$FlowFixMeState 47 | 48 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) 49 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ 50 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy 51 | suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError 52 | 53 | [version] 54 | ^0.65.0 55 | -------------------------------------------------------------------------------- /js/googleAuth/GoogleAuth.js: -------------------------------------------------------------------------------- 1 | var rs = require('jsrsasign'); 2 | import postAsForm from './postAsForm'; 3 | 4 | 5 | const encodeJWT = function (options) { 6 | 7 | if (!options) { throw new Error('options is required'); } 8 | if (!options.email) { throw new Error('options.email is required'); } 9 | if (!options.scopes) { throw new Error('options.scopes is required'); } 10 | if (!Array.isArray(options.scopes)) { throw new Error('options.scopes must be an array'); } 11 | if (options.scopes.length === 0) { throw new Error('options.scopes must contain at least one scope'); } 12 | if (!options.key) { throw new Error('options.key is required'); } 13 | 14 | 15 | var iat = Math.floor(new Date().getTime() / 1000), 16 | exp = iat + Math.floor((options.expiration || 60 * 60 * 1000) / 1000), 17 | claims = { 18 | iss: options.email, 19 | scope: options.scopes.join(' '), 20 | aud: 'https://accounts.google.com/o/oauth2/token', 21 | exp: exp, 22 | iat: iat, 23 | sub: null 24 | }; 25 | 26 | if (options.delegationEmail) { 27 | claims.sub = options.delegationEmail; 28 | } 29 | 30 | // Sign JWT 31 | var sHeader = JSON.stringify({ alg: 'RS256', typ: 'JWT' }); 32 | return rs.jws.JWS.sign("RS256", sHeader, JSON.stringify(claims), options.key); 33 | } 34 | 35 | const authenticate = async (email, key, scopes) => { 36 | 37 | const json = await postAsForm('https://accounts.google.com/o/oauth2/token', 38 | { 39 | grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer', 40 | assertion: encodeJWT({ email, key, scopes }) 41 | }); 42 | 43 | return JSON.parse(json).access_token; 44 | } 45 | 46 | export default authenticate; -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | 4 | repositories { 5 | mavenLocal() 6 | mavenCentral() 7 | 8 | maven { url "https://oss.sonatype.org/content/repositories/snapshots" } 9 | } 10 | 11 | buildscript { 12 | repositories { 13 | jcenter() 14 | } 15 | dependencies { 16 | classpath 'com.android.tools.build:gradle:2.2.3' 17 | 18 | // NOTE: Do not place your application dependencies here; they belong 19 | // in the individual module build.gradle files 20 | } 21 | } 22 | 23 | 24 | android { 25 | compileSdkVersion 25 26 | buildToolsVersion "25.0.3" 27 | 28 | defaultConfig { 29 | minSdkVersion 16 30 | targetSdkVersion 22 31 | versionCode 1 32 | versionName "1.0" 33 | } 34 | lintOptions { 35 | abortOnError false 36 | warning 'InvalidPackage' 37 | } 38 | 39 | packagingOptions { 40 | exclude 'META-INF/DEPENDENCIES.txt' 41 | exclude 'META-INF/LICENSE.txt' 42 | exclude 'META-INF/NOTICE.txt' 43 | exclude 'META-INF/NOTICE' 44 | exclude 'META-INF/LICENSE' 45 | exclude 'META-INF/DEPENDENCIES' 46 | exclude 'META-INF/notice.txt' 47 | exclude 'META-INF/license.txt' 48 | exclude 'META-INF/dependencies.txt' 49 | exclude 'META-INF/LGPL2.1' 50 | } 51 | 52 | } 53 | 54 | 55 | 56 | 57 | dependencies { 58 | compile "com.facebook.react:react-native:+" 59 | compile fileTree(dir: 'libs', include: ['*.jar']) 60 | compile 'com.android.support:appcompat-v7:23.2.1' 61 | compile 'ai.api:sdk:2.0.7@aar' 62 | compile 'com.google.code.gson:gson:2.3' 63 | compile 'commons-io:commons-io:2.4' 64 | compile('ai.api:libai:1.4.8') { 65 | exclude module: 'log4j-core' 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /js/ResetContextsRequest.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by toni on 30.08.2017. 3 | */ 4 | import { ApiAiRequestError } from "./Errors"; 5 | import XhrRequest from './XhrRequest'; 6 | export const DEFAULT_BASE_URL = "https://api.api.ai/v1/"; 7 | 8 | 9 | class ResetContextsRequest { 10 | constructor(accessToken, sessionId, contextName) { 11 | 12 | if (contextName != null) { 13 | this.uri = DEFAULT_BASE_URL + "contexts/" + contextName + "?sessionId=" + sessionId; 14 | } else { 15 | this.uri = DEFAULT_BASE_URL + "contexts?sessionId=" + sessionId; 16 | } 17 | 18 | this.headers = { 19 | Authorization: "Bearer " + accessToken, 20 | Accept: "application/json", 21 | }; 22 | } 23 | static handleSuccess(xhr) { 24 | return Promise.resolve(JSON.parse(xhr.responseText)); 25 | } 26 | static handleError(xhr) { 27 | let error = new ApiAiRequestError(null); 28 | try { 29 | const serverResponse = JSON.parse(xhr.responseText); 30 | if (serverResponse.status && serverResponse.status.errorDetails) { 31 | error = new ApiAiRequestError(serverResponse.status.errorDetails, serverResponse.status.code); 32 | } 33 | else { 34 | error = new ApiAiRequestError(xhr.statusText, xhr.status); 35 | } 36 | } 37 | catch (e) { 38 | error = new ApiAiRequestError(xhr.statusText, xhr.status); 39 | } 40 | return Promise.reject(error); 41 | } 42 | perform() { 43 | return XhrRequest.delete(this.uri, null, this.headers, {}) 44 | .then(ResetContextsRequest.handleSuccess.bind(this)) 45 | .catch(ResetContextsRequest.handleError.bind(this)); 46 | } 47 | } 48 | export default ResetContextsRequest; -------------------------------------------------------------------------------- /example/ios/DialogflowExample-tvOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UIViewControllerBasedStatusBarAppearance 38 | 39 | NSLocationWhenInUseUsageDescription 40 | 41 | NSAppTransportSecurity 42 | 43 | 44 | NSExceptionDomains 45 | 46 | localhost 47 | 48 | NSExceptionAllowsInsecureHTTPLoads 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /example/android/app/BUCK: -------------------------------------------------------------------------------- 1 | # To learn about Buck see [Docs](https://buckbuild.com/). 2 | # To run your application with Buck: 3 | # - install Buck 4 | # - `npm start` - to start the packager 5 | # - `cd android` 6 | # - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"` 7 | # - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck 8 | # - `buck install -r android/app` - compile, install and run application 9 | # 10 | 11 | lib_deps = [] 12 | 13 | for jarfile in glob(['libs/*.jar']): 14 | name = 'jars__' + jarfile[jarfile.rindex('/') + 1: jarfile.rindex('.jar')] 15 | lib_deps.append(':' + name) 16 | prebuilt_jar( 17 | name = name, 18 | binary_jar = jarfile, 19 | ) 20 | 21 | for aarfile in glob(['libs/*.aar']): 22 | name = 'aars__' + aarfile[aarfile.rindex('/') + 1: aarfile.rindex('.aar')] 23 | lib_deps.append(':' + name) 24 | android_prebuilt_aar( 25 | name = name, 26 | aar = aarfile, 27 | ) 28 | 29 | android_library( 30 | name = "all-libs", 31 | exported_deps = lib_deps, 32 | ) 33 | 34 | android_library( 35 | name = "app-code", 36 | srcs = glob([ 37 | "src/main/java/**/*.java", 38 | ]), 39 | deps = [ 40 | ":all-libs", 41 | ":build_config", 42 | ":res", 43 | ], 44 | ) 45 | 46 | android_build_config( 47 | name = "build_config", 48 | package = "com.dialogflowexample", 49 | ) 50 | 51 | android_resource( 52 | name = "res", 53 | package = "com.dialogflowexample", 54 | res = "src/main/res", 55 | ) 56 | 57 | android_binary( 58 | name = "app", 59 | keystore = "//android/keystores:debug", 60 | manifest = "src/main/AndroidManifest.xml", 61 | package_type = "debug", 62 | deps = [ 63 | ":app-code", 64 | ], 65 | ) 66 | -------------------------------------------------------------------------------- /example/ios/DialogflowExample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | DialogflowExample 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSRequiresIPhoneOS 26 | 27 | NSLocationWhenInUseUsageDescription 28 | 29 | UILaunchStoryboardName 30 | LaunchScreen 31 | UIRequiredDeviceCapabilities 32 | 33 | armv7 34 | 35 | UISupportedInterfaceOrientations 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationLandscapeLeft 39 | UIInterfaceOrientationLandscapeRight 40 | 41 | UIViewControllerBasedStatusBarAppearance 42 | 43 | NSLocationWhenInUseUsageDescription 44 | 45 | NSAppTransportSecurity 46 | 47 | 48 | NSAllowsArbitraryLoads 49 | 50 | NSExceptionDomains 51 | 52 | localhost 53 | 54 | NSExceptionAllowsInsecureHTTPLoads 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /example/ios/DialogflowExampleTests/DialogflowExampleTests.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #import 9 | #import 10 | 11 | #import 12 | #import 13 | 14 | #define TIMEOUT_SECONDS 600 15 | #define TEXT_TO_LOOK_FOR @"Welcome to React Native!" 16 | 17 | @interface DialogflowExampleTests : XCTestCase 18 | 19 | @end 20 | 21 | @implementation DialogflowExampleTests 22 | 23 | - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test 24 | { 25 | if (test(view)) { 26 | return YES; 27 | } 28 | for (UIView *subview in [view subviews]) { 29 | if ([self findSubviewInView:subview matching:test]) { 30 | return YES; 31 | } 32 | } 33 | return NO; 34 | } 35 | 36 | - (void)testRendersWelcomeScreen 37 | { 38 | UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController]; 39 | NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS]; 40 | BOOL foundElement = NO; 41 | 42 | __block NSString *redboxError = nil; 43 | RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) { 44 | if (level >= RCTLogLevelError) { 45 | redboxError = message; 46 | } 47 | }); 48 | 49 | while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) { 50 | [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 51 | [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 52 | 53 | foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) { 54 | if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) { 55 | return YES; 56 | } 57 | return NO; 58 | }]; 59 | } 60 | 61 | RCTSetLogFunction(RCTDefaultLogFunction); 62 | 63 | XCTAssertNil(redboxError, @"RedBox error: %@", redboxError); 64 | XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS); 65 | } 66 | 67 | 68 | @end 69 | -------------------------------------------------------------------------------- /js/googleAuth/postAsForm.js: -------------------------------------------------------------------------------- 1 | export default async function postAsForm(url, data) { 2 | var response; 3 | try { 4 | 5 | //array that holds the items that get added into the form 6 | var form = []; 7 | 8 | //special handling for object/array data, arrays will use "model" as the container ns 9 | addItemsToForm(form, typeof data == 'object' ? [] : [options.name || 'model'], data); 10 | 11 | //you'll need to await on response.text/blob/json etc 12 | var response = await fetch(url, { 13 | method: 'post', 14 | headers: { 15 | 'Accept': 'application/json, application/xml, text/play, text/html, *.*', 16 | 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8' 17 | }, 18 | body: form.join('&') 19 | }); 20 | 21 | //return plain text as-is, don't parse it here 22 | return await response.text(); 23 | } catch (err) { 24 | //console.error("Error from server:", err && err.stack || err); 25 | err.response = response; 26 | throw err; 27 | } 28 | } 29 | 30 | function addItemsToForm(form, names, obj) { 31 | if (obj === undefined || obj === "" || obj === null) return addItemToForm(form, names, ""); 32 | 33 | if ( 34 | typeof obj == "string" 35 | || typeof obj == "number" 36 | || obj === true 37 | || obj === false 38 | ) return addItemToForm(form, names, obj); 39 | 40 | if (obj instanceof Date) return addItemToForm(form, names, obj.toJSON()); 41 | 42 | // array or otherwise array-like 43 | if (obj instanceof Array) { 44 | return obj.forEach((v, i) => { 45 | names.push(`[${i}]`); 46 | addItemsToForm(form, names, v); 47 | names.pop(); 48 | }); 49 | } 50 | 51 | if (typeof obj === "object") { 52 | return Object.keys(obj).forEach((k) => { 53 | names.push(k); 54 | addItemsToForm(form, names, obj[k]); 55 | names.pop(); 56 | }); 57 | } 58 | } 59 | 60 | function addItemToForm(form, names, value) { 61 | var name = encodeURIComponent(names.join('.').replace(/\.\[/g, '[')); 62 | value = encodeURIComponent(value.toString()); 63 | form.push(`${name}=${value}`); 64 | } 65 | -------------------------------------------------------------------------------- /android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /example/android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /example/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Disabling obfuscation is useful if you collect stack traces from production crashes 20 | # (unless you are using a system that supports de-obfuscate the stack traces). 21 | -dontobfuscate 22 | 23 | # React Native 24 | 25 | # Keep our interfaces so they can be used by other ProGuard rules. 26 | # See http://sourceforge.net/p/proguard/bugs/466/ 27 | -keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip 28 | -keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters 29 | -keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip 30 | 31 | # Do not strip any method/class that is annotated with @DoNotStrip 32 | -keep @com.facebook.proguard.annotations.DoNotStrip class * 33 | -keep @com.facebook.common.internal.DoNotStrip class * 34 | -keepclassmembers class * { 35 | @com.facebook.proguard.annotations.DoNotStrip *; 36 | @com.facebook.common.internal.DoNotStrip *; 37 | } 38 | 39 | -keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * { 40 | void set*(***); 41 | *** get*(); 42 | } 43 | 44 | -keep class * extends com.facebook.react.bridge.JavaScriptModule { *; } 45 | -keep class * extends com.facebook.react.bridge.NativeModule { *; } 46 | -keepclassmembers,includedescriptorclasses class * { native ; } 47 | -keepclassmembers class * { @com.facebook.react.uimanager.UIProp ; } 48 | -keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactProp ; } 49 | -keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactPropGroup ; } 50 | 51 | -dontwarn com.facebook.react.** 52 | 53 | # TextLayoutBuilder uses a non-public Android constructor within StaticLayout. 54 | # See libs/proxy/src/main/java/com/facebook/fbui/textlayoutbuilder/proxy for details. 55 | -dontwarn android.text.StaticLayout 56 | 57 | # okhttp 58 | 59 | -keepattributes Signature 60 | -keepattributes *Annotation* 61 | -keep class okhttp3.** { *; } 62 | -keep interface okhttp3.** { *; } 63 | -dontwarn okhttp3.** 64 | 65 | # okio 66 | 67 | -keep class sun.misc.Unsafe { *; } 68 | -dontwarn java.nio.file.* 69 | -dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement 70 | -dontwarn okio.** 71 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import { NativeAppEventEmitter } from 'react-native'; 4 | import { Dialogflow } from './js/Dialogflow'; 5 | import { Dialogflow_V2 } from './js/Dialogflow_V2'; 6 | import Voice from './js/RCTVoice'; 7 | 8 | /** 9 | * DIALOGFLOW V1 10 | */ 11 | var dialogflow = new Dialogflow(); 12 | 13 | dialogflow.setConfiguration = function (accessToken, languageTag) { 14 | dialogflow.accessToken = accessToken; 15 | dialogflow.languageTag = languageTag; 16 | dialogflow.sessionId = dialogflow.sessionId ? dialogflow.sessionId : dialogflow.guid(); 17 | 18 | Voice.onSpeechStart = () => (c) => dialogflow.onListeningStarted(c); 19 | Voice.onSpeechEnd = () => (c) => dialogflow.onListeningFinished(c); 20 | } 21 | 22 | dialogflow.startListening = function (onResult, onError) { 23 | 24 | dialogflow.subscription = NativeAppEventEmitter.addListener( 25 | 'onSpeechResults', 26 | (result) => { 27 | if (result.value) { 28 | dialogflow.requestQuery(result.value[0], onResult, onError); 29 | } 30 | 31 | } 32 | ); 33 | 34 | Voice.start(dialogflow.languageTag); 35 | } 36 | 37 | dialogflow.finishListening = function () { 38 | Voice.stop(); 39 | } 40 | 41 | export default dialogflow; 42 | 43 | 44 | /** 45 | * DIALOGFLOW V2 46 | */ 47 | var dialogflow2 = new Dialogflow_V2(); 48 | 49 | dialogflow2.setConfiguration = async function (clientEmail, privateKey, languageTag, projectId) { 50 | dialogflow2.accessToken = await dialogflow2.generateAccessToken(clientEmail, privateKey); 51 | dialogflow2.languageTag = languageTag; 52 | dialogflow2.projectId = projectId; 53 | dialogflow2.sessionId = dialogflow2.sessionId ? dialogflow2.sessionId : dialogflow2.guid(); 54 | 55 | // set listeners 56 | Voice.onSpeechStart = (c) => { 57 | dialogflow2.speechResult = null; 58 | if (dialogflow2.onListeningStarted) { 59 | dialogflow2.onListeningStarted(c); 60 | } 61 | } 62 | 63 | Voice.onSpeechEnd = (c) => { 64 | 65 | if (dialogflow2.speechResult) { 66 | dialogflow2.requestQuery(dialogflow2.speechResult[0], dialogflow2.onResult, dialogflow2.onError); 67 | } 68 | 69 | if (dialogflow2.onListeningFinished) { 70 | dialogflow2.onListeningFinished(c); 71 | } 72 | } 73 | 74 | Voice.onSpeechVolumeChanged = (c) => { 75 | if (dialogflow2.onAudioLevel) { 76 | dialogflow2.onAudioLevel(c); 77 | } 78 | } 79 | 80 | Voice.onSpeechResults = (result) => { 81 | if (result.value) { 82 | dialogflow2.speechResult = result.value; 83 | } 84 | } 85 | } 86 | 87 | dialogflow2.startListening = function (onResult, onError) { 88 | dialogflow2.onResult = onResult; 89 | dialogflow2.onError = onError; 90 | 91 | Voice.start(dialogflow2.languageTag); 92 | } 93 | 94 | dialogflow2.finishListening = function () { 95 | Voice.stop(); 96 | } 97 | 98 | export { dialogflow2 as Dialogflow_V2 }; 99 | 100 | -------------------------------------------------------------------------------- /example/ios/DialogflowExample/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 21 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /js/Dialogflow.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import { NativeModules, NativeAppEventEmitter } from 'react-native'; 4 | import requestEvent from './ResetContextsRequest'; 5 | import ResetContextsRequest from './ResetContextsRequest'; 6 | export const DEFAULT_BASE_URL = "https://api.api.ai/v1/"; 7 | export const DEFAULT_API_VERSION = "20150910"; 8 | 9 | export class Dialogflow { 10 | 11 | onListeningStarted(callback) { 12 | callback(); 13 | } 14 | 15 | onListeningCanceled(callback) { 16 | callback(); 17 | } 18 | 19 | onListeningFinished(callback) { 20 | callback(); 21 | } 22 | 23 | setContexts(contexts) { 24 | this.contexts = contexts; 25 | } 26 | 27 | setPermanentContexts(contexts) { 28 | // set lifespan to 1 if it's not set 29 | contexts.forEach((c, i, a) => { 30 | if (!c.lifespan) { 31 | a[i] = { ...c, lifespan: 1 }; 32 | } 33 | }); 34 | 35 | this.permanentContexts = contexts; 36 | } 37 | 38 | setEntities(entities) { 39 | this.entities = entities; 40 | } 41 | 42 | onAudioLevel(callback) { 43 | 44 | } 45 | 46 | requestEvent = async (eventName, eventData, onResult, onError) => { 47 | 48 | const data = { 49 | "event": { 50 | "name": eventName, 51 | "data": { 52 | ...eventData 53 | } 54 | }, 55 | 'lang': this.languageTag, 56 | "sessionId": this.sessionId 57 | }; 58 | 59 | fetch(DEFAULT_BASE_URL + "query?v=" + DEFAULT_API_VERSION, { 60 | method: "POST", 61 | headers: { 62 | 'Content-Type': 'application/json; charset=utf-8', 63 | 'Authorization': 'Bearer ' + this.accessToken, 64 | 'charset': "utf-8" 65 | }, 66 | body: JSON.stringify(data) 67 | }) 68 | .then(function (response) { 69 | var json = response.json().then(onResult) 70 | }) 71 | .catch(onError); 72 | }; 73 | 74 | requestQuery = async (query, onResult, onError) => { 75 | 76 | const data = { 77 | "contexts": this.mergeContexts(this.contexts, this.permanentContexts), 78 | "query": query, 79 | 'lang': this.languageTag, 80 | "sessionId": this.sessionId.toString() 81 | }; 82 | 83 | this.contexts = null; 84 | this.entities = null; 85 | 86 | fetch(DEFAULT_BASE_URL + "query?v=" + DEFAULT_API_VERSION, { 87 | method: "POST", 88 | headers: { 89 | 'Content-Type': 'application/json; charset=utf-8', 90 | 'Authorization': 'Bearer ' + this.accessToken, 91 | 'charset': "utf-8" 92 | }, 93 | body: JSON.stringify(data) 94 | }) 95 | .then(function (response) { 96 | var json = response.json().then(onResult) 97 | }) 98 | .catch(onError); 99 | }; 100 | 101 | mergeContexts(context1, context2) { 102 | if (!context1) { 103 | return context2; 104 | } else if (!context2) { 105 | return context1; 106 | } else { 107 | return [...context1, ...context2]; 108 | } 109 | } 110 | 111 | resetContexts(onResult, onError) { 112 | let request = new ResetContextsRequest(this.accessToken, this.sessionId, null); 113 | request.perform().then(res => onResult(res)).catch(err => onError(err)); 114 | }; 115 | 116 | /** 117 | * generates new random UUID 118 | * @returns {string} 119 | */ 120 | guid() { 121 | const s4 = () => Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1); 122 | return s4() + s4() + "-" + s4() + "-" + s4() + "-" + 123 | s4() + "-" + s4() + s4() + s4(); 124 | } 125 | 126 | 127 | LANG_CHINESE_CHINA = "zh-CN"; 128 | LANG_CHINESE_HONGKONG = "zh-HK"; 129 | LANG_CHINESE_TAIWAN = "zh-TW"; 130 | LANG_DUTCH = "nl"; 131 | LANG_ENGLISH = "en"; 132 | LANG_ENGLISH_GB = "en-GB"; 133 | LANG_ENGLISH_US = "en-US"; 134 | LANG_FRENCH = "fr"; 135 | LANG_GERMAN = "de"; 136 | LANG_ITALIAN = "it"; 137 | LANG_JAPANESE = "ja"; 138 | LANG_KOREAN = "ko"; 139 | LANG_PORTUGUESE = "pt"; 140 | LANG_PORTUGUESE_BRAZIL = "pt-BR"; 141 | LANG_RUSSIAN = "ru"; 142 | LANG_SPANISH = "es"; 143 | LANG_UKRAINIAN = "uk"; 144 | } 145 | 146 | -------------------------------------------------------------------------------- /js/XhrRequest.js: -------------------------------------------------------------------------------- 1 | /** 2 | * quick ts implementation of example from 3 | * https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise 4 | * with some minor improvements 5 | * @todo: test (?) 6 | * @todo: add node.js implementation with node's http inside. Just to make SDK cross-platform 7 | */ 8 | class XhrRequest { 9 | // Method that performs the ajax request 10 | static ajax(method, url, args = null, headers = null, options = {}) { 11 | // Creating a promise 12 | return new Promise((resolve, reject) => { 13 | // Instantiates the XMLHttpRequest 14 | const client = XhrRequest.createXMLHTTPObject(); 15 | let uri = url; 16 | let payload = null; 17 | // Add given payload to get request 18 | if (args && (method === XhrRequest.Method.GET)) { 19 | uri += "?"; 20 | let argcount = 0; 21 | for (const key in args) { 22 | if (args.hasOwnProperty(key)) { 23 | if (argcount++) { 24 | uri += "&"; 25 | } 26 | uri += encodeURIComponent(key) + "=" + encodeURIComponent(args[key]); 27 | } 28 | } 29 | } 30 | else if (args) { 31 | if (!headers) { 32 | headers = {}; 33 | } 34 | headers["Content-Type"] = "application/json; charset=utf-8"; 35 | payload = JSON.stringify(args); 36 | } 37 | for (const key in options) { 38 | if (key in client) { 39 | client[key] = options[key]; 40 | } 41 | } 42 | // hack: method[method] is somewhat like .toString for enum Method 43 | // should be made in normal way 44 | client.open(XhrRequest.Method[method], uri, true); 45 | // Add given headers 46 | if (headers) { 47 | for (const key in headers) { 48 | if (headers.hasOwnProperty(key)) { 49 | client.setRequestHeader(key, headers[key]); 50 | } 51 | } 52 | } 53 | payload ? client.send(payload) : client.send(); 54 | client.onload = () => { 55 | if (client.status >= 200 && client.status < 300) { 56 | // Performs the function "resolve" when this.status is equal to 2xx 57 | resolve(client); 58 | } 59 | else { 60 | // Performs the function "reject" when this.status is different than 2xx 61 | reject(client); 62 | } 63 | }; 64 | client.onerror = () => { 65 | reject(client); 66 | }; 67 | }); 68 | } 69 | static get(url, payload = null, headers = null, options = {}) { 70 | return XhrRequest.ajax(XhrRequest.Method.GET, url, payload, headers, options); 71 | } 72 | static post(url, payload = null, headers = null, options = {}) { 73 | return XhrRequest.ajax(XhrRequest.Method.POST, url, payload, headers, options); 74 | } 75 | static put(url, payload = null, headers = null, options = {}) { 76 | return XhrRequest.ajax(XhrRequest.Method.PUT, url, payload, headers, options); 77 | } 78 | static delete(url, payload = null, headers = null, options = {}) { 79 | return XhrRequest.ajax(XhrRequest.Method.DELETE, url, payload, headers, options); 80 | } 81 | static createXMLHTTPObject() { 82 | let xmlhttp = null; 83 | for (const i of XhrRequest.XMLHttpFactories) { 84 | try { 85 | xmlhttp = i(); 86 | } 87 | catch (e) { 88 | continue; 89 | } 90 | break; 91 | } 92 | return xmlhttp; 93 | } 94 | } 95 | XhrRequest.XMLHttpFactories = [ 96 | () => new XMLHttpRequest(), 97 | () => new window["ActiveXObject"]("Msxml2.XMLHTTP"), 98 | () => new window["ActiveXObject"]("Msxml3.XMLHTTP"), 99 | () => new window["ActiveXObject"]("Microsoft.XMLHTTP") 100 | ]; 101 | (function (XhrRequest) { 102 | let Method; 103 | (function (Method) { 104 | Method[Method["GET"] = "GET"] = "GET"; 105 | Method[Method["POST"] = "POST"] = "POST"; 106 | Method[Method["PUT"] = "PUT"] = "PUT"; 107 | Method[Method["DELETE"] = "DELETE"] = "DELETE"; 108 | })(Method = XhrRequest.Method || (XhrRequest.Method = {})); 109 | })(XhrRequest || (XhrRequest = {})); 110 | export default XhrRequest; 111 | -------------------------------------------------------------------------------- /example/App.android.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import { AppRegistry, Button, StyleSheet, Text, View } from 'react-native'; 3 | import Dialogflow, { Dialogflow_V2 } from "react-native-dialogflow"; 4 | 5 | 6 | export default class App extends Component { 7 | constructor(props) { 8 | super(props); 9 | 10 | this.state = { 11 | result: "", 12 | listeningState: "not started", 13 | audioLevel: 0, 14 | }; 15 | 16 | 17 | Dialogflow.setConfiguration( 18 | "3242_your_token_2344454", Dialogflow.LANG_GERMAN 19 | ); 20 | 21 | Dialogflow_V2.setConfiguration( 22 | "reasdfsdfdf@asdf-76866.iam.gserviceaccount.com", 23 | '-----BEGIN PRIVATE KEY-----\nMIIEvgIBADAN...1oqO\n-----END PRIVATE KEY-----\n', 24 | Dialogflow_V2.LANG_GERMAN, 25 | 'testv2-3b5ca' 26 | ); 27 | 28 | 29 | 30 | const contexts = [{ 31 | "name": "deals", 32 | "lifespan": 1, 33 | "parameters": { 34 | "name": "Sam" 35 | } 36 | }]; 37 | 38 | 39 | 40 | Dialogflow.setContexts(contexts); 41 | Dialogflow_V2.setContexts(contexts); 42 | 43 | 44 | const permanentContexts = [{ 45 | "name": "config", 46 | "parameters": { 47 | "access_token": "42 yo 42 tiny rick" 48 | } 49 | }]; 50 | 51 | 52 | Dialogflow.setPermanentContexts(permanentContexts); 53 | Dialogflow_V2.setPermanentContexts(permanentContexts); 54 | 55 | 56 | const entities = [{ 57 | "name": "shop", 58 | "extend": true, 59 | "entries": [ 60 | { 61 | "value": "Media Markt", 62 | "synonyms": [ 63 | "Media Markt", 64 | ] 65 | } 66 | ] 67 | }]; 68 | 69 | 70 | Dialogflow.setEntities(entities); 71 | Dialogflow_V2.setEntities(entities); 72 | } 73 | 74 | 75 | render() { 76 | Dialogflow.requestEvent("WELCOME", null, r => console.log(r), e => console.log(e)); 77 | Dialogflow_V2.requestEvent("WELCOME", null, r => console.log(r), e => console.log(e)); 78 | 79 | 80 | return ( 81 | 82 | 83 | 84 | {"Listening State: " + this.state.listeningState} 85 | {"Audio Level: " + this.state.audioLevel} 86 | {"Result: " + this.state.result} 87 | 88 | 89 |