1+ import React , { Component } from 'react' ;
2+ import {
3+ AppRegistry ,
4+ StyleSheet ,
5+ Text ,
6+ View ,
7+ Button
8+ } from 'react-native' ;
9+
10+ import Dialogflow from "react-native-dialogflow"
11+
12+ export default class App extends Component {
13+ constructor ( props ) {
14+ super ( props ) ;
15+
16+ this . state = {
17+ result : "" ,
18+ listeningState : "not started" ,
19+ audioLevel : 0 ,
20+ } ;
21+
22+
23+ Dialogflow . setConfiguration (
24+ "57b6ce865e6e4b138a74a88cfd8bc526" , Dialogflow . LANG_GERMAN
25+ ) ;
26+
27+
28+
29+ const contexts = [ {
30+ "name" : "deals" ,
31+ "lifespan" : 1 ,
32+ "parameters" : {
33+ "name" : "Sam"
34+ }
35+ } ] ;
36+
37+ Dialogflow . setContexts ( contexts ) ;
38+
39+
40+ const permanentContexts = [ {
41+ "name" : "config" ,
42+ "parameters" : {
43+ "access_token" : "42 yo 42 tiny rick"
44+ }
45+ } ] ;
46+
47+ Dialogflow . setPermanentContexts ( permanentContexts ) ;
48+
49+
50+ const entities = [ {
51+ "name" : "shop" ,
52+ "extend" : true ,
53+ "entries" : [
54+ {
55+ "value" : "Media Markt" ,
56+ "synonyms" : [
57+ "Media Markt" ,
58+ ]
59+ }
60+ ]
61+ } ] ;
62+
63+
64+ Dialogflow . setEntities ( entities ) ;
65+ }
66+
67+
68+ render ( ) {
69+ Dialogflow . requestEvent ( "WELCOME" , null , r => console . log ( r ) , e => console . log ( e ) ) ;
70+
71+
72+ return (
73+ < View style = { styles . container } >
74+
75+ < View style = { { flex : 4 } } >
76+ < Text > { "Listening State: " + this . state . listeningState } </ Text >
77+ < Text > { "Audio Level: " + this . state . audioLevel } </ Text >
78+ < Text > { "Result: " + this . state . result } </ Text >
79+ </ View >
80+ < View style = { { flex : 1 , padding : 10 } } >
81+ < Button title = "Start Listening" onPress = { ( ) => {
82+
83+
84+ Dialogflow . onListeningStarted ( ( ) => {
85+ this . setState ( { listeningState : "started" } ) ;
86+ } ) ;
87+
88+ Dialogflow . onListeningCanceled ( ( ) => {
89+ this . setState ( { listeningState : "canceled" } ) ;
90+ } ) ;
91+
92+ Dialogflow . onListeningFinished ( ( ) => {
93+ this . setState ( { listeningState : "finished" } ) ;
94+ } ) ;
95+
96+ Dialogflow . onAudioLevel ( level => {
97+ this . setState ( { audioLevel : level } ) ;
98+ } ) ;
99+
100+ Dialogflow . startListening ( result => {
101+ console . log ( result ) ;
102+ this . setState ( { result : JSON . stringify ( result ) } ) ;
103+ } , error => {
104+ this . setState ( { result : JSON . stringify ( error ) } ) ;
105+ } ) ;
106+
107+ } } />
108+ </ View >
109+ </ View >
110+ ) ;
111+ }
112+ }
113+
114+ const styles = StyleSheet . create ( {
115+ container : {
116+ flex : 1 ,
117+ backgroundColor : '#F5FCFF' ,
118+ } ,
119+
120+ } ) ;
121+
122+ AppRegistry . registerComponent ( 'DialogflowExample' , ( ) => App ) ;
0 commit comments