@developer_tribe/react-native-comnyx 0.4.1 → 0.4.3

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.
Files changed (65) hide show
  1. package/lib/commonjs/Accumulator.js +1 -2
  2. package/lib/commonjs/Accumulator.js.map +1 -1
  3. package/lib/commonjs/api/customers.js +6 -2
  4. package/lib/commonjs/api/customers.js.map +1 -1
  5. package/lib/commonjs/components/ChatList.js +16 -16
  6. package/lib/commonjs/components/ChatList.js.map +1 -1
  7. package/lib/commonjs/components/CustomerForm.js +3 -2
  8. package/lib/commonjs/components/CustomerForm.js.map +1 -1
  9. package/lib/commonjs/components/MessageInput.js +2 -1
  10. package/lib/commonjs/components/MessageInput.js.map +1 -1
  11. package/lib/commonjs/data/fake/customers.js +0 -1
  12. package/lib/commonjs/data/fake/customers.js.map +1 -1
  13. package/lib/commonjs/hooks/usePolling.js +7 -7
  14. package/lib/commonjs/hooks/usePolling.js.map +1 -1
  15. package/lib/commonjs/register.js +2 -2
  16. package/lib/commonjs/register.js.map +1 -1
  17. package/lib/module/Accumulator.js +1 -2
  18. package/lib/module/Accumulator.js.map +1 -1
  19. package/lib/module/api/customers.js +6 -2
  20. package/lib/module/api/customers.js.map +1 -1
  21. package/lib/module/components/ChatList.js +16 -16
  22. package/lib/module/components/ChatList.js.map +1 -1
  23. package/lib/module/components/CustomerForm.js +3 -2
  24. package/lib/module/components/CustomerForm.js.map +1 -1
  25. package/lib/module/components/MessageInput.js +2 -1
  26. package/lib/module/components/MessageInput.js.map +1 -1
  27. package/lib/module/data/fake/customers.js +0 -1
  28. package/lib/module/data/fake/customers.js.map +1 -1
  29. package/lib/module/hooks/usePolling.js +7 -7
  30. package/lib/module/hooks/usePolling.js.map +1 -1
  31. package/lib/module/register.js +2 -2
  32. package/lib/module/register.js.map +1 -1
  33. package/lib/typescript/commonjs/src/Accumulator.d.ts +1 -1
  34. package/lib/typescript/commonjs/src/Accumulator.d.ts.map +1 -1
  35. package/lib/typescript/commonjs/src/api/customers.d.ts +1 -1
  36. package/lib/typescript/commonjs/src/api/customers.d.ts.map +1 -1
  37. package/lib/typescript/commonjs/src/components/ChatList.d.ts.map +1 -1
  38. package/lib/typescript/commonjs/src/components/CustomerForm.d.ts.map +1 -1
  39. package/lib/typescript/commonjs/src/components/MessageInput.d.ts.map +1 -1
  40. package/lib/typescript/commonjs/src/data/fake/customers.d.ts.map +1 -1
  41. package/lib/typescript/commonjs/src/register.d.ts.map +1 -1
  42. package/lib/typescript/commonjs/src/types/Customer.d.ts +1 -1
  43. package/lib/typescript/commonjs/src/types/Customer.d.ts.map +1 -1
  44. package/lib/typescript/module/src/Accumulator.d.ts +1 -1
  45. package/lib/typescript/module/src/Accumulator.d.ts.map +1 -1
  46. package/lib/typescript/module/src/api/customers.d.ts +1 -1
  47. package/lib/typescript/module/src/api/customers.d.ts.map +1 -1
  48. package/lib/typescript/module/src/components/ChatList.d.ts.map +1 -1
  49. package/lib/typescript/module/src/components/CustomerForm.d.ts.map +1 -1
  50. package/lib/typescript/module/src/components/MessageInput.d.ts.map +1 -1
  51. package/lib/typescript/module/src/data/fake/customers.d.ts.map +1 -1
  52. package/lib/typescript/module/src/register.d.ts.map +1 -1
  53. package/lib/typescript/module/src/types/Customer.d.ts +1 -1
  54. package/lib/typescript/module/src/types/Customer.d.ts.map +1 -1
  55. package/package.json +1 -1
  56. package/src/Accumulator.ts +1 -5
  57. package/src/api/customers.ts +7 -2
  58. package/src/components/ChatList.tsx +16 -21
  59. package/src/components/CustomerForm.tsx +4 -2
  60. package/src/components/MessageInput.tsx +2 -1
  61. package/src/data/fake/customers.ts +0 -1
  62. package/src/data/fake/messages.ts +1 -1
  63. package/src/hooks/usePolling.ts +5 -5
  64. package/src/register.ts +9 -8
  65. package/src/types/Customer.ts +1 -1
@@ -10,7 +10,6 @@ export interface IntegrationParameters {
10
10
  onesignal?: OneSignalIntegrationParameters;
11
11
  }
12
12
  export interface CreateCustomerRequest {
13
- externalId: string;
14
13
  name?: string;
15
14
  country?: string;
16
15
  language?: string;
@@ -36,5 +35,6 @@ export interface Customer {
36
35
  created_at: string;
37
36
  updated_at: string;
38
37
  deleted_at: null | string;
38
+ integration_parameters: IntegrationParameters;
39
39
  }
40
40
  //# sourceMappingURL=Customer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Customer.d.ts","sourceRoot":"","sources":["../../../../../src/types/Customer.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,8BAA8B;IAC7C,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,qBAAqB;IACpC,SAAS,CAAC,EAAE,8BAA8B,CAAC;CAC5C;AAED,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,eAAe,EAAE,CAAC;IACrC,qBAAqB,CAAC,EAAE,qBAAqB,CAAC;CAC/C;AAED,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,IAAI,GAAG,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,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B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,IAAI,GAAG,MAAM,CAAC;IAC1B,sBAAsB,EAAE,qBAAqB,CAAC;CAC/C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@developer_tribe/react-native-comnyx",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "React Native chat component with integrated support panel, enabling real-time customer communication and efficient agent workflow management.",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/commonjs/index.js",
@@ -10,12 +10,8 @@ class Accumulator {
10
10
  private _isListenerCalledOnce: boolean = false;
11
11
  constructor() {}
12
12
 
13
- register(
14
- externalId: string,
15
- listener: (data: CreateCustomerRequest) => Promise<void>
16
- ) {
13
+ register(listener: (data: CreateCustomerRequest) => Promise<void>) {
17
14
  this.registerData = {
18
- externalId,
19
15
  customParameters: [],
20
16
  integrationParameters: {},
21
17
  };
@@ -5,13 +5,18 @@ import { axiosInstance } from './api';
5
5
 
6
6
  export function createCustomer(
7
7
  customerData: CreateCustomerRequest,
8
- options: ApiOptions
8
+ options: ApiOptions,
9
+ externalId: string
9
10
  ): Promise<Customer> {
10
11
  if (options.fake) {
11
12
  return Promise.resolve(getFakeCustomer(customerData));
12
13
  }
13
14
  console.info('[Comnyx] Adding customer info');
14
15
  return axiosInstance
15
- .post('/api/customers/create', customerData)
16
+ .post('/api/customers/create', customerData, {
17
+ headers: {
18
+ 'external-id': externalId,
19
+ },
20
+ })
16
21
  .then((res) => res.data);
17
22
  }
@@ -47,10 +47,10 @@ export function ChatList({ onBack }: { onBack?: () => void }) {
47
47
  (windowHeight - FLATLIST_PADDING) / MESSAGE_MIN_HEIGHT
48
48
  );
49
49
  const [loading, setLoading] = useState(true);
50
- const { customer, data, setData } = useAppStore((s) => ({
51
- customer: s.customer,
50
+ const { data, setData, externalId } = useAppStore((s) => ({
52
51
  data: s.data,
53
52
  setData: s.setData,
53
+ externalId: s.externalId,
54
54
  }));
55
55
  const ref = useRef<SectionList<AppConversationMessage>>(null);
56
56
  const [page, setPage] = useState(1);
@@ -131,7 +131,7 @@ export function ChatList({ onBack }: { onBack?: () => void }) {
131
131
  }, [data]);
132
132
 
133
133
  const resendMessage = useCallback(() => {
134
- if (selectedMessage && customer?.external_id) {
134
+ if (selectedMessage && externalId) {
135
135
  const currentMessage = useAppStore.getState().data || [];
136
136
  const messageIndex = currentMessage.findIndex(
137
137
  (msg) => msg.content === selectedMessage
@@ -155,7 +155,7 @@ export function ChatList({ onBack }: { onBack?: () => void }) {
155
155
  data: updatedValue,
156
156
  });
157
157
 
158
- sendCustomerMessage(customer.external_id, selectedMessage, {
158
+ sendCustomerMessage(externalId, selectedMessage, {
159
159
  fake: useAppStore.getState().fake,
160
160
  })
161
161
  .then((res: any) => {
@@ -214,26 +214,21 @@ export function ChatList({ onBack }: { onBack?: () => void }) {
214
214
  });
215
215
  }
216
216
  }
217
- }, [selectedMessage, customer]);
217
+ }, [selectedMessage, externalId]);
218
218
 
219
219
  const nextPage = useCallback(() => {
220
220
  if (nextPageStatus.current) {
221
221
  return;
222
222
  }
223
223
  nextPageStatus.current = 'loading';
224
- if (customer?.external_id) {
224
+ if (externalId) {
225
225
  const newPage = page + 1;
226
226
  setPage(newPage);
227
227
  const firstMessage = useAppStore.getState().firstMessage;
228
- getCustomerConversation(
229
- customer?.external_id,
230
- firstMessage?.created_at,
231
- newPage,
232
- {
233
- fake: useAppStore.getState().fake,
234
- per_page: MESSAGES_PER_PAGE,
235
- }
236
- )
228
+ getCustomerConversation(externalId, firstMessage?.created_at, newPage, {
229
+ fake: useAppStore.getState().fake,
230
+ per_page: MESSAGES_PER_PAGE,
231
+ })
237
232
  .then((newData) => {
238
233
  listChangedRef.current = true;
239
234
  setData((prevData) => {
@@ -282,7 +277,7 @@ export function ChatList({ onBack }: { onBack?: () => void }) {
282
277
  setLoading(false);
283
278
  });
284
279
  }
285
- }, [MESSAGES_PER_PAGE, customer?.external_id, page, setData]);
280
+ }, [MESSAGES_PER_PAGE, externalId, page, setData]);
286
281
 
287
282
  const renderItem = useCallback(
288
283
  ({ item }: { item: AppConversationMessage }) => {
@@ -417,8 +412,8 @@ export function ChatList({ onBack }: { onBack?: () => void }) {
417
412
  );
418
413
 
419
414
  useEffect(() => {
420
- if (customer?.external_id && !initFailed) {
421
- getCustomerConversation(customer?.external_id, new Date(), 1, {
415
+ if (externalId && !initFailed) {
416
+ getCustomerConversation(externalId, new Date(), 1, {
422
417
  fake: useAppStore.getState().fake,
423
418
  per_page: MESSAGES_PER_PAGE,
424
419
  })
@@ -468,7 +463,7 @@ export function ChatList({ onBack }: { onBack?: () => void }) {
468
463
  setLoading(false);
469
464
  });
470
465
  }
471
- }, [MESSAGES_PER_PAGE, customer?.external_id, initFailed, setData]);
466
+ }, [MESSAGES_PER_PAGE, externalId, initFailed, setData]);
472
467
 
473
468
  // Initialize the current section when sections are loaded
474
469
  useEffect(() => {
@@ -568,6 +563,7 @@ export function ChatList({ onBack }: { onBack?: () => void }) {
568
563
  >
569
564
  <AppText
570
565
  localization="chat.support-team"
566
+ weight={'600'}
571
567
  style={[styles.header, { color: themeColors.text }]}
572
568
  />
573
569
  <View
@@ -742,12 +738,11 @@ const styles = ScaledSheet.create({
742
738
  header: {
743
739
  fontSize: '16@vs',
744
740
  textAlign: 'center',
745
- fontWeight: 600,
746
741
  },
747
742
  liveChat: {
748
743
  fontSize: '16@vs',
749
744
  textAlign: 'center',
750
- fontWeight: 600,
745
+ fontWeight: 400,
751
746
  },
752
747
  headerContainer: {
753
748
  alignItems: 'center',
@@ -65,6 +65,8 @@ export function CustomerForm({ onBack }: { onBack: () => void }) {
65
65
  setLoading(false);
66
66
  }, 100);
67
67
  });
68
+ } else {
69
+ setLoading(false);
68
70
  }
69
71
  }, []);
70
72
 
@@ -74,10 +76,10 @@ export function CustomerForm({ onBack }: { onBack: () => void }) {
74
76
  {
75
77
  ...data,
76
78
  language: 'en',
77
- externalId: useAppStore.getState().externalId || '',
78
79
  customParameters: [],
79
80
  },
80
- { fake: useAppStore.getState().fake }
81
+ { fake: useAppStore.getState().fake },
82
+ useAppStore.getState().externalId || ''
81
83
  );
82
84
  if (customer !== undefined) {
83
85
  useAppStore.getState().setForm(customer);
@@ -17,6 +17,7 @@ export function MessageInput({
17
17
  }) {
18
18
  const [value, setValue] = useState('');
19
19
  const customer = useAppStore((s) => s.customer!);
20
+ const externalId = useAppStore((s) => s.externalId);
20
21
  const themeColors = useThemeColors();
21
22
  const localize = useLocalize();
22
23
 
@@ -36,7 +37,7 @@ export function MessageInput({
36
37
  },
37
38
  ...(data ?? []),
38
39
  ]);
39
- sendCustomerMessage(customer.external_id, value, {
40
+ sendCustomerMessage(externalId as string, value, {
40
41
  fake: useAppStore.getState().fake,
41
42
  })
42
43
  .then((res) => {
@@ -4,7 +4,6 @@ export function getFakeCustomer(customerData: CreateCustomerRequest): Customer {
4
4
  return {
5
5
  id: Math.floor(Math.random() * 1000),
6
6
  project_id: 1,
7
- external_id: customerData.externalId,
8
7
  name: customerData.name!,
9
8
  country: customerData.country!,
10
9
  language: customerData.language!,
@@ -11,7 +11,7 @@ export function getFakeMessageResponse(content: string): MessageResponse {
11
11
  id: Math.floor(Math.random() * 1000),
12
12
  user: null,
13
13
  customer: null,
14
- bot: null ,
14
+ bot: null,
15
15
  conversation: {
16
16
  id: 1,
17
17
  project_id: 1,
@@ -5,18 +5,18 @@ import { getNewCustomerConversation } from '../api';
5
5
  const NEW_MESSAGES_CHECK_INTERVAL = 10000;
6
6
 
7
7
  export function usePolling() {
8
- const { customer, data, setData } = useAppStore((s) => ({
9
- customer: s.customer,
8
+ const { data, setData, externalId } = useAppStore((s) => ({
10
9
  data: s.data,
11
10
  setData: s.setData,
11
+ externalId: s.externalId,
12
12
  }));
13
13
  const lastMessage = data ? data[data.length - 1] : null;
14
14
  useEffect(() => {
15
15
  const created_at = lastMessage?.created_at;
16
16
  let interval: NodeJS.Timeout | null = null;
17
- if (customer?.external_id && created_at) {
17
+ if (externalId && created_at) {
18
18
  interval = setInterval(() => {
19
- getNewCustomerConversation(customer.external_id, created_at, {
19
+ getNewCustomerConversation(externalId, created_at, {
20
20
  fake: useAppStore.getState().fake,
21
21
  }).then((newData) => {
22
22
  setData((prevData) => {
@@ -42,5 +42,5 @@ export function usePolling() {
42
42
  clearInterval(interval);
43
43
  }
44
44
  };
45
- }, [customer?.external_id, lastMessage?.created_at, setData]);
45
+ }, [externalId, lastMessage?.created_at, setData]);
46
46
  }
package/src/register.ts CHANGED
@@ -17,13 +17,14 @@ export function registerComnyx(registerOptions: {
17
17
 
18
18
  initApi(registerOptions.token);
19
19
  useAppStore.getState().init({ externalId: registerOptions.externalId });
20
- accumulator.register(
21
- registerOptions.externalId,
22
- async (accumulatedData: CreateCustomerRequest) => {
23
- const customer = await createCustomer(accumulatedData, {
20
+ accumulator.register(async (accumulatedData: CreateCustomerRequest) => {
21
+ const customer = await createCustomer(
22
+ accumulatedData,
23
+ {
24
24
  fake: false,
25
- });
26
- useAppStore.getState().setCustomer(customer);
27
- }
28
- );
25
+ },
26
+ registerOptions.externalId
27
+ );
28
+ useAppStore.getState().setCustomer(customer);
29
+ });
29
30
  }
@@ -13,7 +13,6 @@ export interface IntegrationParameters {
13
13
  }
14
14
 
15
15
  export interface CreateCustomerRequest {
16
- externalId: string;
17
16
  name?: string;
18
17
  country?: string;
19
18
  language?: string;
@@ -40,4 +39,5 @@ export interface Customer {
40
39
  created_at: string;
41
40
  updated_at: string;
42
41
  deleted_at: null | string;
42
+ integration_parameters: IntegrationParameters;
43
43
  }