-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.js
81 lines (74 loc) · 2.29 KB
/
App.js
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
import { Button, View } from "react-native";
import BpWidget from "./src/BpWidget";
import BpIncommingMessagesListener from "./src/BpIncommingMessagesListener";
import { useRef } from "react";
const testingConfig = {
composerPlaceholder: "Chat with bot",
botConversationDescription:
"This chatbot was built surprisingly fast with Botpress",
botId: "db76fba1-82ca-4a9c-ba4d-d4ac245fcdc6",
hostUrl: "https://cdn.botpress.cloud/webchat/v1",
messagingUrl: "https://messaging.botpress.cloud",
clientId: "db76fba1-82ca-4a9c-ba4d-d4ac245fcdc6",
lazySocket: true,
frontendVersion: "v1",
showPoweredBy: true,
hideWidget: true,
disableAnimations: true,
closeOnEscape: false,
showConversationsButton: false,
enableTranscriptDownload: false,
className: "webchatIframe",
containerWidth: "100%25",
layoutWidth: "100%25",
showCloseButton: false,
};
export default function App() {
const botpressWebChatRef = useRef();
const sendExampleEvent = () => {
botpressWebChatRef.current?.sendEvent({ type: "toggle" });
}
const sendExamplePayload = () => {
botpressWebChatRef.current?.sendPayload({ type: "text", text: "hello" });
}
const changeExampleConfig = () => {
botpressWebChatRef.current?.mergeConfig({ botName: Math.random() });
}
return (
<View style={{ flex: 1, flexDirection: "column" }}>
<View style={{ flex: 1 }}>
<View
style={{ height: 50, justifyContent: "center", alignItems: "center" }}
>
{/* <Text>Your app header or spacer</Text> */}
</View>
<BpWidget
ref={botpressWebChatRef}
botConfig={testingConfig}
onMessage={(event) => {
console.log("event from widget", event);
}}
/>
<Button
onPress={sendExampleEvent}
title="Toggle webchat"
/>
<Button
onPress={changeExampleConfig}
title="changeConfig"
/>
<Button
onPress={sendExamplePayload}
title="send message"
/>
</View>
{/* In case your webchat is not rendered and you want to catch bot messages */}
<BpIncommingMessagesListener
botConfig={testingConfig}
onBotMessage={(event) => {
console.log("bot message", event);
}}
/>
</View>
);
}