This repository was archived by the owner on Oct 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathApp.tsx
More file actions
114 lines (101 loc) · 3.49 KB
/
App.tsx
File metadata and controls
114 lines (101 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import React, { useRef } from 'react';
import { SafeAreaView, StatusBar, Text, View } from 'react-native';
import Video from 'react-native-video';
import RasaChat, { Send, InputToolbar, Composer, Actions, IRasaChatHandles } from './RNRasa';
import styles from './styles';
// your host http://localhost:5005. Apps work better on https so you can use ngrok if development
const HOST = 'http://localhost:5005';
// Avatar images
const botAvatar = "https://images.unsplash.com/photo-1485827404703-89b55fcc595e?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=500&q=80"
const userAvatar = "https://images.unsplash.com/photo-1483884105135-c06ea81a7a80?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=500&q=80"
//TODO: reset bot on destroy
//TODO: handle when bot response error
const App = () => {
const rasaChatRef = useRef<IRasaChatHandles>(null);
const resetMessages = () => {
rasaChatRef?.current?.resetMessages();
}
const resetBot = () => {
rasaChatRef?.current?.resetBot();
}
const sendStartConversation = () => {
rasaChatRef?.current?.sendCustomMessage('Hi');
}
return (
<>
<StatusBar barStyle="dark-content" />
<SafeAreaView style={styles.container}>
<RasaChat
ref={rasaChatRef}
host={HOST}
placeholder="Your input placeholder"
botAvatar={botAvatar}
userAvatar={userAvatar}
showUserAvatar
renderInputToolbar={(props) => (
<InputToolbar
{...props}
containerStyle={styles.InputToolbar}
primaryStyle={{ alignItems: 'center' }}
/>
)}
renderActions={(props) => (
<Actions
{...props}
containerStyle={styles.containerActions}
options={{
'Start New Conversation': sendStartConversation,
'Clear messages': resetMessages,
'Reset Bot': resetBot,
'Cancel': () => { },
}}
/>
)}
renderComposer={(props) => (
<Composer
{...props}
textInputStyle={styles.textComposer}
/>
)}
alwaysShowSend
renderSend={(props) => {
return (
<Send
{...props}
disabled={!props.text}
containerStyle={styles.sendContainer}
>
<Text style={{ color: !props.text ? '#d6d3d1' : '#2097F3' }}>Send</Text>
</Send >
);
}}
// @ts-ignore
renderMessageVideo={(props) => {
const { currentMessage } = props;
return (
<View style={{ padding: 0 }}>
<Video
source={{ uri: currentMessage?.video }}
resizeMode="cover"
repeat
controls
//onBuffer={this.onBuffer} // Callback when remote video is buffering
//onError={this.videoError} // Callback when video cannot be loaded
style={styles.backgroundVideo}
/>
</View>
);
}}
/>
</SafeAreaView>
</>
);
};
export default App;