rn-erxes-sdk 0.1.18 → 0.1.20
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/lib/commonjs/App.js +3 -1
- package/lib/commonjs/App.js.map +1 -1
- package/lib/commonjs/Widget.js +73 -14
- package/lib/commonjs/Widget.js.map +1 -1
- package/lib/commonjs/graphql/mutation.js +13 -144
- package/lib/commonjs/graphql/mutation.js.map +1 -1
- package/lib/commonjs/graphql/query.js +15 -1
- package/lib/commonjs/graphql/query.js.map +1 -1
- package/lib/commonjs/screen/conversation/ConversationDetail.js +0 -11
- package/lib/commonjs/screen/conversation/ConversationDetail.js.map +1 -1
- package/lib/module/App.js +3 -1
- package/lib/module/App.js.map +1 -1
- package/lib/module/Widget.js +76 -16
- package/lib/module/Widget.js.map +1 -1
- package/lib/module/graphql/mutation.js +12 -142
- package/lib/module/graphql/mutation.js.map +1 -1
- package/lib/module/graphql/query.js +14 -1
- package/lib/module/graphql/query.js.map +1 -1
- package/lib/module/screen/conversation/ConversationDetail.js +0 -11
- package/lib/module/screen/conversation/ConversationDetail.js.map +1 -1
- package/lib/typescript/App.d.ts +1 -0
- package/lib/typescript/App.d.ts.map +1 -1
- package/lib/typescript/Widget.d.ts.map +1 -1
- package/lib/typescript/graphql/mutation.d.ts +2 -3
- package/lib/typescript/graphql/mutation.d.ts.map +1 -1
- package/lib/typescript/graphql/query.d.ts +2 -1
- package/lib/typescript/graphql/query.d.ts.map +1 -1
- package/lib/typescript/screen/conversation/ConversationDetail.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/App.tsx +4 -1
- package/src/Widget.tsx +70 -7
- package/src/graphql/mutation.ts +12 -146
- package/src/graphql/query.ts +15 -0
- package/src/screen/conversation/ConversationDetail.tsx +0 -11
package/src/Widget.tsx
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
/* eslint-disable react-hooks/exhaustive-deps */
|
|
1
2
|
/* eslint-disable react-native/no-inline-styles */
|
|
2
3
|
import { View, StyleSheet } from 'react-native';
|
|
3
4
|
import React, { useEffect } from 'react';
|
|
4
|
-
import { useMutation } from '@apollo/client';
|
|
5
|
-
import { connect } from './graphql/mutation';
|
|
5
|
+
import { useMutation, useQuery } from '@apollo/client';
|
|
6
|
+
import { connect, widgetsSaveBrowserInfo } from './graphql/mutation';
|
|
6
7
|
import Greetings from './screen/greetings/Greetings';
|
|
7
8
|
import Conversations from './screen/conversation/Conversations';
|
|
8
9
|
import AppContext from './context/Context';
|
|
@@ -10,6 +11,9 @@ import ConversationDetail from './screen/conversation/ConversationDetail';
|
|
|
10
11
|
import { TouchableOpacity } from 'react-native';
|
|
11
12
|
import { Image } from 'react-native';
|
|
12
13
|
import images from './assets/images';
|
|
14
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
15
|
+
import { widgetsTotalUnreadCount } from './graphql/query';
|
|
16
|
+
import { Text } from 'react-native';
|
|
13
17
|
|
|
14
18
|
const Widget = (props: any) => {
|
|
15
19
|
const {
|
|
@@ -24,8 +28,9 @@ const Widget = (props: any) => {
|
|
|
24
28
|
newChatIcon,
|
|
25
29
|
sendIcon,
|
|
26
30
|
// tracking
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
phone,
|
|
32
|
+
data,
|
|
33
|
+
properties,
|
|
29
34
|
//launcherOption
|
|
30
35
|
show,
|
|
31
36
|
setShow,
|
|
@@ -39,10 +44,20 @@ const Widget = (props: any) => {
|
|
|
39
44
|
null
|
|
40
45
|
);
|
|
41
46
|
|
|
47
|
+
const { data: dataUnreadCount } = useQuery(widgetsTotalUnreadCount, {
|
|
48
|
+
variables: {
|
|
49
|
+
integrationId: response?.data?.widgetsMessengerConnect?.integrationId,
|
|
50
|
+
customerId: connection?.cachedCustomerId || null,
|
|
51
|
+
visitorId: connection?.cachedCustomerId ? null : connection?.visitorId,
|
|
52
|
+
},
|
|
53
|
+
skip: !response,
|
|
54
|
+
fetchPolicy: 'network-only',
|
|
55
|
+
});
|
|
56
|
+
|
|
42
57
|
const [connectMutation] = useMutation(connect);
|
|
58
|
+
const [saveBrowserInfo] = useMutation(widgetsSaveBrowserInfo);
|
|
43
59
|
|
|
44
60
|
useEffect(() => {
|
|
45
|
-
console.log(connection);
|
|
46
61
|
connectMutation({
|
|
47
62
|
variables: {
|
|
48
63
|
brandCode,
|
|
@@ -51,6 +66,8 @@ const Widget = (props: any) => {
|
|
|
51
66
|
visitorId: connection?.visitorId,
|
|
52
67
|
// if client passed email automatically then consider this as user
|
|
53
68
|
isUser: Boolean(email),
|
|
69
|
+
phone: phone ? phone : null,
|
|
70
|
+
data: data ? data : null,
|
|
54
71
|
},
|
|
55
72
|
})
|
|
56
73
|
.then((res: any) => {
|
|
@@ -58,13 +75,40 @@ const Widget = (props: any) => {
|
|
|
58
75
|
const showLauncher =
|
|
59
76
|
res?.data?.widgetsMessengerConnect?.messengerData?.showLauncher;
|
|
60
77
|
setVisibleLauncher(showLauncher);
|
|
78
|
+
|
|
79
|
+
const customerId = res?.data?.widgetsMessengerConnect?.customerId;
|
|
80
|
+
|
|
81
|
+
if (connection?.customerId !== customerId) {
|
|
82
|
+
const jsonValue = JSON.stringify(customerId);
|
|
83
|
+
AsyncStorage.setItem('cachedCustomerId', jsonValue);
|
|
84
|
+
setConnection({
|
|
85
|
+
visitorId: connection?.visitorId,
|
|
86
|
+
cachedCustomerId: customerId,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
61
89
|
})
|
|
62
90
|
.catch((err) => {
|
|
63
91
|
console.log(err);
|
|
64
92
|
});
|
|
65
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
66
93
|
}, []);
|
|
67
94
|
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
if (connection?.cachedCustomerId) {
|
|
97
|
+
saveBrowserInfo({
|
|
98
|
+
variables: {
|
|
99
|
+
customerId: connection?.cachedCustomerId,
|
|
100
|
+
browserInfo: properties,
|
|
101
|
+
},
|
|
102
|
+
})
|
|
103
|
+
.then(() => {
|
|
104
|
+
console.log('browser info saved');
|
|
105
|
+
})
|
|
106
|
+
.catch((err) => {
|
|
107
|
+
console.log(err);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}, [connection]);
|
|
111
|
+
|
|
68
112
|
const integrationId = response?.data?.widgetsMessengerConnect?.integrationId;
|
|
69
113
|
|
|
70
114
|
if (!visibleLauncher || !integrationId) {
|
|
@@ -81,13 +125,21 @@ const Widget = (props: any) => {
|
|
|
81
125
|
display: visibleLauncher ? 'flex' : 'none',
|
|
82
126
|
},
|
|
83
127
|
]}
|
|
84
|
-
onPress={() =>
|
|
128
|
+
onPress={() => {
|
|
129
|
+
AsyncStorage.removeItem('cachedCustomerId');
|
|
130
|
+
// setShow(false);
|
|
131
|
+
}}
|
|
85
132
|
>
|
|
86
133
|
<Image
|
|
87
134
|
source={images.logo}
|
|
88
135
|
style={styles.image}
|
|
89
136
|
resizeMode="contain"
|
|
90
137
|
/>
|
|
138
|
+
<View style={styles.unreadCountContainer}>
|
|
139
|
+
<Text style={{ color: '#fff' }}>
|
|
140
|
+
{dataUnreadCount?.widgetsTotalUnreadCount || 0}
|
|
141
|
+
</Text>
|
|
142
|
+
</View>
|
|
91
143
|
</TouchableOpacity>
|
|
92
144
|
</View>
|
|
93
145
|
);
|
|
@@ -172,4 +224,15 @@ const styles = StyleSheet.create({
|
|
|
172
224
|
backgroundColor: '#2F1F69',
|
|
173
225
|
},
|
|
174
226
|
image: { width: 50, height: 50, borderRadius: 90 },
|
|
227
|
+
unreadCountContainer: {
|
|
228
|
+
position: 'absolute',
|
|
229
|
+
top: 0,
|
|
230
|
+
right: 0,
|
|
231
|
+
backgroundColor: 'red',
|
|
232
|
+
width: 20,
|
|
233
|
+
height: 20,
|
|
234
|
+
borderRadius: 50,
|
|
235
|
+
justifyContent: 'center',
|
|
236
|
+
alignItems: 'center',
|
|
237
|
+
},
|
|
175
238
|
});
|
package/src/graphql/mutation.ts
CHANGED
|
@@ -1,46 +1,5 @@
|
|
|
1
1
|
import { gql } from '@apollo/client';
|
|
2
2
|
|
|
3
|
-
const userDetailFields = `
|
|
4
|
-
avatar
|
|
5
|
-
fullName
|
|
6
|
-
`;
|
|
7
|
-
|
|
8
|
-
const messageFields = `
|
|
9
|
-
_id
|
|
10
|
-
conversationId
|
|
11
|
-
customerId
|
|
12
|
-
user {
|
|
13
|
-
_id
|
|
14
|
-
details {
|
|
15
|
-
${userDetailFields}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
content
|
|
19
|
-
createdAt
|
|
20
|
-
internal
|
|
21
|
-
fromBot
|
|
22
|
-
contentType
|
|
23
|
-
videoCallData {
|
|
24
|
-
url
|
|
25
|
-
status
|
|
26
|
-
}
|
|
27
|
-
engageData {
|
|
28
|
-
content
|
|
29
|
-
kind
|
|
30
|
-
sentAs
|
|
31
|
-
messageId
|
|
32
|
-
brandId
|
|
33
|
-
}
|
|
34
|
-
botData
|
|
35
|
-
messengerAppData
|
|
36
|
-
attachments {
|
|
37
|
-
url
|
|
38
|
-
name
|
|
39
|
-
size
|
|
40
|
-
type
|
|
41
|
-
}
|
|
42
|
-
`;
|
|
43
|
-
|
|
44
3
|
const connect = gql`
|
|
45
4
|
mutation connect(
|
|
46
5
|
$brandCode: String!
|
|
@@ -161,112 +120,20 @@ const widgetsSaveCustomerGetNotified = gql`
|
|
|
161
120
|
}
|
|
162
121
|
`;
|
|
163
122
|
|
|
164
|
-
const
|
|
165
|
-
mutation widgetsSaveBrowserInfo(
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
`;
|
|
171
|
-
|
|
172
|
-
const customersAdd = gql`
|
|
173
|
-
mutation customersAdd(
|
|
174
|
-
$state: String
|
|
175
|
-
$avatar: String
|
|
176
|
-
$firstName: String
|
|
177
|
-
$lastName: String
|
|
178
|
-
$middleName: String
|
|
179
|
-
$sex: Int
|
|
180
|
-
$birthDate: Date
|
|
181
|
-
$primaryEmail: String
|
|
182
|
-
$primaryPhone: String
|
|
183
|
-
$phones: [String]
|
|
184
|
-
$emails: [String]
|
|
185
|
-
$ownerId: String
|
|
186
|
-
$position: String
|
|
187
|
-
$department: String
|
|
188
|
-
$leadStatus: String
|
|
189
|
-
$hasAuthority: String
|
|
190
|
-
$description: String
|
|
191
|
-
$isSubscribed: String
|
|
192
|
-
$links: JSON
|
|
193
|
-
$customFieldsData: JSON
|
|
194
|
-
$code: String
|
|
195
|
-
$emailValidationStatus: String
|
|
196
|
-
$phoneValidationStatus: String
|
|
123
|
+
const widgetsSaveBrowserInfo = gql`
|
|
124
|
+
mutation widgetsSaveBrowserInfo(
|
|
125
|
+
$customerId: String
|
|
126
|
+
$visitorId: String
|
|
127
|
+
$browserInfo: JSON!
|
|
197
128
|
) {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
lastName: $lastName
|
|
203
|
-
middleName: $middleName
|
|
204
|
-
sex: $sex
|
|
205
|
-
birthDate: $birthDate
|
|
206
|
-
primaryEmail: $primaryEmail
|
|
207
|
-
primaryPhone: $primaryPhone
|
|
208
|
-
phones: $phones
|
|
209
|
-
emails: $emails
|
|
210
|
-
ownerId: $ownerId
|
|
211
|
-
position: $position
|
|
212
|
-
department: $department
|
|
213
|
-
leadStatus: $leadStatus
|
|
214
|
-
hasAuthority: $hasAuthority
|
|
215
|
-
description: $description
|
|
216
|
-
isSubscribed: $isSubscribed
|
|
217
|
-
links: $links
|
|
218
|
-
customFieldsData: $customFieldsData
|
|
219
|
-
code: $code
|
|
220
|
-
emailValidationStatus: $emailValidationStatus
|
|
221
|
-
phoneValidationStatus: $phoneValidationStatus
|
|
129
|
+
widgetsSaveBrowserInfo(
|
|
130
|
+
customerId: $customerId
|
|
131
|
+
visitorId: $visitorId
|
|
132
|
+
browserInfo: $browserInfo
|
|
222
133
|
) {
|
|
223
134
|
_id
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
lastName
|
|
227
|
-
avatar
|
|
228
|
-
sex
|
|
229
|
-
birthDate
|
|
230
|
-
primaryEmail
|
|
231
|
-
emails
|
|
232
|
-
primaryPhone
|
|
233
|
-
phones
|
|
234
|
-
state
|
|
235
|
-
visitorContactInfo
|
|
236
|
-
modifiedAt
|
|
237
|
-
position
|
|
238
|
-
department
|
|
239
|
-
leadStatus
|
|
240
|
-
hasAuthority
|
|
241
|
-
description
|
|
242
|
-
isSubscribed
|
|
243
|
-
code
|
|
244
|
-
emailValidationStatus
|
|
245
|
-
phoneValidationStatus
|
|
246
|
-
score
|
|
247
|
-
isOnline
|
|
248
|
-
lastSeenAt
|
|
249
|
-
sessionCount
|
|
250
|
-
links
|
|
251
|
-
ownerId
|
|
252
|
-
owner {
|
|
253
|
-
_id
|
|
254
|
-
details {
|
|
255
|
-
fullName
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
integrationId
|
|
259
|
-
createdAt
|
|
260
|
-
remoteAddress
|
|
261
|
-
location
|
|
262
|
-
customFieldsData
|
|
263
|
-
trackedData
|
|
264
|
-
tagIds
|
|
265
|
-
getTags {
|
|
266
|
-
_id
|
|
267
|
-
name
|
|
268
|
-
colorCode
|
|
269
|
-
}
|
|
135
|
+
conversationId
|
|
136
|
+
customerId
|
|
270
137
|
}
|
|
271
138
|
}
|
|
272
139
|
`;
|
|
@@ -275,6 +142,5 @@ export {
|
|
|
275
142
|
connect,
|
|
276
143
|
widgetsInsertMessage,
|
|
277
144
|
widgetsSaveCustomerGetNotified,
|
|
278
|
-
|
|
279
|
-
customersAdd,
|
|
145
|
+
widgetsSaveBrowserInfo,
|
|
280
146
|
};
|
package/src/graphql/query.ts
CHANGED
|
@@ -158,10 +158,25 @@ const widgetsConversationDetail = gql`
|
|
|
158
158
|
}
|
|
159
159
|
`;
|
|
160
160
|
|
|
161
|
+
const widgetsTotalUnreadCount = gql`
|
|
162
|
+
query widgetsTotalUnreadCount(
|
|
163
|
+
$integrationId: String!
|
|
164
|
+
$customerId: String
|
|
165
|
+
$visitorId: String
|
|
166
|
+
) {
|
|
167
|
+
widgetsTotalUnreadCount(
|
|
168
|
+
integrationId: $integrationId
|
|
169
|
+
customerId: $customerId
|
|
170
|
+
visitorId: $visitorId
|
|
171
|
+
)
|
|
172
|
+
}
|
|
173
|
+
`;
|
|
174
|
+
|
|
161
175
|
export {
|
|
162
176
|
widgetsMessengerSupporters,
|
|
163
177
|
widgetsConversations,
|
|
164
178
|
widgetsConversationDetail,
|
|
165
179
|
knowledgeBaseTopicDetail,
|
|
166
180
|
knowledgeBaseCategoryDetail,
|
|
181
|
+
widgetsTotalUnreadCount,
|
|
167
182
|
};
|
|
@@ -22,7 +22,6 @@ import { widgetsInsertMessage } from '../../graphql/mutation';
|
|
|
22
22
|
import { conversationMessageInserted } from '../../graphql/subscription';
|
|
23
23
|
import { getAttachmentUrl } from '../../utils/utils';
|
|
24
24
|
import AppContext from '../../context/Context';
|
|
25
|
-
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
26
25
|
|
|
27
26
|
const ConversationDetail = () => {
|
|
28
27
|
const value = useContext(AppContext);
|
|
@@ -34,7 +33,6 @@ const ConversationDetail = () => {
|
|
|
34
33
|
integrationId,
|
|
35
34
|
customerId,
|
|
36
35
|
visitorId,
|
|
37
|
-
setConnection,
|
|
38
36
|
//
|
|
39
37
|
backIcon,
|
|
40
38
|
sendIcon,
|
|
@@ -123,15 +121,6 @@ const ConversationDetail = () => {
|
|
|
123
121
|
return console.log(res.errors);
|
|
124
122
|
}
|
|
125
123
|
if (res.data.widgetsInsertMessage) {
|
|
126
|
-
if (!customerId) {
|
|
127
|
-
const tempCustomerId = res.data.widgetsInsertMessage.customerId;
|
|
128
|
-
const jsonValue = JSON.stringify(tempCustomerId);
|
|
129
|
-
AsyncStorage.setItem('cachedCustomerId', jsonValue);
|
|
130
|
-
setConnection({
|
|
131
|
-
visitorId,
|
|
132
|
-
cachedCustomerId: tempCustomerId,
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
124
|
let shouldAdd = messages?.length === 0;
|
|
136
125
|
if (!shouldAdd) {
|
|
137
126
|
shouldAdd = res.data.widgetsInsertMessage._id !== messages[0]._id;
|