@cobbai/react-native-sdk 1.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CobbaiMobileRnSdk.podspec +22 -0
- package/LICENSE +32 -0
- package/README.md +386 -0
- package/dist/ChatPlaceholder.d.ts +13 -0
- package/dist/ChatPlaceholder.d.ts.map +1 -0
- package/dist/ChatPlaceholder.js +87 -0
- package/dist/CobbaiChatScreen.d.ts +4 -0
- package/dist/CobbaiChatScreen.d.ts.map +1 -0
- package/dist/CobbaiChatScreen.js +196 -0
- package/dist/CobbaiInAppBanner.d.ts +15 -0
- package/dist/CobbaiInAppBanner.d.ts.map +1 -0
- package/dist/CobbaiInAppBanner.js +159 -0
- package/dist/CobbaiLauncher.d.ts +19 -0
- package/dist/CobbaiLauncher.d.ts.map +1 -0
- package/dist/CobbaiLauncher.js +149 -0
- package/dist/CobbaiWebView.d.ts +28 -0
- package/dist/CobbaiWebView.d.ts.map +1 -0
- package/dist/CobbaiWebView.js +141 -0
- package/dist/adapters/expoAdapter.d.ts +85 -0
- package/dist/adapters/expoAdapter.d.ts.map +1 -0
- package/dist/adapters/expoAdapter.js +152 -0
- package/dist/adapters/firebaseAdapter.d.ts +41 -0
- package/dist/adapters/firebaseAdapter.d.ts.map +1 -0
- package/dist/adapters/firebaseAdapter.js +139 -0
- package/dist/adapters/iosRelayAdapter.d.ts +26 -0
- package/dist/adapters/iosRelayAdapter.d.ts.map +1 -0
- package/dist/adapters/iosRelayAdapter.js +101 -0
- package/dist/androidKeyboardFrame.d.ts +16 -0
- package/dist/androidKeyboardFrame.d.ts.map +1 -0
- package/dist/androidKeyboardFrame.js +34 -0
- package/dist/bridge/messages.d.ts +20 -0
- package/dist/bridge/messages.d.ts.map +1 -0
- package/dist/bridge/messages.js +20 -0
- package/dist/bridge/nativeEvent.d.ts +10 -0
- package/dist/bridge/nativeEvent.d.ts.map +1 -0
- package/dist/bridge/nativeEvent.js +15 -0
- package/dist/bridge/parser.d.ts +29 -0
- package/dist/bridge/parser.d.ts.map +1 -0
- package/dist/bridge/parser.js +109 -0
- package/dist/chatPresentation.d.ts +19 -0
- package/dist/chatPresentation.d.ts.map +1 -0
- package/dist/chatPresentation.js +51 -0
- package/dist/chatScreen/useInAppBannerQueue.d.ts +22 -0
- package/dist/chatScreen/useInAppBannerQueue.d.ts.map +1 -0
- package/dist/chatScreen/useInAppBannerQueue.js +60 -0
- package/dist/chatScreen/useKeyboardFrame.d.ts +14 -0
- package/dist/chatScreen/useKeyboardFrame.d.ts.map +1 -0
- package/dist/chatScreen/useKeyboardFrame.js +63 -0
- package/dist/chatScreen/useLauncherPresentation.d.ts +20 -0
- package/dist/chatScreen/useLauncherPresentation.d.ts.map +1 -0
- package/dist/chatScreen/useLauncherPresentation.js +76 -0
- package/dist/chatScreen/useNativeToWebSync.d.ts +17 -0
- package/dist/chatScreen/useNativeToWebSync.d.ts.map +1 -0
- package/dist/chatScreen/useNativeToWebSync.js +36 -0
- package/dist/chatScreen/usePushIntegration.d.ts +19 -0
- package/dist/chatScreen/usePushIntegration.d.ts.map +1 -0
- package/dist/chatScreen/usePushIntegration.js +129 -0
- package/dist/chatScreen/useReadyLifecycle.d.ts +33 -0
- package/dist/chatScreen/useReadyLifecycle.d.ts.map +1 -0
- package/dist/chatScreen/useReadyLifecycle.js +138 -0
- package/dist/chatScreen/useSheetPresentation.d.ts +25 -0
- package/dist/chatScreen/useSheetPresentation.d.ts.map +1 -0
- package/dist/chatScreen/useSheetPresentation.js +98 -0
- package/dist/chatUnavailable.d.ts +23 -0
- package/dist/chatUnavailable.d.ts.map +1 -0
- package/dist/chatUnavailable.js +36 -0
- package/dist/externalLinks.d.ts +4 -0
- package/dist/externalLinks.d.ts.map +1 -0
- package/dist/externalLinks.js +48 -0
- package/dist/host/buildHostHtml.d.ts +7 -0
- package/dist/host/buildHostHtml.d.ts.map +1 -0
- package/dist/host/buildHostHtml.js +101 -0
- package/dist/host/hostPageKey.d.ts +7 -0
- package/dist/host/hostPageKey.d.ts.map +1 -0
- package/dist/host/hostPageKey.js +18 -0
- package/dist/inAppBanner.d.ts +19 -0
- package/dist/inAppBanner.d.ts.map +1 -0
- package/dist/inAppBanner.js +42 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/launcher.d.ts +25 -0
- package/dist/launcher.d.ts.map +1 -0
- package/dist/launcher.js +55 -0
- package/dist/launcherGlyph.d.ts +2 -0
- package/dist/launcherGlyph.d.ts.map +1 -0
- package/dist/launcherGlyph.js +5 -0
- package/dist/openChatScreen.d.ts +13 -0
- package/dist/openChatScreen.d.ts.map +1 -0
- package/dist/openChatScreen.js +63 -0
- package/dist/push.d.ts +59 -0
- package/dist/push.d.ts.map +1 -0
- package/dist/push.js +309 -0
- package/dist/pushIntegration.d.ts +76 -0
- package/dist/pushIntegration.d.ts.map +1 -0
- package/dist/pushIntegration.js +244 -0
- package/dist/pushLogout.d.ts +57 -0
- package/dist/pushLogout.d.ts.map +1 -0
- package/dist/pushLogout.js +225 -0
- package/dist/types.d.ts +42 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/version.d.ts +8 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +10 -0
- package/ios/CobbaiPush.m +96 -0
- package/ios/CobbaiPushRelay.h +59 -0
- package/ios/CobbaiPushRelay.m +364 -0
- package/package.json +69 -0
- package/src/ChatPlaceholder.tsx +132 -0
- package/src/CobbaiChatScreen.tsx +348 -0
- package/src/CobbaiInAppBanner.tsx +237 -0
- package/src/CobbaiLauncher.tsx +223 -0
- package/src/CobbaiWebView.tsx +242 -0
- package/src/adapters/expoAdapter.ts +227 -0
- package/src/adapters/firebaseAdapter.ts +201 -0
- package/src/adapters/iosRelayAdapter.ts +137 -0
- package/src/androidKeyboardFrame.ts +56 -0
- package/src/bridge/messages.ts +24 -0
- package/src/bridge/nativeEvent.ts +12 -0
- package/src/bridge/parser.ts +159 -0
- package/src/chatPresentation.ts +73 -0
- package/src/chatScreen/useInAppBannerQueue.ts +91 -0
- package/src/chatScreen/useKeyboardFrame.ts +89 -0
- package/src/chatScreen/useLauncherPresentation.ts +121 -0
- package/src/chatScreen/useNativeToWebSync.ts +54 -0
- package/src/chatScreen/usePushIntegration.ts +191 -0
- package/src/chatScreen/useReadyLifecycle.ts +186 -0
- package/src/chatScreen/useSheetPresentation.ts +147 -0
- package/src/chatUnavailable.ts +58 -0
- package/src/externalLinks.ts +56 -0
- package/src/host/buildHostHtml.ts +117 -0
- package/src/host/hostPageKey.ts +17 -0
- package/src/inAppBanner.ts +58 -0
- package/src/index.ts +53 -0
- package/src/launcher.ts +79 -0
- package/src/launcherGlyph.ts +3 -0
- package/src/openChatScreen.ts +78 -0
- package/src/push.ts +424 -0
- package/src/pushIntegration.ts +338 -0
- package/src/pushLogout.ts +277 -0
- package/src/types.ts +46 -0
- package/src/version.ts +8 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
|
|
5
|
+
# iPhone native relay of Cobbai pushes. Picked up by React Native
|
|
6
|
+
# autolinking; Android has no native code.
|
|
7
|
+
Pod::Spec.new do |s|
|
|
8
|
+
s.name = 'CobbaiMobileRnSdk'
|
|
9
|
+
s.version = package['version']
|
|
10
|
+
s.summary = package['description']
|
|
11
|
+
s.homepage = 'https://cobbai.com'
|
|
12
|
+
s.license = { :type => 'Proprietary', :file => 'LICENSE' }
|
|
13
|
+
s.authors = 'Cobbai'
|
|
14
|
+
s.platforms = { :ios => '15.1' }
|
|
15
|
+
# Installed from node_modules by React Native autolinking; the published npm tarball otherwise.
|
|
16
|
+
s.source = { :http => "https://registry.npmjs.org/#{package['name']}/-/#{package['name'].split('/').last}-#{s.version}.tgz" }
|
|
17
|
+
|
|
18
|
+
s.source_files = 'ios/**/*.{h,m}'
|
|
19
|
+
s.frameworks = 'UIKit', 'UserNotifications'
|
|
20
|
+
|
|
21
|
+
install_modules_dependencies(s)
|
|
22
|
+
end
|
package/LICENSE
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Cobbai React Native SDK — Proprietary License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Cobbai. All rights reserved.
|
|
4
|
+
|
|
5
|
+
1. Grant. Cobbai grants you a non-exclusive, non-transferable, revocable license to install and use
|
|
6
|
+
this software (the "SDK"), in object or source form as distributed, solely to integrate Cobbai
|
|
7
|
+
services into your own applications and to distribute it as part of those applications, for as
|
|
8
|
+
long as you hold a valid agreement with Cobbai for those services.
|
|
9
|
+
|
|
10
|
+
2. Restrictions. Except as expressly permitted above or by applicable law, you may not: (a) copy,
|
|
11
|
+
modify, translate or create derivative works of the SDK; (b) distribute, sublicense, sell, rent
|
|
12
|
+
or otherwise make the SDK available on its own or as part of a software development kit,
|
|
13
|
+
library or product that competes with Cobbai; (c) use the SDK to access any service other than
|
|
14
|
+
Cobbai's; (d) remove or alter any proprietary notice in the SDK.
|
|
15
|
+
|
|
16
|
+
3. Ownership. The SDK is licensed, not sold. Cobbai retains all right, title and interest in and to
|
|
17
|
+
the SDK, including all intellectual property rights.
|
|
18
|
+
|
|
19
|
+
4. Termination. This license ends automatically when your agreement with Cobbai ends or if you
|
|
20
|
+
breach its terms. You must then stop using the SDK and remove it from future releases of your
|
|
21
|
+
applications.
|
|
22
|
+
|
|
23
|
+
5. No warranty. THE SDK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
24
|
+
INCLUDING THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
25
|
+
NON-INFRINGEMENT, EXCEPT AS OTHERWISE PROVIDED IN YOUR AGREEMENT WITH COBBAI.
|
|
26
|
+
|
|
27
|
+
6. Limitation of liability. TO THE MAXIMUM EXTENT PERMITTED BY LAW, COBBAI SHALL NOT BE LIABLE FOR
|
|
28
|
+
ANY INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF OR INABILITY
|
|
29
|
+
TO USE THE SDK, EXCEPT AS OTHERWISE PROVIDED IN YOUR AGREEMENT WITH COBBAI.
|
|
30
|
+
|
|
31
|
+
7. Agreement. If you have a separate agreement with Cobbai covering the SDK, that agreement
|
|
32
|
+
prevails over this license where they conflict.
|
package/README.md
ADDED
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
# Cobbai React Native SDK
|
|
2
|
+
|
|
3
|
+
Add the Cobbai support chat to your React Native app: a native launcher, the chat in a sheet over
|
|
4
|
+
your app, unread badges, and push notifications for support replies.
|
|
5
|
+
|
|
6
|
+
## Requirements
|
|
7
|
+
|
|
8
|
+
- React Native 0.76 or later, New Architecture.
|
|
9
|
+
- `react-native-webview` 13 or later and `react-native-safe-area-context` 4 or later.
|
|
10
|
+
- Expo: development or production builds (the SDK has native code for iPhone, so Expo Go is not
|
|
11
|
+
supported).
|
|
12
|
+
- A Cobbai chat. Its chat ID and the installation steps, with your values already filled in, are
|
|
13
|
+
in the chat's **Install** tab › **Mobile** in Cobbai.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @cobbai/react-native-sdk@beta react-native-webview react-native-safe-area-context
|
|
19
|
+
cd ios && pod install
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The SDK is in beta: `@beta` installs the latest pre-release (`1.0.0-beta.N`). Its API may still
|
|
23
|
+
change before 1.0.0; each change is listed in the release notes.
|
|
24
|
+
|
|
25
|
+
Run `pod install` again after each SDK update.
|
|
26
|
+
|
|
27
|
+
## Quick start
|
|
28
|
+
|
|
29
|
+
Mount `CobbaiChatScreen` **once**, near the root of your app, next to your main content:
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
import React, { useMemo } from 'react';
|
|
33
|
+
import { StyleSheet, View } from 'react-native';
|
|
34
|
+
import { SafeAreaProvider } from 'react-native-safe-area-context';
|
|
35
|
+
import { CobbaiChatScreen, type CobbaiChatConfig } from '@cobbai/react-native-sdk';
|
|
36
|
+
|
|
37
|
+
export default function App() {
|
|
38
|
+
const config = useMemo<CobbaiChatConfig>(
|
|
39
|
+
() => ({
|
|
40
|
+
baseUrl: 'https://your-cobbai-domain.com',
|
|
41
|
+
chatId: 'your-chat-id',
|
|
42
|
+
userId: 'user-1',
|
|
43
|
+
metadata: { plan: 'pro' },
|
|
44
|
+
onError: (error) => console.warn('Cobbai chat error', error),
|
|
45
|
+
}),
|
|
46
|
+
[],
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<SafeAreaProvider>
|
|
51
|
+
<View style={styles.root}>
|
|
52
|
+
{/* your app */}
|
|
53
|
+
<CobbaiChatScreen config={config} />
|
|
54
|
+
</View>
|
|
55
|
+
</SafeAreaProvider>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const styles = StyleSheet.create({
|
|
60
|
+
root: { flex: 1, position: 'relative' },
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
The SDK shows its launcher at the bottom of the screen; a tap opens the chat.
|
|
65
|
+
|
|
66
|
+
## Configuration
|
|
67
|
+
|
|
68
|
+
### `CobbaiChatConfig`
|
|
69
|
+
|
|
70
|
+
| Field | Description |
|
|
71
|
+
| --- | --- |
|
|
72
|
+
| `baseUrl` | Your Cobbai address, without a trailing slash. |
|
|
73
|
+
| `chatId` | The chat ID from the chat's Install tab. |
|
|
74
|
+
| `userId` | Your user's ID, when the chat identifies users by the ID your app sends. |
|
|
75
|
+
| `authToken` | A token signed by your backend, when the chat verifies user identities. |
|
|
76
|
+
| `metadata` | Values attached to the user's conversations (`string`, `number`, `boolean` or `null`). |
|
|
77
|
+
| `locale` | Chat language, e.g. `'en'` or `'fr'`. Defaults to the chat's language settings. |
|
|
78
|
+
| `onReady` | The chat is loaded and ready. |
|
|
79
|
+
| `onClose` | The user closed the chat. |
|
|
80
|
+
| `onError` | See [Errors](#errors). |
|
|
81
|
+
| `onNewMessage` | A support reply arrived (see below). |
|
|
82
|
+
| `onUnreadCountChange` | The number of unread support replies changed. |
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
onNewMessage?: (event: {
|
|
86
|
+
conversationId: number;
|
|
87
|
+
messageId: number;
|
|
88
|
+
speaker: 'agent' | 'auto'; // a human agent, or an automatic reply
|
|
89
|
+
senderName?: string;
|
|
90
|
+
preview?: string; // the beginning of the reply, plain text
|
|
91
|
+
chatVisible: boolean; // whether the chat is open
|
|
92
|
+
}) => void;
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The chat is reloaded only when `baseUrl`, `chatId`, `authToken`, `userId`, `locale` or the content
|
|
96
|
+
of `metadata` changes. Passing a new `config` object or new callbacks on each render is fine;
|
|
97
|
+
memoizing `config` with `useMemo` still avoids needless work.
|
|
98
|
+
|
|
99
|
+
When a user logs in or out, pass the new user's config (or one without `userId` / `authToken`),
|
|
100
|
+
and see [Logout](#7-logout) for push notifications.
|
|
101
|
+
|
|
102
|
+
### `CobbaiChatScreen` props
|
|
103
|
+
|
|
104
|
+
| Prop | Default | Description |
|
|
105
|
+
| --- | --- | --- |
|
|
106
|
+
| `config` | — | The `CobbaiChatConfig` above. |
|
|
107
|
+
| `prewarm` | `true` | Loads the chat in the background so it opens instantly and the unread badge stays live. With `false`, the chat loads when first opened. |
|
|
108
|
+
| `launcherVisible` | `true` | Shows the SDK's launcher while the chat is closed. |
|
|
109
|
+
| `launcherBottomOffset` | — | Space to leave below the launcher, e.g. your tab bar's height. |
|
|
110
|
+
| `inAppBanner` | `true` | Shows a banner when a reply arrives while the app is open and the chat is closed. |
|
|
111
|
+
|
|
112
|
+
### Functions
|
|
113
|
+
|
|
114
|
+
- `openChatScreen()`: opens the chat.
|
|
115
|
+
- `closeChatScreen()`: closes the chat from your code (logout, deep link). `onClose` is not
|
|
116
|
+
called; it reports closes made by the user.
|
|
117
|
+
- `isChatScreenOpen()`: whether the chat is open.
|
|
118
|
+
|
|
119
|
+
## Launcher
|
|
120
|
+
|
|
121
|
+
- Visible while the chat is closed, hidden while it is open.
|
|
122
|
+
- Its badge shows the number of unread support replies (`9+` above 9).
|
|
123
|
+
- Its colours are the chat's button colours set in Cobbai. A change is picked up at the next app
|
|
124
|
+
start (allow a few minutes for it to propagate).
|
|
125
|
+
|
|
126
|
+
### Showing it on some screens only
|
|
127
|
+
|
|
128
|
+
Keep a single `CobbaiChatScreen` at the root and derive the launcher's visibility from your
|
|
129
|
+
navigation state:
|
|
130
|
+
|
|
131
|
+
```tsx
|
|
132
|
+
const routeName = getFocusedRouteNameFromRoute(route) ?? 'Home';
|
|
133
|
+
|
|
134
|
+
<CobbaiChatScreen
|
|
135
|
+
config={config}
|
|
136
|
+
launcherVisible={routeName !== 'Checkout'}
|
|
137
|
+
launcherBottomOffset={useBottomTabBarHeight()}
|
|
138
|
+
/>;
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Do not mount `CobbaiChatScreen` inside your screens.
|
|
142
|
+
|
|
143
|
+
### Your own sheets and overlays
|
|
144
|
+
|
|
145
|
+
Alerts, React Native `Modal`s and screens presented modally by your navigator cover the launcher.
|
|
146
|
+
Sheets and overlays drawn in your JS tree instead (e.g. `@gorhom/bottom-sheet` without a portal,
|
|
147
|
+
a custom absolute overlay) render under it: set `launcherVisible={false}` while they are open.
|
|
148
|
+
|
|
149
|
+
### Using your own button
|
|
150
|
+
|
|
151
|
+
```tsx
|
|
152
|
+
import { CobbaiChatScreen, openChatScreen } from '@cobbai/react-native-sdk';
|
|
153
|
+
|
|
154
|
+
<CobbaiChatScreen config={config} launcherVisible={false} />;
|
|
155
|
+
|
|
156
|
+
// In your button:
|
|
157
|
+
openChatScreen();
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Use `onUnreadCountChange` to show your own badge. If `CobbaiChatScreen` unmounts while the chat is
|
|
161
|
+
open, the chat is closed.
|
|
162
|
+
|
|
163
|
+
## Errors
|
|
164
|
+
|
|
165
|
+
`onError` receives `{ code, message }`:
|
|
166
|
+
|
|
167
|
+
| `code` | Meaning |
|
|
168
|
+
| --- | --- |
|
|
169
|
+
| `init_script_load_error` | The chat could not be loaded (no network, server unreachable). |
|
|
170
|
+
| `ready_timeout` | The chat did not get ready within 10 seconds while open. |
|
|
171
|
+
| `webview_process_gone` | The system stopped the chat's web view (memory pressure or crash). |
|
|
172
|
+
| `chat_error` | An error reported by the chat itself. |
|
|
173
|
+
|
|
174
|
+
Until the chat is ready, an error shows a "chat unavailable" screen with a Retry button and a close
|
|
175
|
+
button. After `webview_process_gone` the SDK reloads the chat on its own; after 3 times within 60
|
|
176
|
+
seconds it stops and shows the "chat unavailable" screen.
|
|
177
|
+
|
|
178
|
+
## Push notifications
|
|
179
|
+
|
|
180
|
+
Cobbai can send a push notification for each support reply. You keep your own notification
|
|
181
|
+
library: you hand it to the SDK once, at start-up, through an **adapter**. The SDK then registers
|
|
182
|
+
the device, opens the right conversation when a notification is tapped (including the tap that
|
|
183
|
+
launches the app), decides what the open app shows, and reports the permission status. Your own
|
|
184
|
+
notifications are left alone.
|
|
185
|
+
|
|
186
|
+
### 1) Cobbai settings
|
|
187
|
+
|
|
188
|
+
In the chat's Install tab › Mobile, step "Mobile push notifications":
|
|
189
|
+
|
|
190
|
+
- Android: the Firebase service-account JSON. Optional: notification channel ID, icon and colour.
|
|
191
|
+
- iPhone: the APNs `.p8` key, Key ID, Team ID and bundle ID.
|
|
192
|
+
|
|
193
|
+
### 2) Start-up with Firebase (Android)
|
|
194
|
+
|
|
195
|
+
Prerequisites: `@react-native-firebase/app` and `@react-native-firebase/messaging` (v19 or later)
|
|
196
|
+
set up with `google-services.json`.
|
|
197
|
+
|
|
198
|
+
```ts
|
|
199
|
+
import * as messaging from '@react-native-firebase/messaging';
|
|
200
|
+
import { configureCobbaiPush, firebaseAdapter } from '@cobbai/react-native-sdk';
|
|
201
|
+
|
|
202
|
+
// Once, at start-up (index.js or your root component), not in a screen.
|
|
203
|
+
configureCobbaiPush({ adapter: firebaseAdapter(messaging) });
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
The adapter never sets Firebase's background message handler: that one stays yours.
|
|
207
|
+
|
|
208
|
+
**iPhone: nothing to write.** Cobbai notifications go to Apple directly (Firebase is not needed on
|
|
209
|
+
iPhone) and the SDK's native module handles them:
|
|
210
|
+
|
|
211
|
+
- Enable the **Push Notifications** capability in Xcode and run `pod install`.
|
|
212
|
+
- At launch the module becomes the notification-centre delegate and keeps the previous one: your
|
|
213
|
+
own notifications are forwarded to it unchanged. It also obtains the device token (your own
|
|
214
|
+
`didRegisterForRemoteNotificationsWithDeviceToken` still runs first).
|
|
215
|
+
- To start it yourself instead, set `CobbaiPushAutoInstall` to `NO` in `Info.plist` and call
|
|
216
|
+
`reinstallCobbaiPushRelay()` once your other notification libraries have started. Call it too if
|
|
217
|
+
a development build warns that the module is not installed (another library took the delegate
|
|
218
|
+
without forwarding to it).
|
|
219
|
+
|
|
220
|
+
### 2b) Start-up with Expo (`expo-notifications`)
|
|
221
|
+
|
|
222
|
+
```ts
|
|
223
|
+
import * as Notifications from 'expo-notifications';
|
|
224
|
+
import { configureCobbaiPush, expoAdapter, withCobbaiHandler } from '@cobbai/react-native-sdk';
|
|
225
|
+
|
|
226
|
+
configureCobbaiPush({ adapter: expoAdapter(Notifications) });
|
|
227
|
+
|
|
228
|
+
// Expo keeps a single foreground handler: wrap yours instead of replacing it.
|
|
229
|
+
Notifications.setNotificationHandler(
|
|
230
|
+
withCobbaiHandler({ handleNotification: async () => ({ /* your behaviour */ }) }),
|
|
231
|
+
);
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
`withCobbaiHandler` decides for Cobbai notifications and hands every other notification to your
|
|
235
|
+
handler. In your own listeners, read a notification's data with
|
|
236
|
+
`expoNotificationData(notification)`: for notifications not sent through Expo's push service, Expo
|
|
237
|
+
does not put the data in `content.data`.
|
|
238
|
+
|
|
239
|
+
### 3) Skip Cobbai notifications in your own handlers
|
|
240
|
+
|
|
241
|
+
Your notification library gives every message to every listener, Cobbai's included. Return early
|
|
242
|
+
on them, or your code may show them twice or navigate to the wrong screen:
|
|
243
|
+
|
|
244
|
+
```ts
|
|
245
|
+
import { isCobbaiPush } from '@cobbai/react-native-sdk';
|
|
246
|
+
|
|
247
|
+
onMessage(getMessaging(), (message) => {
|
|
248
|
+
if (isCobbaiPush(message.data)) return;
|
|
249
|
+
// your code
|
|
250
|
+
});
|
|
251
|
+
onNotificationOpenedApp(getMessaging(), (message) => {
|
|
252
|
+
if (isCobbaiPush(message.data)) return;
|
|
253
|
+
// your navigation
|
|
254
|
+
});
|
|
255
|
+
setBackgroundMessageHandler(getMessaging(), async (message) => {
|
|
256
|
+
if (isCobbaiPush(message.data)) return; // the system already shows it
|
|
257
|
+
// your code
|
|
258
|
+
});
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### 4) Permission and status
|
|
262
|
+
|
|
263
|
+
- The SDK never asks for permission on its own. If your app already asks, there is nothing to do:
|
|
264
|
+
the device is registered as soon as permission is granted.
|
|
265
|
+
- Otherwise call `requestCobbaiPushPermission()` at a meaningful moment (not at first launch). It
|
|
266
|
+
asks through your library and resolves with the new status.
|
|
267
|
+
- `getCobbaiPushStatus()` / `subscribeCobbaiPushStatus(listener)`: `'not-asked' | 'granted' |
|
|
268
|
+
'denied' | 'stopped' | 'unavailable'` (`unavailable`: no adapter, or Firebase not configured).
|
|
269
|
+
- `setCobbaiPushEnabled(false)` stops Cobbai notifications on this device while the user stays
|
|
270
|
+
logged in (status `stopped`); `setCobbaiPushEnabled(true)` or `requestCobbaiPushPermission()`
|
|
271
|
+
turns them back on. Only Cobbai notifications are affected.
|
|
272
|
+
|
|
273
|
+
### 5) What the phone shows
|
|
274
|
+
|
|
275
|
+
- App in the background or closed: the system notification. A tap opens the chat on that
|
|
276
|
+
conversation.
|
|
277
|
+
- App open, chat open: nothing; the reply appears in the chat.
|
|
278
|
+
- App open, chat closed: the SDK's in-app banner (turn it off with `inAppBanner={false}`).
|
|
279
|
+
- App open with no `CobbaiChatScreen` mounted, or with `inAppBanner={false}` while the chat is not
|
|
280
|
+
loaded: the system notification on iPhone and with Expo; nothing with Firebase on Android (the
|
|
281
|
+
reply waits in the chat and its badge).
|
|
282
|
+
- The app-icon badge is not changed; use `onUnreadCountChange` if you manage one.
|
|
283
|
+
|
|
284
|
+
**Android: no pop-up by default.** Unless the chat's Install tab › Mobile names a notification
|
|
285
|
+
channel, Firebase uses its default channel, whose importance is normal: the notification goes to
|
|
286
|
+
the notification shade without popping up over the screen. To get the pop-up (heads-up):
|
|
287
|
+
|
|
288
|
+
1. Create a channel with **high** importance at start-up, e.g. `cobbai_chat` (with Expo:
|
|
289
|
+
`setNotificationChannelAsync('cobbai_chat', { name: 'Support', importance:
|
|
290
|
+
AndroidImportance.HIGH })`; with Firebase only, `@notifee/react-native` or a few lines of
|
|
291
|
+
Kotlin). It also lets users mute support replies in the system settings.
|
|
292
|
+
2. Enter that channel ID in the chat's Install tab › Mobile.
|
|
293
|
+
|
|
294
|
+
If the app has not created the channel, Android uses the default one: notifications still arrive.
|
|
295
|
+
|
|
296
|
+
### 6) Other notification libraries
|
|
297
|
+
|
|
298
|
+
Write an adapter (`CobbaiPushAdapter`): `start(handlers)` subscribes to your library, reports
|
|
299
|
+
`handlers.token(...)`, `handlers.tap(data)`, `handlers.foreground({ data, title, body })` and
|
|
300
|
+
`handlers.status(...)`, and returns an unsubscribe function; `requestPermission()` asks the user.
|
|
301
|
+
Lower-level functions are also available: `setPushToken`, `clearPushToken`, `isCobbaiPush`,
|
|
302
|
+
`handleCobbaiPushTap`, `handleCobbaiPushInForeground`.
|
|
303
|
+
|
|
304
|
+
### 7) Logout
|
|
305
|
+
|
|
306
|
+
When the user logs out of your app, call `logoutCobbai()`, then pass the next user's config (or one
|
|
307
|
+
without `userId` / `authToken`) to `CobbaiChatScreen`:
|
|
308
|
+
|
|
309
|
+
```ts
|
|
310
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
311
|
+
import { configureCobbaiPush, firebaseAdapter, logoutCobbai } from '@cobbai/react-native-sdk';
|
|
312
|
+
|
|
313
|
+
// At start-up: `storage` lets a logout survive an app restart (recommended).
|
|
314
|
+
configureCobbaiPush({ adapter: firebaseAdapter(messaging), storage: AsyncStorage });
|
|
315
|
+
|
|
316
|
+
// At logout:
|
|
317
|
+
await logoutCobbai();
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
- It stops Cobbai notifications for the logged-out user on this device, even with the chat closed
|
|
321
|
+
or the app offline (it is sent again at the next start-up). Your own notifications are not
|
|
322
|
+
affected.
|
|
323
|
+
- The next user receives notifications as soon as their chat is loaded.
|
|
324
|
+
- Without `storage`, a logout right after an app restart only works once the chat has been loaded.
|
|
325
|
+
|
|
326
|
+
### 8) Privacy
|
|
327
|
+
|
|
328
|
+
Notifications show the sender's name and the beginning of the reply; the text goes through Apple
|
|
329
|
+
or Google and may appear on the lock screen. Cobbai stores the device token for the chat user and
|
|
330
|
+
deletes it at logout or when Apple or Google report it invalid.
|
|
331
|
+
|
|
332
|
+
## Attachments and camera
|
|
333
|
+
|
|
334
|
+
### iOS (`Info.plist`)
|
|
335
|
+
|
|
336
|
+
- `NSCameraUsageDescription` (required), e.g. `Allow camera access to take photos or videos in chat.`
|
|
337
|
+
- `NSMicrophoneUsageDescription` (required), e.g. `Allow microphone access when recording video in chat.`
|
|
338
|
+
- `NSPhotoLibraryUsageDescription` (recommended), e.g. `Allow selecting photos and videos to share in chat.`
|
|
339
|
+
|
|
340
|
+
### Android
|
|
341
|
+
|
|
342
|
+
No extra permission is needed.
|
|
343
|
+
|
|
344
|
+
- Do not declare `android.permission.CAMERA` for the chat. If your app declares it for another
|
|
345
|
+
feature, request it at runtime before opening the chat, or the chat's picker may lose the camera
|
|
346
|
+
option.
|
|
347
|
+
- Do not add `READ_MEDIA_IMAGES` or `READ_EXTERNAL_STORAGE` for the chat.
|
|
348
|
+
- `react-native-webview` registers a `FileProvider` with the authority
|
|
349
|
+
`${applicationId}.fileprovider`. If your app defines one with the same authority, the manifest
|
|
350
|
+
merge fails: rename yours.
|
|
351
|
+
|
|
352
|
+
## Links
|
|
353
|
+
|
|
354
|
+
Links in the chat open in the system browser (`http`, `https`, `mailto` and `tel` only); the chat
|
|
355
|
+
stays open.
|
|
356
|
+
|
|
357
|
+
## Integration rules
|
|
358
|
+
|
|
359
|
+
- Mount `CobbaiChatScreen` once, near the root, as a sibling of your main content, in a container
|
|
360
|
+
with `flex: 1` and `position: 'relative'`.
|
|
361
|
+
- The SDK owns the chat's open and close animation: do not animate, hide or resize
|
|
362
|
+
`CobbaiChatScreen` yourself.
|
|
363
|
+
- The SDK keeps the chat above the keyboard on both platforms: do not wrap it in
|
|
364
|
+
`KeyboardAvoidingView` or add keyboard offsets. On Android, keep
|
|
365
|
+
`android:windowSoftInputMode="adjustResize"` on your activity.
|
|
366
|
+
- While the chat is open, the Android back button closes it.
|
|
367
|
+
- The SDK does not change the status bar style.
|
|
368
|
+
- The SDK never plays sounds. To play one on a reply, use `onNewMessage` (for example only when
|
|
369
|
+
`chatVisible` is `false`) with your app's audio and silent-mode policy.
|
|
370
|
+
|
|
371
|
+
## Versions
|
|
372
|
+
|
|
373
|
+
The SDK follows semantic versioning: 1.0.x versions fix bugs, 1.x versions add features without
|
|
374
|
+
breaking changes, and a new major version (2.0) may need changes in your app (rare, announced).
|
|
375
|
+
|
|
376
|
+
Backend changes never break a released SDK version. Each SDK major version keeps working for at
|
|
377
|
+
least 6 months after the next major version is released; that release is the end-of-support
|
|
378
|
+
announcement.
|
|
379
|
+
|
|
380
|
+
`SDK_VERSION` is exported. The SDK sends it to Cobbai so that the server stays compatible with
|
|
381
|
+
every release in use; please include it when you contact Cobbai support.
|
|
382
|
+
|
|
383
|
+
## License
|
|
384
|
+
|
|
385
|
+
Proprietary. Use of this SDK is subject to the [LICENSE](LICENSE) included in the package and to
|
|
386
|
+
your agreement with Cobbai.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Animated } from 'react-native';
|
|
3
|
+
type ChatPlaceholderMode = 'loading' | 'unavailable';
|
|
4
|
+
type ChatPlaceholderProps = {
|
|
5
|
+
mode: ChatPlaceholderMode;
|
|
6
|
+
locale: string | undefined;
|
|
7
|
+
opacity: Animated.Value;
|
|
8
|
+
onClose: () => void;
|
|
9
|
+
onRetry: () => void;
|
|
10
|
+
};
|
|
11
|
+
export declare function ChatPlaceholder(props: ChatPlaceholderProps): React.JSX.Element;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=ChatPlaceholder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatPlaceholder.d.ts","sourceRoot":"","sources":["../src/ChatPlaceholder.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAC;AACvC,OAAO,EAAqB,QAAQ,EAAqC,MAAM,cAAc,CAAC;AAG9F,KAAK,mBAAmB,GAAG,SAAS,GAAG,aAAa,CAAC;AAErD,KAAK,oBAAoB,GAAG;IAC1B,IAAI,EAAE,mBAAmB,CAAC;IAC1B,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC;IACxB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAEF,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAyC9E"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChatPlaceholder = ChatPlaceholder;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const react_native_1 = require("react-native");
|
|
7
|
+
const chatUnavailable_1 = require("./chatUnavailable");
|
|
8
|
+
function ChatPlaceholder(props) {
|
|
9
|
+
const { mode, locale, opacity, onClose, onRetry } = props;
|
|
10
|
+
const copy = (0, react_1.useMemo)(() => (0, chatUnavailable_1.getChatUnavailableCopy)(locale), [locale]);
|
|
11
|
+
return ((0, jsx_runtime_1.jsxs)(react_native_1.Animated.View, { style: [styles.root, { opacity }], pointerEvents: "auto", children: [(0, jsx_runtime_1.jsx)(react_native_1.Pressable, { accessibilityRole: "button", accessibilityLabel: copy.close, testID: "cobbai-placeholder-close", onPress: onClose, style: styles.closeButton, children: (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.closeIcon, children: [(0, jsx_runtime_1.jsx)(react_native_1.View, { style: [styles.closeBar, styles.closeBarPrimary] }), (0, jsx_runtime_1.jsx)(react_native_1.View, { style: [styles.closeBar, styles.closeBarSecondary] })] }) }), mode === 'loading' ? ((0, jsx_runtime_1.jsx)(react_native_1.ActivityIndicator, { size: "large" })) : ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.unavailableContainer, testID: "cobbai-unavailable", children: [(0, jsx_runtime_1.jsx)(react_native_1.Text, { accessibilityRole: "header", style: styles.title, children: copy.title }), (0, jsx_runtime_1.jsx)(react_native_1.Text, { numberOfLines: 1, style: styles.body, children: copy.body }), (0, jsx_runtime_1.jsx)(react_native_1.Pressable, { accessibilityRole: "button", testID: "cobbai-unavailable-retry", onPress: onRetry, style: styles.retryButton, children: (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.retryLabel, children: copy.retry }) })] }))] }));
|
|
12
|
+
}
|
|
13
|
+
const styles = react_native_1.StyleSheet.create({
|
|
14
|
+
root: {
|
|
15
|
+
position: 'absolute',
|
|
16
|
+
top: 0,
|
|
17
|
+
right: 0,
|
|
18
|
+
bottom: 0,
|
|
19
|
+
left: 0,
|
|
20
|
+
alignItems: 'center',
|
|
21
|
+
justifyContent: 'center',
|
|
22
|
+
backgroundColor: '#FFFFFF',
|
|
23
|
+
borderTopLeftRadius: 16,
|
|
24
|
+
borderTopRightRadius: 16,
|
|
25
|
+
},
|
|
26
|
+
closeButton: {
|
|
27
|
+
position: 'absolute',
|
|
28
|
+
top: 8,
|
|
29
|
+
right: 8,
|
|
30
|
+
width: 44,
|
|
31
|
+
height: 44,
|
|
32
|
+
alignItems: 'center',
|
|
33
|
+
justifyContent: 'center',
|
|
34
|
+
},
|
|
35
|
+
closeIcon: {
|
|
36
|
+
width: 20,
|
|
37
|
+
height: 20,
|
|
38
|
+
alignItems: 'center',
|
|
39
|
+
justifyContent: 'center',
|
|
40
|
+
},
|
|
41
|
+
closeBar: {
|
|
42
|
+
position: 'absolute',
|
|
43
|
+
width: 18,
|
|
44
|
+
height: 2,
|
|
45
|
+
borderRadius: 1,
|
|
46
|
+
backgroundColor: '#2D2D30',
|
|
47
|
+
},
|
|
48
|
+
closeBarPrimary: {
|
|
49
|
+
transform: [{ rotate: '45deg' }],
|
|
50
|
+
},
|
|
51
|
+
closeBarSecondary: {
|
|
52
|
+
transform: [{ rotate: '-45deg' }],
|
|
53
|
+
},
|
|
54
|
+
unavailableContainer: {
|
|
55
|
+
width: '100%',
|
|
56
|
+
paddingHorizontal: 20,
|
|
57
|
+
alignItems: 'center',
|
|
58
|
+
},
|
|
59
|
+
title: {
|
|
60
|
+
fontSize: 20,
|
|
61
|
+
lineHeight: 26,
|
|
62
|
+
fontWeight: '700',
|
|
63
|
+
color: '#2D2D30',
|
|
64
|
+
},
|
|
65
|
+
body: {
|
|
66
|
+
marginTop: 8,
|
|
67
|
+
fontSize: 14,
|
|
68
|
+
lineHeight: 20,
|
|
69
|
+
color: '#4B4B52',
|
|
70
|
+
},
|
|
71
|
+
retryButton: {
|
|
72
|
+
marginTop: 20,
|
|
73
|
+
minHeight: 44,
|
|
74
|
+
paddingHorizontal: 18,
|
|
75
|
+
borderRadius: 12,
|
|
76
|
+
borderWidth: 1,
|
|
77
|
+
borderColor: '#2D2D30',
|
|
78
|
+
alignItems: 'center',
|
|
79
|
+
justifyContent: 'center',
|
|
80
|
+
},
|
|
81
|
+
retryLabel: {
|
|
82
|
+
fontSize: 15,
|
|
83
|
+
lineHeight: 20,
|
|
84
|
+
fontWeight: '600',
|
|
85
|
+
color: '#2D2D30',
|
|
86
|
+
},
|
|
87
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CobbaiChatScreen.d.ts","sourceRoot":"","sources":["../src/CobbaiChatScreen.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4D,MAAM,OAAO,CAAC;AAoCjF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAErD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAgShF"}
|