77 Button
88} from 'react-native' ;
99
10- import Dialogflow from "react-native-dialogflow"
10+ import Dialogflow , { Dialogflow_V2 } from "react-native-dialogflow"
1111
1212export default class App extends Component {
1313 constructor ( props ) {
@@ -24,6 +24,12 @@ export default class App extends Component {
2424 "57b6ce865e6e4b138a74a88cfd8bc526" , Dialogflow . LANG_GERMAN
2525 ) ;
2626
27+ Dialogflow_V2 . setConfiguration (
28+ "ya29.c.El92BV4aRCnGyaJ0VWKF0ewGNprivoW68g9lm0IrbsIi7T9m3QEL-JoPnfq3tWU07WhAjmIhD14z6X-1d8N_jzLz7o_8sB-c5OgAJE4cswJPoOzixZDTmCBvMbD901_0RA" ,
29+ Dialogflow_V2 . LANG_GERMAN ,
30+ 'testv2-3b5ca'
31+ ) ;
32+
2733
2834
2935 const contexts = [ {
@@ -34,7 +40,17 @@ export default class App extends Component {
3440 }
3541 } ] ;
3642
43+
44+ const contexts_V2 = [ {
45+ "name" : "deals" ,
46+ "lifespanCount" : 1 ,
47+ "parameters" : {
48+ "name" : "Sam"
49+ }
50+ } ] ;
51+
3752 Dialogflow . setContexts ( contexts ) ;
53+ //Dialogflow_V2.setContexts(contexts_V2);
3854
3955
4056 const permanentContexts = [ {
@@ -44,7 +60,15 @@ export default class App extends Component {
4460 }
4561 } ] ;
4662
63+ const permanentContexts_V2 = [ {
64+ "name" : "config" ,
65+ "parameters" : {
66+ "access_token" : "42 yo 42 tiny rick"
67+ }
68+ } ] ;
69+
4770 Dialogflow . setPermanentContexts ( permanentContexts ) ;
71+ //Dialogflow_V2.setPermanentContexts(permanentContexts_V2);
4872
4973
5074 const entities = [ {
@@ -62,11 +86,13 @@ export default class App extends Component {
6286
6387
6488 Dialogflow . setEntities ( entities ) ;
89+ Dialogflow_V2 . setEntities ( entities ) ;
6590 }
6691
6792
6893 render ( ) {
6994 Dialogflow . requestEvent ( "WELCOME" , null , r => console . log ( r ) , e => console . log ( e ) ) ;
95+ Dialogflow_V2 . requestEvent ( "WELCOME" , null , r => console . log ( r ) , e => console . log ( e ) ) ;
7096
7197
7298 return (
@@ -81,6 +107,7 @@ export default class App extends Component {
81107 < Button title = "Start Listening" onPress = { ( ) => {
82108
83109
110+ // V1
84111 Dialogflow . onListeningStarted ( ( ) => {
85112 this . setState ( { listeningState : "started" } ) ;
86113 } ) ;
@@ -103,7 +130,32 @@ export default class App extends Component {
103130 } , error => {
104131 this . setState ( { result : JSON . stringify ( error ) } ) ;
105132 } ) ;
133+ } } />
106134
135+ < Button color = "orange" title = "Start Listening V2" onPress = { ( ) => {
136+ // V2
137+ Dialogflow_V2 . onListeningStarted ( ( ) => {
138+ this . setState ( { listeningState : "started" } ) ;
139+ } ) ;
140+
141+ Dialogflow_V2 . onListeningCanceled ( ( ) => {
142+ this . setState ( { listeningState : "canceled" } ) ;
143+ } ) ;
144+
145+ Dialogflow_V2 . onListeningFinished ( ( ) => {
146+ this . setState ( { listeningState : "finished" } ) ;
147+ } ) ;
148+
149+ Dialogflow_V2 . onAudioLevel ( level => {
150+ this . setState ( { audioLevel : level } ) ;
151+ } ) ;
152+
153+ Dialogflow_V2 . startListening ( result => {
154+ console . log ( result ) ;
155+ this . setState ( { result : JSON . stringify ( result ) } ) ;
156+ } , error => {
157+ this . setState ( { result : JSON . stringify ( error ) } ) ;
158+ } ) ;
107159 } } />
108160 </ View >
109161 </ View >
0 commit comments