@zean-chat/react-native 0.1.9 → 0.1.11
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/README.md +22 -1
- package/dist/components/TeamAvatar.d.ts +2 -2
- package/dist/i18n/en.d.ts +2 -0
- package/dist/i18n/fr.d.ts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +166 -69
- package/dist/interfaces.d.ts +6 -0
- package/dist/models/sdk.interface.d.ts +3 -1
- package/dist/models/sdk.store.d.ts +5 -0
- package/dist/models/sdk.utils.d.ts +8 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,11 +19,32 @@ import { ZeanChat, useZean } from "@zean-chat/react-native";
|
|
|
19
19
|
<ZeanChat appKey="app_your_app_key" user={user ? { id: user.id, name: user.name, email: user.email } : undefined} locale="fr" />;
|
|
20
20
|
|
|
21
21
|
// Anywhere. The chat opens in a modal over the app.
|
|
22
|
-
const { open, close, toggle, unreadCount, identify, signOut, setAttributes } = useZean();
|
|
22
|
+
const { open, close, toggle, unreadCount, identify, signOut, setAttributes, setPushToken } = useZean();
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
Passing `user` signs the person in; `undefined` signs them out. `locale` (`fr`, `en`) and `colorScheme` (`light`, `dark`) default to the phone's. `maxPhotos` sets the photos per message, 1 to 6; 4 by default. The chat keeps the newest 100 messages in your app's storage: it shows them at once and downloads only new ones. To choose the storage, pass `storage`: AsyncStorage, an MMKV instance (any version) or anything with `getItem` and `setItem`. Full guide: [install the chat in React Native and Expo](https://zean.chat/docs/install-react-native), [React Native reference](https://zean.chat/docs/reference-react-native).
|
|
26
26
|
|
|
27
|
+
## Push notifications
|
|
28
|
+
|
|
29
|
+
Zean never sends a push itself: your server does, from the `message.member` webhook.
|
|
30
|
+
|
|
31
|
+
1. In App settings > Developers, set your webhook address.
|
|
32
|
+
2. Give the chat the phone's push token: `useZean().setPushToken(token)`. It is given again after a sign-out by itself.
|
|
33
|
+
3. On `message.member`, your server sends `push.title` and `push.body` to `push.tokens`, with `push.data` as the notification's data.
|
|
34
|
+
4. Open the chat on tap, from a cold start too:
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
import { openFromNotification, useZean } from "@zean-chat/react-native";
|
|
38
|
+
|
|
39
|
+
Notifications.addNotificationResponseReceivedListener(response => openFromNotification(response.notification.request.content.data));
|
|
40
|
+
|
|
41
|
+
// The app icon's badge.
|
|
42
|
+
const { unreadCount } = useZean();
|
|
43
|
+
Notifications.setBadgeCountAsync(unreadCount);
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
`isZeanNotification(data)` tells a Zean push from your own. Full guide: [push notifications](https://zean.chat/docs/push-notifications).
|
|
47
|
+
|
|
27
48
|
## Why Zean
|
|
28
49
|
|
|
29
50
|
- Free plan to start. Paid plans in FCFA, payable by Mobile Money.
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { TeamAvatarProps } from '../models/sdk.interface';
|
|
2
|
-
/** Beside the team's messages: the Member's photo or initials, else the App's logo or initial. */
|
|
3
|
-
export declare function TeamAvatar({ app, sender }: TeamAvatarProps): import("react").JSX.Element;
|
|
2
|
+
/** Beside the team's messages: the Member's photo or initials, else the App's logo or initial; for an AI reply, the sparkles. */
|
|
3
|
+
export declare function TeamAvatar({ app, sender, ai }: TeamAvatarProps): import("react").JSX.Element;
|
package/dist/i18n/en.d.ts
CHANGED
package/dist/i18n/fr.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { ZeanChat } from './components/ZeanChat';
|
|
2
2
|
export { useZean } from './hooks/use-zean';
|
|
3
|
+
export { openFromNotification } from './models/sdk.store';
|
|
4
|
+
export { isZeanNotification } from './models/sdk.utils';
|
|
3
5
|
export type { ZeanAttributeValue, ZeanAttributes, ZeanChatProps, ZeanColorScheme, ZeanControls, ZeanKeyValueStorage, ZeanLocale, ZeanMMKV, ZeanStorage, ZeanUser } from './interfaces';
|
package/dist/index.js
CHANGED
|
@@ -21,6 +21,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
ZeanChat: () => ZeanChat,
|
|
24
|
+
isZeanNotification: () => isZeanNotification,
|
|
25
|
+
openFromNotification: () => openFromNotification,
|
|
24
26
|
useZean: () => useZean
|
|
25
27
|
});
|
|
26
28
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -65,8 +67,10 @@ var RESERVED_CONTACT_ATTRIBUTES = [
|
|
|
65
67
|
];
|
|
66
68
|
var MISSED_REPLY_DELAY_MS = 60 * 6e4;
|
|
67
69
|
var MAX_MESSAGE_LENGTH = 5e3;
|
|
70
|
+
var TEST_DEVICE_MAX_AGE_MS = 24 * 60 * 60 * 1e3;
|
|
68
71
|
|
|
69
72
|
// ../shared/src/constants/widget.ts
|
|
73
|
+
var EXPO_GO_BUNDLE_ID = "host.exp.exponent";
|
|
70
74
|
var DEFAULT_WIDGET_TEXTS = {
|
|
71
75
|
fr: {
|
|
72
76
|
header: "Bonjour ! Comment pouvons-nous vous aider ?",
|
|
@@ -164,6 +168,15 @@ function languageTag(value) {
|
|
|
164
168
|
}).join("-");
|
|
165
169
|
}
|
|
166
170
|
|
|
171
|
+
// ../shared/src/utils/domains.ts
|
|
172
|
+
function isLocalHost(host) {
|
|
173
|
+
const hostname = host.toLowerCase().replace(/:\d+$/, "");
|
|
174
|
+
return hostname === "localhost" || hostname === "127.0.0.1";
|
|
175
|
+
}
|
|
176
|
+
function isExpoGo(bundle) {
|
|
177
|
+
return bundle.id.toLowerCase() === EXPO_GO_BUNDLE_ID;
|
|
178
|
+
}
|
|
179
|
+
|
|
167
180
|
// ../shared/src/utils/widget.ts
|
|
168
181
|
var WEEKDAYS = { Mon: 1, Tue: 2, Wed: 3, Thu: 4, Fri: 5, Sat: 6, Sun: 7 };
|
|
169
182
|
function isWithinBusinessHours(hours, at) {
|
|
@@ -257,6 +270,8 @@ function createChatStore(backend, options) {
|
|
|
257
270
|
let identified = false;
|
|
258
271
|
let identifiedKnown = false;
|
|
259
272
|
let watchers = [];
|
|
273
|
+
let pushToken2;
|
|
274
|
+
let pushSent = null;
|
|
260
275
|
let destroyed = false;
|
|
261
276
|
let state = derive();
|
|
262
277
|
const emit2 = () => {
|
|
@@ -266,16 +281,20 @@ function createChatStore(backend, options) {
|
|
|
266
281
|
};
|
|
267
282
|
const args = () => ({ appKey: options.appKey, deviceSecret, host: options.host, bundle: options.bundle });
|
|
268
283
|
const deviceLanguage = options.deviceLanguage ?? options.languages[0];
|
|
284
|
+
const devLoad = options.dev === true || options.host !== void 0 && isLocalHost(options.host) || options.bundle !== void 0 && isExpoGo(options.bundle);
|
|
285
|
+
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
269
286
|
const device = () => ({
|
|
270
287
|
locale: state.locale,
|
|
271
288
|
...deviceLanguage ? { language: deviceLanguage } : {},
|
|
272
289
|
browser: options.browser,
|
|
273
|
-
os: options.os
|
|
290
|
+
os: options.os,
|
|
291
|
+
timeZone
|
|
274
292
|
});
|
|
275
293
|
const deviceWaiters = [];
|
|
276
294
|
const useSecret = (secret) => {
|
|
277
295
|
deviceSecret = secret;
|
|
278
296
|
for (const resolve of deviceWaiters.splice(0)) resolve();
|
|
297
|
+
sendPushToken();
|
|
279
298
|
};
|
|
280
299
|
const deviceKnown = () => deviceSecret || destroyed ? Promise.resolve() : new Promise((resolve) => deviceWaiters.push(resolve));
|
|
281
300
|
const starting = (async () => {
|
|
@@ -405,11 +424,22 @@ function createChatStore(backend, options) {
|
|
|
405
424
|
return { ok: false, code: codeOf(error) };
|
|
406
425
|
}
|
|
407
426
|
}
|
|
427
|
+
function sendPushToken() {
|
|
428
|
+
if (pushToken2 === void 0 || !deviceSecret || destroyed) return;
|
|
429
|
+
if (pushSent?.deviceSecret === deviceSecret && pushSent.token === pushToken2) return;
|
|
430
|
+
const sent = { deviceSecret, token: pushToken2 };
|
|
431
|
+
pushSent = sent;
|
|
432
|
+
backend.call("setPushToken", { ...args(), token: pushToken2 }).catch((error) => {
|
|
433
|
+
if (pushSent === sent) pushSent = null;
|
|
434
|
+
if (codeOf(error) === "invalid_push_token") console.warn(`${APP_NAME}: the push token was refused: it is too long.`);
|
|
435
|
+
});
|
|
436
|
+
}
|
|
408
437
|
function startOnce() {
|
|
409
438
|
if (started || state.status === "loading" || state.status === "hidden") return;
|
|
410
439
|
started = true;
|
|
411
|
-
if (state.known
|
|
412
|
-
|
|
440
|
+
if (state.known || devLoad)
|
|
441
|
+
backend.call("start", { ...args(), device: device(), ...options.dev ? { dev: true } : {} }).catch(() => {
|
|
442
|
+
});
|
|
413
443
|
for (const entry of outbox) if (entry.error === null) deliver(entry);
|
|
414
444
|
}
|
|
415
445
|
function handleTyping(result) {
|
|
@@ -468,6 +498,8 @@ function createChatStore(backend, options) {
|
|
|
468
498
|
outbox = outbox.filter((other) => other.clientId !== entry.clientId);
|
|
469
499
|
saveOutbox();
|
|
470
500
|
emit2();
|
|
501
|
+
backend.reportCountry({ ...args(), timeZone, language: deviceLanguage }).catch(() => {
|
|
502
|
+
});
|
|
471
503
|
},
|
|
472
504
|
(error) => {
|
|
473
505
|
outbox = outbox.map((other) => other.clientId === entry.clientId ? { ...other, error: codeOf(error) } : other);
|
|
@@ -853,6 +885,10 @@ function createChatStore(backend, options) {
|
|
|
853
885
|
emit2();
|
|
854
886
|
watchAll();
|
|
855
887
|
},
|
|
888
|
+
setPushToken(token) {
|
|
889
|
+
pushToken2 = token?.trim() || null;
|
|
890
|
+
sendPushToken();
|
|
891
|
+
},
|
|
856
892
|
async joinWithPass(pass) {
|
|
857
893
|
await starting;
|
|
858
894
|
await deviceKnown();
|
|
@@ -6240,6 +6276,14 @@ function convexBackend(url) {
|
|
|
6240
6276
|
throw withCode(error);
|
|
6241
6277
|
});
|
|
6242
6278
|
},
|
|
6279
|
+
// A WebSocket hides the connection from Convex functions: a plain request to an HTTP action, through Cloudflare.
|
|
6280
|
+
reportCountry: async (report) => {
|
|
6281
|
+
const response = await fetch(`${url.replace(/\/$/, "")}/http/widget/country`, {
|
|
6282
|
+
method: "POST",
|
|
6283
|
+
body: JSON.stringify(report)
|
|
6284
|
+
});
|
|
6285
|
+
if (!response.ok) throw new Error(`Country report failed: ${response.status}`);
|
|
6286
|
+
},
|
|
6243
6287
|
watchConnection: (onChange) => {
|
|
6244
6288
|
onChange(client.connectionState().isWebSocketConnected);
|
|
6245
6289
|
return client.subscribeToConnectionState((state) => onChange(state.isWebSocketConnected));
|
|
@@ -6264,66 +6308,6 @@ function backendUrlFor(appKey) {
|
|
|
6264
6308
|
return isStagingKey(appKey) ? STAGING_BACKEND_URL : PRODUCTION_BACKEND_URL;
|
|
6265
6309
|
}
|
|
6266
6310
|
|
|
6267
|
-
// src/models/sdk.store.ts
|
|
6268
|
-
var chat = null;
|
|
6269
|
-
var open = false;
|
|
6270
|
-
var view = { open: false, unread: 0 };
|
|
6271
|
-
var listeners = /* @__PURE__ */ new Set();
|
|
6272
|
-
var identity = null;
|
|
6273
|
-
var signOutWaiting = false;
|
|
6274
|
-
var attributes = {};
|
|
6275
|
-
var emit = () => {
|
|
6276
|
-
const unread = chat?.getState().unread ?? 0;
|
|
6277
|
-
if (view.open === open && view.unread === unread) return;
|
|
6278
|
-
view = { open, unread };
|
|
6279
|
-
for (const listener of listeners) listener();
|
|
6280
|
-
};
|
|
6281
|
-
var setOpen = (next) => {
|
|
6282
|
-
open = next;
|
|
6283
|
-
emit();
|
|
6284
|
-
};
|
|
6285
|
-
var zean = {
|
|
6286
|
-
open: () => setOpen(true),
|
|
6287
|
-
close: () => setOpen(false),
|
|
6288
|
-
toggle: () => setOpen(!open),
|
|
6289
|
-
identify(user) {
|
|
6290
|
-
identity = user;
|
|
6291
|
-
void chat?.identify(user);
|
|
6292
|
-
},
|
|
6293
|
-
signOut() {
|
|
6294
|
-
identity = null;
|
|
6295
|
-
attributes = {};
|
|
6296
|
-
if (chat) void chat.signOut();
|
|
6297
|
-
else signOutWaiting = true;
|
|
6298
|
-
},
|
|
6299
|
-
setAttributes(next) {
|
|
6300
|
-
attributes = { ...attributes, ...next };
|
|
6301
|
-
void chat?.setAttributes(next);
|
|
6302
|
-
}
|
|
6303
|
-
};
|
|
6304
|
-
function attachChat(next) {
|
|
6305
|
-
if (chat) console.warn(`${APP_NAME}: render <ZeanChat> once, near the root of the app.`);
|
|
6306
|
-
chat = next;
|
|
6307
|
-
if (identity) void next.identify(identity);
|
|
6308
|
-
else if (signOutWaiting) void next.signOut();
|
|
6309
|
-
signOutWaiting = false;
|
|
6310
|
-
if (Object.keys(attributes).length > 0) void next.setAttributes(attributes);
|
|
6311
|
-
const stop = next.subscribe(emit);
|
|
6312
|
-
emit();
|
|
6313
|
-
return () => {
|
|
6314
|
-
stop();
|
|
6315
|
-
if (chat === next) chat = null;
|
|
6316
|
-
emit();
|
|
6317
|
-
};
|
|
6318
|
-
}
|
|
6319
|
-
function chatView() {
|
|
6320
|
-
return view;
|
|
6321
|
-
}
|
|
6322
|
-
function subscribeChatView(listener) {
|
|
6323
|
-
listeners.add(listener);
|
|
6324
|
-
return () => listeners.delete(listener);
|
|
6325
|
-
}
|
|
6326
|
-
|
|
6327
6311
|
// src/models/sdk.utils.ts
|
|
6328
6312
|
var import_react_native = require("react-native");
|
|
6329
6313
|
|
|
@@ -6464,7 +6448,9 @@ var ICONS = {
|
|
|
6464
6448
|
mark: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEgAAABICAYAAABV7bNHAAAEfElEQVR4nOycV6hcRRzGP2MBe4m9YSEaFQuIRkUsIBhbriU2LKigglgeFB81ICgWVIxiQQULiA2NsSchNyHtISGQkJ6HJJBCQnp/CMn38d+Ey+Xu/OecPbt7znB+8GMfZhZ2v3tmzpz/zN5BqAkyCDVB6oAc6oAc6oAc6oAc6oAc6oAcDkHrXEovp0MbnkFPpCc07ATr6YbG6yz6Ox2PAjgI+bi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DobgZNYFUVnMHUMuOXzQboN9iA99IxW6M6qjon8RI9E9emlN3udsh5H+Ru2PK96GURbTiNjOuY5r6NJTT9yGY3qodqQzlneici6dqvFeJ0gGwXbUCxzeWQZ7JCUtsF3ZXljkbsVmp+0FayT6+eje4GpAqGrXHVp/URcPw9fipy0cztHlbxz0f4fAeuBU4s93WmLOiRxgDIdoCol9b+mcKgDcqgDcqgDcqgDcqgDctgHAAD//5X8VgcAAAAGSURBVAMABqK0QlGO9rwAAAAASUVORK5CYII=",
|
|
6465
6449
|
check: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEgAAABICAYAAABV7bNHAAAACXBIWXMAAAsTAAALEwEAmpwYAAABLElEQVR4nO3aSwrCMBRG4X/QUYnrdHvOxQfFfSlKOhGNaZum3tzzQSfiIDncWC1KAAAAAAAA/6iTtJd0iNc+vgZJQdJJ0v3tOhJJrzjDhzjj9Zwkt8KPOPd43FwKGXHcBgqZcVwesTAhzsnbnayXdM6Mc5O0kyM9cb4jTgJxEoiTQJwE4iQQJ4E4CcSxHqfb6InclN9WQ3x/dV18+va+oMvKCzIRR3Faai/MTBzFI1Vzgabi5AQquVBzcX4dsZILNhln/JC+rrxws3FqfBcx8T1nq430rcRZY0PNxSm5sWbjlNhg83GWbNRNnLm3Z9O38rn6CVPhZnLWitRknDnHrfljVXqSmp6cpZPkYnLmTpKryZkayXWcUYjPrms/zzal4z/KAAAAAAAAgNrwALFeI+D8E4TKAAAAAElFTkSuQmCC",
|
|
6466
6450
|
seen: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEgAAABICAYAAABV7bNHAAAACXBIWXMAAAsTAAALEwEAmpwYAAABnElEQVR4nO2aTWrDMBCF3yKribpuj9Ib+WI9QPclTQm9UpbBJWUMxTTWjyV7JL0PRIhJ0OTjSfbYAQghhBBCCCGEEEL25ABgAPCuY9BjBIADcAIwzsYHJeFXzuUfOdO4J6lbnEfOqMutS1yAnG4FuUA5XS4xFyHn1NuZTAB8Bs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kgldf64a2tJzXOR9JA0+OOuG8N5mol53IwmKkn91zDjefmnF1vn7/07T+9nje4+MYxVpLk443GzJhVoiBhpKY5ZoGrmFYsZKSSO2SvmXAMGPCpSSJyXn9FUK+kZMOiea34NvOdNiWgjRjpdnJiRThsnRqTTxzkyUjZxjoiUXZw9I2UbZ49I2cf5J1IxcbZEKi7O2k8Dq0+X02zSUNrmbNmk4jbn300qYnO2blJRm7N2k4rcnNBIxFn4XWP5+yhJdUo//AAAAAAAAAAAAKCcvAFtUXbojKVOAwAAAABJRU5ErkJggg==",
|
|
6452
|
+
/** An AI reply, beside its label and in its avatar. */
|
|
6453
|
+
sparkles: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEgAAABICAYAAABV7bNHAAAACXBIWXMAAAsTAAALEwEAmpwYAAAEvklEQVR4nO1cPUwUQRT+xCjE6rxcVOhMBAs6PbEQTRQSsbAUK39QKAFFC7GiUSoxRCiASm3E1kSMiICIhVCJP2BxJT+SoxAKlZAzk7xLLse+2Zn9Yffm9ktectl9O/Pm3c68n5m3QIQIEQxHCYBmAGMAVoneAWihe15gL4AeAGtEPXQt9EgAmAWQYWiWeNzisUXb4lqoUQrgo0Q5WZoiXjdIW7QrroUaTQrKydJVl31x7YYaExoKGi82BZUB2NRQ0CY9UzQKOsEIvAhgibmX1LRWGU0KlXVrYYR8DWCEuSdcASfWSpdCYd36GeEeAHjI3OtzaK10KRTW7RMj3CUAjcy96WJRUAmAdUa4SgBVzL0NBc/aiCl2lBFsnRQgU6BQnvGL9GVGQOFVZzHN8Ijp5wScUkKJbkbYJzk8fQyPWMCNV9AbRtibOTzNDI9wAYxX0DIj7PEcniTDs2J6sFquGEqI6P0fw3vI5HTHBWbQXyx45xjeBpMTZveZQT+14H3G8HbCYLxkBn3bgreD4R2GwfjJDPqsBe85hncBhiIGYIsZdNyCP87wblFbxuEuM+CU5JkU84yYfsYgRsr5ywz2keTZHuaZP6SkgnuT9gOoBdBOVuibZFpl6ZiDzGN+FvI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@@ function deviceInfoBundleId() {
|
|
|
6575
6561
|
return null;
|
|
6576
6562
|
}
|
|
6577
6563
|
}
|
|
6564
|
+
function isDevBuild() {
|
|
6565
|
+
return typeof __DEV__ !== "undefined" && __DEV__;
|
|
6566
|
+
}
|
|
6567
|
+
function isZeanNotification(data) {
|
|
6568
|
+
const value = objectOf(data);
|
|
6569
|
+
if (!value) return false;
|
|
6570
|
+
if (value.zean === "message" && typeof value.conversationId === "string") return true;
|
|
6571
|
+
const inner = objectOf(value.data);
|
|
6572
|
+
return inner !== null && inner.zean === "message" && typeof inner.conversationId === "string";
|
|
6573
|
+
}
|
|
6574
|
+
function objectOf(data) {
|
|
6575
|
+
let value = data;
|
|
6576
|
+
if (typeof value === "string") {
|
|
6577
|
+
try {
|
|
6578
|
+
value = JSON.parse(value);
|
|
6579
|
+
} catch {
|
|
6580
|
+
return null;
|
|
6581
|
+
}
|
|
6582
|
+
}
|
|
6583
|
+
return typeof value === "object" && value !== null ? value : null;
|
|
6584
|
+
}
|
|
6578
6585
|
function deviceOs() {
|
|
6579
6586
|
if (import_react_native.Platform.OS === "ios") return `iOS ${import_react_native.Platform.Version}`;
|
|
6580
6587
|
if (import_react_native.Platform.OS === "android") return `Android ${import_react_native.Platform.constants.Release}`;
|
|
@@ -6610,6 +6617,77 @@ function hideKeyboard() {
|
|
|
6610
6617
|
});
|
|
6611
6618
|
}
|
|
6612
6619
|
|
|
6620
|
+
// src/models/sdk.store.ts
|
|
6621
|
+
var chat = null;
|
|
6622
|
+
var open = false;
|
|
6623
|
+
var view = { open: false, unread: 0 };
|
|
6624
|
+
var listeners = /* @__PURE__ */ new Set();
|
|
6625
|
+
var identity = null;
|
|
6626
|
+
var signOutWaiting = false;
|
|
6627
|
+
var attributes = {};
|
|
6628
|
+
var pushToken;
|
|
6629
|
+
var emit = () => {
|
|
6630
|
+
const unread = chat?.getState().unread ?? 0;
|
|
6631
|
+
if (view.open === open && view.unread === unread) return;
|
|
6632
|
+
view = { open, unread };
|
|
6633
|
+
for (const listener of listeners) listener();
|
|
6634
|
+
};
|
|
6635
|
+
var setOpen = (next) => {
|
|
6636
|
+
open = next;
|
|
6637
|
+
emit();
|
|
6638
|
+
};
|
|
6639
|
+
var zean = {
|
|
6640
|
+
open: () => setOpen(true),
|
|
6641
|
+
close: () => setOpen(false),
|
|
6642
|
+
toggle: () => setOpen(!open),
|
|
6643
|
+
identify(user) {
|
|
6644
|
+
identity = user;
|
|
6645
|
+
void chat?.identify(user);
|
|
6646
|
+
},
|
|
6647
|
+
signOut() {
|
|
6648
|
+
identity = null;
|
|
6649
|
+
attributes = {};
|
|
6650
|
+
if (chat) void chat.signOut();
|
|
6651
|
+
else signOutWaiting = true;
|
|
6652
|
+
},
|
|
6653
|
+
setAttributes(next) {
|
|
6654
|
+
attributes = { ...attributes, ...next };
|
|
6655
|
+
void chat?.setAttributes(next);
|
|
6656
|
+
},
|
|
6657
|
+
setPushToken(token) {
|
|
6658
|
+
pushToken = token;
|
|
6659
|
+
chat?.setPushToken(token);
|
|
6660
|
+
}
|
|
6661
|
+
};
|
|
6662
|
+
function openFromNotification(data) {
|
|
6663
|
+
if (!isZeanNotification(data)) return false;
|
|
6664
|
+
zean.open();
|
|
6665
|
+
return true;
|
|
6666
|
+
}
|
|
6667
|
+
function attachChat(next) {
|
|
6668
|
+
if (chat) console.warn(`${APP_NAME}: render <ZeanChat> once, near the root of the app.`);
|
|
6669
|
+
chat = next;
|
|
6670
|
+
if (identity) void next.identify(identity);
|
|
6671
|
+
else if (signOutWaiting) void next.signOut();
|
|
6672
|
+
signOutWaiting = false;
|
|
6673
|
+
if (Object.keys(attributes).length > 0) void next.setAttributes(attributes);
|
|
6674
|
+
if (pushToken !== void 0) next.setPushToken(pushToken);
|
|
6675
|
+
const stop = next.subscribe(emit);
|
|
6676
|
+
emit();
|
|
6677
|
+
return () => {
|
|
6678
|
+
stop();
|
|
6679
|
+
if (chat === next) chat = null;
|
|
6680
|
+
emit();
|
|
6681
|
+
};
|
|
6682
|
+
}
|
|
6683
|
+
function chatView() {
|
|
6684
|
+
return view;
|
|
6685
|
+
}
|
|
6686
|
+
function subscribeChatView(listener) {
|
|
6687
|
+
listeners.add(listener);
|
|
6688
|
+
return () => listeners.delete(listener);
|
|
6689
|
+
}
|
|
6690
|
+
|
|
6613
6691
|
// src/components/ChatModal.tsx
|
|
6614
6692
|
var import_react16 = require("react");
|
|
6615
6693
|
var import_react_native23 = require("react-native");
|
|
@@ -6637,6 +6715,8 @@ function useChatContext() {
|
|
|
6637
6715
|
|
|
6638
6716
|
// src/i18n/en.ts
|
|
6639
6717
|
var en = {
|
|
6718
|
+
ai: "AI",
|
|
6719
|
+
request_human: "Talk to a Member",
|
|
6640
6720
|
close_chat: "Close chat",
|
|
6641
6721
|
online: "Online",
|
|
6642
6722
|
away: "Away for now",
|
|
@@ -6691,6 +6771,8 @@ var en = {
|
|
|
6691
6771
|
|
|
6692
6772
|
// src/i18n/fr.ts
|
|
6693
6773
|
var fr = {
|
|
6774
|
+
ai: "IA",
|
|
6775
|
+
request_human: "Parler \xE0 un membre",
|
|
6694
6776
|
close_chat: "Fermer le chat",
|
|
6695
6777
|
online: "En ligne",
|
|
6696
6778
|
away: "Absents pour le moment",
|
|
@@ -7774,8 +7856,19 @@ var styles10 = import_react_native16.StyleSheet.create({
|
|
|
7774
7856
|
// src/components/TeamAvatar.tsx
|
|
7775
7857
|
var import_react_native17 = require("react-native");
|
|
7776
7858
|
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
7777
|
-
function TeamAvatar({ app, sender }) {
|
|
7859
|
+
function TeamAvatar({ app, sender, ai = false }) {
|
|
7778
7860
|
const { colors } = useChatContext();
|
|
7861
|
+
if (ai) {
|
|
7862
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
7863
|
+
import_react_native17.View,
|
|
7864
|
+
{
|
|
7865
|
+
style: [styles11.avatar, { backgroundColor: colors.primaryTint }],
|
|
7866
|
+
accessibilityElementsHidden: true,
|
|
7867
|
+
importantForAccessibility: "no-hide-descendants",
|
|
7868
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Icon, { name: "sparkles", color: colors.primaryText, size: 14 })
|
|
7869
|
+
}
|
|
7870
|
+
);
|
|
7871
|
+
}
|
|
7779
7872
|
const image = sender ? sender.image : app.logoUrl;
|
|
7780
7873
|
if (image) {
|
|
7781
7874
|
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_react_native17.Image, { source: { uri: image }, style: [styles11.avatar, { borderColor: colors.border }], accessibilityIgnoresInvertColors: true });
|
|
@@ -7807,7 +7900,7 @@ var styles11 = import_react_native17.StyleSheet.create({
|
|
|
7807
7900
|
// src/components/MessageBubble.tsx
|
|
7808
7901
|
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
7809
7902
|
function MessageBubble({ row, app, onRetry }) {
|
|
7810
|
-
const { t, locale, colors, openedAt } = useChatContext();
|
|
7903
|
+
const { chat: chat2, t, locale, colors, openedAt } = useChatContext();
|
|
7811
7904
|
const { message, startsRun, endsRun, startsDay } = row;
|
|
7812
7905
|
const own = message.from === "contact";
|
|
7813
7906
|
const rise = useRiseIn(message.createdAt > openedAt && (!own || message.status === "sending"));
|
|
@@ -7830,9 +7923,9 @@ function MessageBubble({ row, app, onRetry }) {
|
|
|
7830
7923
|
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MessageFiles, { attachments: message.attachments, own: true, stored: message.status === "sent" }),
|
|
7831
7924
|
endsRun && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MessageMeta, { row, onRetry })
|
|
7832
7925
|
] }) : /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_react_native18.View, { style: styles12.team, children: [
|
|
7833
|
-
startsRun && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_native18.Text, { style: [styles12.name, { color: colors.muted }], numberOfLines: 1, children: message.sender?.name ?? app.name }),
|
|
7926
|
+
(startsRun || message.ai) && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_native18.Text, { style: [styles12.name, { color: colors.muted }], numberOfLines: 1, children: message.ai ? t.ai : message.sender?.name ?? app.name }),
|
|
7834
7927
|
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_react_native18.View, { style: styles12.teamRow, children: [
|
|
7835
|
-
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_native18.View, { style: styles12.avatar, children: endsRun && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(TeamAvatar, { app, sender: message.sender }) }),
|
|
7928
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_native18.View, { style: styles12.avatar, children: endsRun && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(TeamAvatar, { app, sender: message.sender, ai: message.ai }) }),
|
|
7836
7929
|
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_react_native18.View, { style: styles12.teamColumn, children: [
|
|
7837
7930
|
message.body !== "" && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
7838
7931
|
import_react_native18.Text,
|
|
@@ -7849,6 +7942,7 @@ function MessageBubble({ row, app, onRetry }) {
|
|
|
7849
7942
|
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MessageFiles, { attachments: message.attachments, own: false, stored: true })
|
|
7850
7943
|
] })
|
|
7851
7944
|
] }),
|
|
7945
|
+
message.ai && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_native18.Pressable, { accessibilityRole: "button", onPress: () => chat2.send(t.request_human), hitSlop: 8, style: styles12.teamMeta, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_native18.Text, { style: [styles12.human, { color: colors.primaryText }], children: t.request_human }) }),
|
|
7852
7946
|
endsRun && !row.welcome && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_native18.View, { style: styles12.teamMeta, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MessageMeta, { row, onRetry }) })
|
|
7853
7947
|
] })
|
|
7854
7948
|
] });
|
|
@@ -7875,6 +7969,7 @@ var styles12 = import_react_native18.StyleSheet.create({
|
|
|
7875
7969
|
avatar: { width: AVATAR },
|
|
7876
7970
|
teamColumn: { flexShrink: 1, alignItems: "flex-start", gap: 4 },
|
|
7877
7971
|
teamMeta: { marginLeft: AVATAR + 8 },
|
|
7972
|
+
human: { fontSize: 13, fontWeight: "600", textDecorationLine: "underline", paddingVertical: 8 },
|
|
7878
7973
|
bubble: {
|
|
7879
7974
|
borderRadius: RADII.group,
|
|
7880
7975
|
paddingHorizontal: 14,
|
|
@@ -8182,7 +8277,9 @@ function ZeanChat({
|
|
|
8182
8277
|
// Checked against the App's Bundle ID or Package name: another app with the same key shows no chat.
|
|
8183
8278
|
bundle: appBundle(),
|
|
8184
8279
|
// The Conversation stays on the phone: the next start shows it at once and asks only for newer messages.
|
|
8185
|
-
keep: true
|
|
8280
|
+
keep: true,
|
|
8281
|
+
// A development build: the phone becomes a Test device for App settings > Developers > Webhook.
|
|
8282
|
+
dev: isDevBuild()
|
|
8186
8283
|
});
|
|
8187
8284
|
const detach = attachChat(started);
|
|
8188
8285
|
setChat(started);
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -64,5 +64,11 @@ export interface ZeanControls {
|
|
|
64
64
|
signOut: () => void;
|
|
65
65
|
/** Joined to what was set before. Values the chat cannot keep are refused, and the console says why. */
|
|
66
66
|
setAttributes: (attributes: ZeanAttributes) => void;
|
|
67
|
+
/**
|
|
68
|
+
* The phone's push token, from your push library (`ExponentPushToken[…]`, an FCM or an APNs token), or null once
|
|
69
|
+
* there is none. Zean passes it to your server in each `message.member` webhook event, in `push.tokens`: your server
|
|
70
|
+
* sends the push. Given again after a sign-out by itself; the same token twice sends nothing.
|
|
71
|
+
*/
|
|
72
|
+
setPushToken: (token: string | null) => void;
|
|
67
73
|
unreadCount: number;
|
|
68
74
|
}
|
|
@@ -138,6 +138,8 @@ export interface TeamAvatarProps {
|
|
|
138
138
|
app: ChatApp;
|
|
139
139
|
/** Null: the App. */
|
|
140
140
|
sender: ChatSender | null;
|
|
141
|
+
/** An AI reply: the sparkles, not the sender's initials. */
|
|
142
|
+
ai?: boolean;
|
|
141
143
|
}
|
|
142
144
|
export interface AppMarkProps {
|
|
143
145
|
app: ChatApp;
|
|
@@ -176,7 +178,7 @@ export interface IconProps {
|
|
|
176
178
|
color: string;
|
|
177
179
|
size: number;
|
|
178
180
|
}
|
|
179
|
-
export type IconName = 'close' | 'send' | 'photo' | 'file' | 'download' | 'remove' | 'mark' | 'check' | 'seen' | 'down';
|
|
181
|
+
export type IconName = 'close' | 'send' | 'photo' | 'file' | 'download' | 'remove' | 'mark' | 'check' | 'seen' | 'down' | 'sparkles';
|
|
180
182
|
export interface ExpoImagePickerAsset {
|
|
181
183
|
uri: string;
|
|
182
184
|
fileName?: string | null;
|
|
@@ -3,6 +3,11 @@ import type { ZeanControls } from '../interfaces';
|
|
|
3
3
|
import type { ChatView } from './sdk.interface';
|
|
4
4
|
/** The chat's methods. Usable before `<ZeanChat>` mounts: what is asked waits for the chat. */
|
|
5
5
|
export declare const zean: Omit<ZeanControls, 'unreadCount'>;
|
|
6
|
+
/**
|
|
7
|
+
* Opens the chat when a tapped notification is a push for a Member's reply, and says whether it was. Works before
|
|
8
|
+
* `<ZeanChat>` mounts, as when the tap started the app.
|
|
9
|
+
*/
|
|
10
|
+
export declare function openFromNotification(data: unknown): boolean;
|
|
6
11
|
/** `<ZeanChat>` hands over the chat it started. Returns the way to let it go. */
|
|
7
12
|
export declare function attachChat(next: Chat): () => void;
|
|
8
13
|
/** Whether the chat is open and how many replies wait: the same object until one changes. */
|
|
@@ -25,6 +25,14 @@ export declare function appBundle(): AppBundle | undefined;
|
|
|
25
25
|
* back to memory too.
|
|
26
26
|
*/
|
|
27
27
|
export declare function chatStorage(storage?: ZeanStorage): ChatStorage;
|
|
28
|
+
/** A development build: the phone becomes a Test device, which App settings send Test events as. */
|
|
29
|
+
export declare function isDevBuild(): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Whether a notification's data is a push for a Member's reply: `{ zean: 'message', conversationId }`, as the
|
|
32
|
+
* `message.member` webhook's `push.data` gives it. Also as JSON text, or nested in `{ data }`, as some push setups
|
|
33
|
+
* deliver it.
|
|
34
|
+
*/
|
|
35
|
+
export declare function isZeanNotification(data: unknown): boolean;
|
|
28
36
|
/** "iOS 18.2" or "Android 15", for the Contact panel. */
|
|
29
37
|
export declare function deviceOs(): string | undefined;
|
|
30
38
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zean-chat/react-native",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"description": "In-app support chat for React Native and Expo, iOS and Android. Pure JS, no native module. A free Intercom, Crisp and Zendesk mobile SDK alternative.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native",
|