@zean-chat/react-native 0.1.12 → 0.1.14

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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Add a free customer support chat inside your iOS and Android app, with [Zean](https://zean.chat/?utm_source=npm&utm_medium=readme&utm_campaign=react-native). Plain React Native: no native module of its own, works in Expo Go. Your App key is in your Zean dashboard.
4
4
 
5
- First, in App settings, set your app's Bundle ID (iOS) and Package name (Android): the chat shows only in that app, and always in Expo Go.
5
+ Before release, in App settings, set your app's Production Bundle ID (iOS) and Production Package name (Android): a release build shows the chat only with those, or with the optional Development ones (a test build such as `com.acme.app.dev`). A development build (`__DEV__`, 0.1.13 or later) and Expo Go always show it.
6
6
 
7
7
  ```bash
8
8
  npx expo install @zean-chat/react-native expo-application @react-native-async-storage/async-storage expo-image-picker
@@ -22,6 +22,8 @@ import { ZeanChat, useZean } from "@zean-chat/react-native";
22
22
  const { open, close, toggle, unreadCount, identify, signOut, setAttributes, setPushToken } = useZean();
23
23
  ```
24
24
 
25
+ `open({ message })` opens the chat with that text in the message field: the person edits it and sends it, nothing goes before. Give the details of the screen they ask from, such as an order number.
26
+
25
27
  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
28
 
27
29
  ## Push notifications
@@ -45,6 +47,18 @@ Notifications.setBadgeCountAsync(unreadCount);
45
47
 
46
48
  `isZeanNotification(data)` tells a Zean push from your own. Full guide: [push notifications](https://zean.chat/docs/push-notifications).
47
49
 
50
+ Your server already sends pushes? Ignore `push.tokens` and skip `setPushToken`. On `message.member`, find the person by `data.contact.externalId` and send `push.title` and `push.body` with your own tokens. Attach `push.data` so `openFromNotification` opens the chat on tap, or call `useZean().open()` in your own tap handler.
51
+
52
+ ## Test devices
53
+
54
+ A development build with 0.1.11 or later, or any build of your Development app, that opened the chat in the last 24 hours is a Test device. Its events never go to the webhook address, only to the Zean CLI. Write a message from it, then:
55
+
56
+ ```bash
57
+ npx zean-cli trigger message.member
58
+ ```
59
+
60
+ It writes a real test reply in its Conversation, so the push is real. See the [Zean CLI](https://zean.chat/docs/cli).
61
+
48
62
  ## Why Zean
49
63
 
50
64
  - Free plan to start. Paid plans in FCFA, payable by Mobile Money.
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * The Contact's message field: a pill with the photo button, when the app installed a picker, and a round send button
3
3
  * in the App's colour. 16 point text; the field grows with the text up to five lines. Emoji come from the phone's keyboard.
4
- * Picked photos show above the field and upload when the message is sent.
4
+ * Picked photos show above the field and upload when the message is sent. A message given to `open()` fills the field.
5
5
  */
6
6
  export declare function Composer(): import("react").JSX.Element;
package/dist/index.d.ts CHANGED
@@ -2,4 +2,4 @@ export { ZeanChat } from './components/ZeanChat';
2
2
  export { useZean } from './hooks/use-zean';
3
3
  export { openFromNotification } from './models/sdk.store';
4
4
  export { isZeanNotification } from './models/sdk.utils';
5
- export type { ZeanAttributeValue, ZeanAttributes, ZeanChatProps, ZeanColorScheme, ZeanControls, ZeanKeyValueStorage, ZeanLocale, ZeanMMKV, ZeanStorage, ZeanUser } from './interfaces';
5
+ export type { ZeanAttributeValue, ZeanAttributes, ZeanChatProps, ZeanColorScheme, ZeanControls, ZeanKeyValueStorage, ZeanLocale, ZeanMMKV, ZeanOpenOptions, ZeanStorage, ZeanUser } from './interfaces';
package/dist/index.js CHANGED
@@ -279,7 +279,13 @@ function createChatStore(backend, options) {
279
279
  state = derive();
280
280
  for (const listener of listeners2) listener();
281
281
  };
282
- const args = () => ({ appKey: options.appKey, deviceSecret, host: options.host, bundle: options.bundle });
282
+ const args = () => ({
283
+ appKey: options.appKey,
284
+ deviceSecret,
285
+ host: options.host,
286
+ bundle: options.bundle,
287
+ ...options.dev ? { dev: true } : {}
288
+ });
283
289
  const deviceLanguage = options.deviceLanguage ?? options.languages[0];
284
290
  const devLoad = options.dev === true || options.host !== void 0 && isLocalHost(options.host) || options.bundle !== void 0 && isExpoGo(options.bundle);
285
291
  const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
@@ -402,7 +408,7 @@ function createChatStore(backend, options) {
402
408
  emit2();
403
409
  if ("report" in result && result.report && !reported) {
404
410
  reported = true;
405
- backend.call("reportInstall", { ...args(), ...options.dev ? { dev: true } : {} }).catch(() => {
411
+ backend.call("reportInstall", args()).catch(() => {
406
412
  });
407
413
  }
408
414
  startOnce();
@@ -437,9 +443,8 @@ function createChatStore(backend, options) {
437
443
  function startOnce() {
438
444
  if (started || state.status === "loading" || state.status === "hidden") return;
439
445
  started = true;
440
- if (state.known || devLoad)
441
- backend.call("start", { ...args(), device: device(), ...options.dev ? { dev: true } : {} }).catch(() => {
442
- });
446
+ if (state.known || devLoad) backend.call("start", { ...args(), device: device() }).catch(() => {
447
+ });
443
448
  for (const entry of outbox) if (entry.error === null) deliver(entry);
444
449
  }
445
450
  function handleTyping(result) {
@@ -6626,19 +6631,34 @@ var identity = null;
6626
6631
  var signOutWaiting = false;
6627
6632
  var attributes = {};
6628
6633
  var pushToken;
6634
+ var draft = null;
6635
+ var notify = () => {
6636
+ for (const listener of listeners) listener();
6637
+ };
6629
6638
  var emit = () => {
6630
6639
  const unread = chat?.getState().unread ?? 0;
6631
6640
  if (view.open === open && view.unread === unread) return;
6632
6641
  view = { open, unread };
6633
- for (const listener of listeners) listener();
6642
+ notify();
6643
+ };
6644
+ var setDraft = (next) => {
6645
+ draft = next;
6646
+ notify();
6634
6647
  };
6635
6648
  var setOpen = (next) => {
6636
6649
  open = next;
6637
6650
  emit();
6638
6651
  };
6639
6652
  var zean = {
6640
- open: () => setOpen(true),
6641
- close: () => setOpen(false),
6653
+ open(options) {
6654
+ const message = options?.message;
6655
+ if (typeof message === "string" && message.trim() !== "") setDraft(message.slice(0, MAX_MESSAGE_LENGTH));
6656
+ setOpen(true);
6657
+ },
6658
+ close() {
6659
+ setDraft(null);
6660
+ setOpen(false);
6661
+ },
6642
6662
  toggle: () => setOpen(!open),
6643
6663
  identify(user) {
6644
6664
  identity = user;
@@ -6683,6 +6703,12 @@ function attachChat(next) {
6683
6703
  function chatView() {
6684
6704
  return view;
6685
6705
  }
6706
+ function chatDraft() {
6707
+ return draft;
6708
+ }
6709
+ function clearDraft() {
6710
+ setDraft(null);
6711
+ }
6686
6712
  function subscribeChatView(listener) {
6687
6713
  listeners.add(listener);
6688
6714
  return () => listeners.delete(listener);
@@ -7401,10 +7427,16 @@ function Composer() {
7401
7427
  const pending = usePendingPhotos();
7402
7428
  const picker = photoPicker();
7403
7429
  const canSend = !pending.sending && (text.trim().length > 0 || pending.photos.length > 0);
7430
+ const draft2 = (0, import_react8.useSyncExternalStore)(subscribeChatView, chatDraft);
7404
7431
  const changeText = (value) => {
7405
7432
  typed.current = value;
7406
7433
  setText(value);
7407
7434
  };
7435
+ (0, import_react8.useEffect)(() => {
7436
+ if (draft2 === null) return;
7437
+ changeText(draft2);
7438
+ clearDraft();
7439
+ }, [draft2]);
7408
7440
  const handleSend = async () => {
7409
7441
  const attachments = pending.photos.length > 0 ? await pending.send() : [];
7410
7442
  if (!attachments) return;
@@ -50,9 +50,18 @@ export interface ZeanChatProps {
50
50
  */
51
51
  backendUrl?: string;
52
52
  }
53
+ /** How `open()` opens the chat. */
54
+ export interface ZeanOpenOptions {
55
+ /**
56
+ * Text put in the message field, in place of what it held: the person reads it, edits it and sends it. Nothing is
57
+ * sent until they do. Cut at 5,000 characters.
58
+ */
59
+ message?: string;
60
+ }
53
61
  /** The chat's methods, and the count of replies the Contact has not seen. */
54
62
  export interface ZeanControls {
55
- open: () => void;
63
+ /** Opens the chat; with `message`, that text waits in the message field. */
64
+ open: (options?: ZeanOpenOptions) => void;
56
65
  close: () => void;
57
66
  toggle: () => void;
58
67
  /**
@@ -12,4 +12,8 @@ export declare function openFromNotification(data: unknown): boolean;
12
12
  export declare function attachChat(next: Chat): () => void;
13
13
  /** Whether the chat is open and how many replies wait: the same object until one changes. */
14
14
  export declare function chatView(): ChatView;
15
+ /** The text waiting for the message field, or null. */
16
+ export declare function chatDraft(): string | null;
17
+ /** The message field took the draft. */
18
+ export declare function clearDraft(): void;
15
19
  export declare function subscribeChatView(listener: () => void): () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zean-chat/react-native",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
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",