Skip to content

Commit eb74ba6

Browse files
author
spoeck
committed
doc: contexts example
1 parent e7f0bc4 commit eb74ba6

1 file changed

Lines changed: 27 additions & 7 deletions

File tree

README.md

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Import ApiAi:
4242
import ApiAi from "react-native-api-ai";
4343
```
4444

45+
### Configuration
4546
Set the `clientAccessToken` and the language in your constructor:
4647
```javascript
4748
constructor(props) {
@@ -54,6 +55,7 @@ Set the `clientAccessToken` and the language in your constructor:
5455

5556
```
5657

58+
### Listening
5759
Start listening with integrated speech recognition:
5860
```javascript
5961
<Button onPress={() => {
@@ -72,6 +74,31 @@ ApiAi.finishListening();
7274
// after this call your callbacks from the startListening will be executed.
7375
```
7476

77+
### Text Request
78+
For using your own speech recognition:
79+
```javascript
80+
<Button onPress={() => {
81+
ApiAi.requestQuery("Some text for your api-ai agent", result=>console.log(result), error=>console.log(error));
82+
}}
83+
/>
84+
```
85+
86+
87+
### Contexts
88+
Set contexts (will take affect on next startListening or queryRequest):
89+
```javascript
90+
const contexts = [{
91+
name: "deals",
92+
lifespan: 1,
93+
parameters: {
94+
Shop: "Rewe"
95+
}
96+
}];
97+
98+
ApiAi.setContexts(contexts);
99+
```
100+
101+
### Events on Android
75102
Only in Android we have four additional methods: `onListeningStarted`, `onListeningCanceled`, `onListeningFinished` and `onAudioLevel`. In iOS they will be never called:
76103
```javascript
77104
<Button onPress={() => {
@@ -103,13 +130,6 @@ Only in Android we have four additional methods: `onListeningStarted`, `onListen
103130
```
104131
Note: Make sure you are setting the callbacks before startListening every single time again. Don't set the callbacks in e.g. constructor or componentsDidMount if you are executing startListening more than one times.
105132

106-
Using your own speech recognition:
107-
```javascript
108-
<Button onPress={() => {
109-
ApiAi.requestQuery("Some text for your api-ai agent", result=>console.log(result), error=>console.log(error));
110-
}}
111-
/>
112-
```
113133

114134
## Supported Languages
115135
Set the language in your configuration:

0 commit comments

Comments
 (0)