@defra/flood-webchat 0.0.1-beta.53 → 0.0.1-beta.54
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/package.json +1 -1
- package/src/client/components/availability/availability.jsx +0 -130
- package/src/client/components/chat/chat.jsx +0 -233
- package/src/client/components/errorSummary/error-summary.jsx +0 -34
- package/src/client/components/live-region.jsx +0 -55
- package/src/client/components/message/message.jsx +0 -21
- package/src/client/components/panel/panel-footer.jsx +0 -9
- package/src/client/components/panel/panel-header.jsx +0 -75
- package/src/client/components/panel/panel.jsx +0 -163
- package/src/client/components/screens/end-chat.jsx +0 -77
- package/src/client/components/screens/feedback.jsx +0 -65
- package/src/client/components/screens/pre-chat.jsx +0 -62
- package/src/client/components/screens/request-chat.jsx +0 -183
- package/src/client/components/screens/settings.jsx +0 -97
- package/src/client/components/screens/unavailable.jsx +0 -23
- package/src/client/components/skip-link.jsx +0 -42
- package/src/client/hooks/useFocusedElements.js +0 -80
- package/src/client/hooks/useTextareaAutosize.js +0 -13
- package/src/client/index.jsx +0 -33
- package/src/client/lib/agent-status-headline.js +0 -17
- package/src/client/lib/check-availability.js +0 -8
- package/src/client/lib/classnames.js +0 -1
- package/src/client/lib/history.js +0 -13
- package/src/client/lib/message-notification.js +0 -30
- package/src/client/lib/transform-messages.js +0 -47
- package/src/client/store/AppProvider.jsx +0 -183
- package/src/client/store/actions-map.js +0 -152
- package/src/client/store/constants.js +0 -3
- package/src/client/store/reducer.js +0 -31
- package/src/client/store/useApp.js +0 -5
- package/src/client/store/useChatSdk.js +0 -37
- package/src/server/index.js +0 -60
- package/src/server/lib/client.js +0 -88
- package/src/server/lib/utils.js +0 -23
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
export const useChatSdk = sdk => {
|
|
2
|
-
const connect = async () => sdk.authorize()
|
|
3
|
-
|
|
4
|
-
const fetchCustomerId = async () => {
|
|
5
|
-
const response = await connect()
|
|
6
|
-
return response?.consumerIdentity.idOnExternalPlatform
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const fetchThread = async threadId => {
|
|
10
|
-
await connect()
|
|
11
|
-
return sdk.getThread(threadId)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const fetchMessages = async (thread, threadId) => {
|
|
15
|
-
await connect()
|
|
16
|
-
|
|
17
|
-
const recovered = await thread.recover(threadId)
|
|
18
|
-
|
|
19
|
-
const allMessages = []
|
|
20
|
-
let fetchedMessages = recovered.messages
|
|
21
|
-
|
|
22
|
-
while (fetchedMessages.length) {
|
|
23
|
-
fetchedMessages.map(msg => allMessages.push(msg))
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
const response = await thread.loadMoreMessages()
|
|
27
|
-
fetchedMessages = response.data.messages
|
|
28
|
-
} catch (err) {
|
|
29
|
-
fetchedMessages = []
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return allMessages
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return { connect, fetchCustomerId, fetchThread, fetchMessages }
|
|
37
|
-
}
|
package/src/server/index.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
const { authenticate, getApiBaseUrl, getIsOpen, getActivity } = require('./lib/client.js')
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Returns webchat availability
|
|
5
|
-
* @param options {object}
|
|
6
|
-
* @param options.clientId {string}
|
|
7
|
-
* @param options.clientSecret {string}
|
|
8
|
-
* @param options.accessKey {string}
|
|
9
|
-
* @param options.accessSecret {string}
|
|
10
|
-
* @param options.skillEndpoint {string}
|
|
11
|
-
* @param options.hoursEndpoint {string}
|
|
12
|
-
* @param options.authenticationUri {string}
|
|
13
|
-
* @param options.wellKnownUri {string}
|
|
14
|
-
* @param options.maxQueueCount {string}
|
|
15
|
-
* @returns {Promise<{date: Date, availability: (string)}>}
|
|
16
|
-
*/
|
|
17
|
-
module.exports = async function getAvailability ({
|
|
18
|
-
clientId,
|
|
19
|
-
clientSecret,
|
|
20
|
-
accessKey,
|
|
21
|
-
accessSecret,
|
|
22
|
-
maxQueueCount,
|
|
23
|
-
skillEndpoint,
|
|
24
|
-
hoursEndpoint,
|
|
25
|
-
wellKnownUri = 'https://cxone.niceincontact.com/.well-known/cxone-configuration',
|
|
26
|
-
authenticationUri = 'https://cxone.niceincontact.com/auth/token'
|
|
27
|
-
}) {
|
|
28
|
-
const authorisation = 'Basic ' + Buffer.from(`${encodeURIComponent(clientId)}:${encodeURIComponent(clientSecret)}`).toString('base64')
|
|
29
|
-
|
|
30
|
-
// Cache authentication and re-authenticate when needed (lasts 1 hour?)
|
|
31
|
-
const { tenantId, token, tokenType } = await authenticate({
|
|
32
|
-
authenticationUri,
|
|
33
|
-
authorisation,
|
|
34
|
-
accessKey,
|
|
35
|
-
accessSecret
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
const apiBaseUrl = await getApiBaseUrl({ wellKnownUri, tenantId })
|
|
39
|
-
|
|
40
|
-
const [{ hasCapacity, hasAgentsAvailable }, isOpen] = await Promise.all([
|
|
41
|
-
getActivity({ baseUrl: apiBaseUrl, tokenType, token, skillEndpoint, maxQueueCount }),
|
|
42
|
-
getIsOpen({ baseUrl: apiBaseUrl, token, tokenType, hoursEndpoint })
|
|
43
|
-
])
|
|
44
|
-
|
|
45
|
-
const isAvailable = isOpen && hasAgentsAvailable && hasCapacity
|
|
46
|
-
const isExistingOnly = isOpen && hasAgentsAvailable && !hasCapacity
|
|
47
|
-
|
|
48
|
-
let availability = 'UNAVAILABLE'
|
|
49
|
-
|
|
50
|
-
if (isAvailable) {
|
|
51
|
-
availability = 'AVAILABLE'
|
|
52
|
-
} else if (isExistingOnly) {
|
|
53
|
-
availability = 'EXISTING'
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return {
|
|
57
|
-
date: new Date(),
|
|
58
|
-
availability
|
|
59
|
-
}
|
|
60
|
-
}
|
package/src/server/lib/client.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
const querystring = require('querystring')
|
|
2
|
-
const axios = require('axios')
|
|
3
|
-
const jwtdecode = require('jwt-decode')
|
|
4
|
-
const { isWithinHours } = require('./utils.js')
|
|
5
|
-
|
|
6
|
-
const contentType = 'application/x-www-form-urlencoded'
|
|
7
|
-
|
|
8
|
-
const authenticate = async ({ authenticationUri, authorisation, accessKey, accessSecret }) => {
|
|
9
|
-
const url = new URL(authenticationUri)
|
|
10
|
-
const body = querystring.stringify({
|
|
11
|
-
grant_type: 'password',
|
|
12
|
-
username: accessKey,
|
|
13
|
-
password: accessSecret
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
const auth = await axios.post(url.href, body, {
|
|
17
|
-
signal: AbortSignal.timeout(3000),
|
|
18
|
-
headers: {
|
|
19
|
-
Host: url.host,
|
|
20
|
-
'Content-Type': contentType,
|
|
21
|
-
Authorization: authorisation
|
|
22
|
-
}
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
token: auth.data.access_token,
|
|
27
|
-
tokenType: auth.data.token_type,
|
|
28
|
-
tenantId: jwtdecode(auth.data.id_token)?.tenantId
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const getApiBaseUrl = async ({ wellKnownUri, tenantId }) => {
|
|
33
|
-
const url = new URL(wellKnownUri)
|
|
34
|
-
url.searchParams.set('tenantId', tenantId)
|
|
35
|
-
|
|
36
|
-
const { data } = await axios.get(url.href, {
|
|
37
|
-
headers: {
|
|
38
|
-
Host: url.host
|
|
39
|
-
},
|
|
40
|
-
signal: AbortSignal.timeout(3000)
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
return data.api_endpoint
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const getActivity = async ({ tokenType, token, baseUrl, skillEndpoint, maxQueueCount }) => {
|
|
47
|
-
const url = new URL(skillEndpoint, baseUrl)
|
|
48
|
-
|
|
49
|
-
const skill = await axios.get(url.href, {
|
|
50
|
-
signal: AbortSignal.timeout(3000),
|
|
51
|
-
headers: {
|
|
52
|
-
Host: url.host,
|
|
53
|
-
Authorization: `${tokenType} ${token}`,
|
|
54
|
-
'Content-Type': contentType
|
|
55
|
-
}
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
const activity = skill.data.skillActivity[0]
|
|
59
|
-
|
|
60
|
-
return {
|
|
61
|
-
hasCapacity: activity.queueCount < maxQueueCount,
|
|
62
|
-
hasAgentsAvailable: activity.agentsAvailable >= 1
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const getIsOpen = async ({ baseUrl, token, tokenType, hoursEndpoint }) => {
|
|
67
|
-
const url = new URL(hoursEndpoint, baseUrl)
|
|
68
|
-
|
|
69
|
-
const hours = await axios.get(url.href, {
|
|
70
|
-
signal: AbortSignal.timeout(3000),
|
|
71
|
-
headers: {
|
|
72
|
-
Host: url.host,
|
|
73
|
-
Authorization: `${tokenType} ${token}`,
|
|
74
|
-
'Content-Type': contentType
|
|
75
|
-
}
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
const days = hours.data.resultSet.hoursOfOperationProfiles[0].days
|
|
79
|
-
|
|
80
|
-
return isWithinHours(days)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
module.exports = {
|
|
84
|
-
authenticate,
|
|
85
|
-
getApiBaseUrl,
|
|
86
|
-
getIsOpen,
|
|
87
|
-
getActivity
|
|
88
|
-
}
|
package/src/server/lib/utils.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const { DateTime } = require('luxon')
|
|
2
|
-
|
|
3
|
-
const getHour = time => Number(time.split(':')[0])
|
|
4
|
-
|
|
5
|
-
const isWithinHours = (days, date) => {
|
|
6
|
-
const now = date ? DateTime.fromISO(date) : DateTime.local()
|
|
7
|
-
now.setZone('Europe/London')
|
|
8
|
-
|
|
9
|
-
const newDate = date ? new Date(date) : new Date()
|
|
10
|
-
|
|
11
|
-
const today = newDate.toLocaleDateString('en-GB', { weekday: 'long' })
|
|
12
|
-
const dateParts = newDate.toLocaleDateString('en-GB').split('/')
|
|
13
|
-
|
|
14
|
-
const todaysAvailability = days.find(item => item.day === today)
|
|
15
|
-
const todaysDateTimeOpen = DateTime.local(Number(dateParts[2]), Number(dateParts[1]), Number(dateParts[0]), getHour(todaysAvailability.openTime))
|
|
16
|
-
const todaysDateTimeClose = DateTime.local(Number(dateParts[2]), Number(dateParts[1]), Number(dateParts[0]), getHour(todaysAvailability.closeTime))
|
|
17
|
-
|
|
18
|
-
return now.diff(todaysDateTimeOpen).milliseconds >= 0 && now.diff(todaysDateTimeClose).milliseconds <= 0
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
module.exports = {
|
|
22
|
-
isWithinHours
|
|
23
|
-
}
|